Logo Search packages:      
Sourcecode: csound version File versions  Download package

void csound::Score::save ( MidiFile midiFile  )  [virtual]

Save as a MIDI file, format 1.

Definition at line 314 of file Score.cpp.

References csound::MidiFile::clear(), csound::MidiFile::currentSecondsPerTick, csound::MidiFile::midiTracks, sort(), csound::MidiEvent::ticks, and csound::MidiEvent::time.

  {
    findScale();
    sort();
    // Format 0 file.
    midiFile.clear();
    MidiTrack midiTrack;
    midiFile.midiTracks.push_back(midiTrack);
    for(Score::iterator it = begin(); it != end(); ++it)
      {
        Event &event = (*it);
        // event.dump(std::cout);
        if(event.isNoteOn())
          {
            MidiEvent onEvent;
            onEvent.time = event.getTime();
            onEvent.ticks = int(Conversions::round(onEvent.time / midiFile.currentSecondsPerTick));
            onEvent.push_back(event.getMidiStatus());
            onEvent.push_back(event.getKeyNumber());
            onEvent.push_back(event.getVelocityNumber());
            midiFile.midiTracks[0].push_back(onEvent);
            MidiEvent offEvent;
            offEvent.time = event.getTime() + event.getDuration();
            offEvent.ticks = int(Conversions::round(offEvent.time / midiFile.currentSecondsPerTick));
            offEvent.push_back(event.getMidiStatus());
            offEvent.push_back(event.getKeyNumber());
            offEvent.push_back(0);
            midiFile.midiTracks[0].push_back(offEvent);
          }
      }
    midiFile.midiTracks[0].sort();
    MidiEvent trackEnd;
    if(midiFile.midiTracks.size() > 0)
      {
        if(midiFile.midiTracks[0].size() > 0)
          {
            trackEnd.ticks = midiFile.midiTracks[0][midiFile.midiTracks[0].size() - 1].ticks;
          }
      }
    trackEnd.push_back(MidiFile::META_EVENT);
    trackEnd.push_back(MidiFile::META_END_OF_TRACK);
    trackEnd.push_back(0);
    midiFile.midiTracks[0].push_back(trackEnd);
  }


Generated by  Doxygen 1.6.0   Back to index