lilypond-0.1.16
[lilypond.git] / src / midiwalker.cc
blobb8350bc2cc85d7dcd2c024253d43f20edfaba652
1 /*
2 midiwalker.cc -- implement Midi_walker
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>, Jan Nieuwenhuizen <jan@digicash.com>
7 */
9 #include "musicalrequest.hh"
10 #include "pscore.hh"
11 #include "staff.hh"
12 #include "midiwalker.hh"
13 #include "midiitem.hh"
14 #include "midistream.hh"
15 #include "debug.hh"
16 #include "staffcolumn.hh"
18 Midi_walker::Midi_walker(Staff *st_l, Midi_track* track_l)
19 : PCursor<Staff_column*>(st_l->cols_)
21 track_l_ = track_l;
22 last_moment_= 0;
25 /**
26 output notestop events for all notes which end before #max_moment#
28 void
29 Midi_walker::do_stop_notes(Moment max_moment)
31 while (stop_notes.size() && stop_notes.front_idx() <= max_moment) {
32 Moment stop_moment = stop_notes.front_idx();
33 Melodic_req * req_l = stop_notes.get();
35 Midi_note note(req_l, track_l_->number_i_, false);
36 output_event(note, stop_moment);
39 /** advance the track to #now#, output the item, and adjust current
40 "moment". */
41 void
42 Midi_walker::output_event(Midi_item &i, Moment now)
44 Moment delta_t = now - last_moment_ ;
45 last_moment_ += delta_t;
46 track_l_->add(delta_t, &i );
49 void
50 Midi_walker::process_requests()
52 do_stop_notes(ptr()->when());
53 for ( int i = 0; i < ptr()->musicalreq_l_arr_.size(); i++ ) {
55 Rhythmic_req *n = ptr()->musicalreq_l_arr_[i]->rhythmic();
56 if ( !n)
57 continue;
58 Note_req * note_l = n->note();
59 if (!note_l)
60 continue;
62 Midi_note note(note_l, track_l_->number_i_, true);
63 stop_notes.enter(note_l, n->duration() + ptr()->when() );
64 output_event(note, ptr()->when());
68 Midi_walker::~Midi_walker()
70 do_stop_notes( last_moment_ + Moment(10,1)); // ugh