]> git.donarmstrong.com Git - lilypond.git/blob - src/midiwalker.cc
release: 0.0.34
[lilypond.git] / src / midiwalker.cc
1 /*
2   midiwalker.cc -- implement Midi_walker
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>, Jan Nieuwenhuizen <jan@digicash.com>
7 */
8
9 #include "musicalrequest.hh"
10 #include "pscore.hh"
11 #include "staff.hh"
12 #include "stcol.hh"
13 #include "midiwalker.hh"
14 #include "midiitem.hh"
15 #include "midistream.hh"
16 #include "debug.hh"
17
18 Midi_walker::Midi_walker(Staff *st_l, Midi_track* track_l)
19     : PCursor<Staff_column*>(st_l->cols_)
20 {
21     track_l_ = track_l;
22     last_moment_= 0;
23 }
24
25 void
26 Midi_walker::do_stop_notes(Moment max_moment)
27 {
28     while (stop_notes.size() && stop_notes.front_idx() <= max_moment) {
29         Moment stop_moment = stop_notes.front_idx();
30         Melodic_req * req_l = stop_notes.get();
31         
32         Midi_note note(req_l, track_l_->number_i_, false);
33         
34         Moment delta_t = stop_moment-last_moment_ ;
35         last_moment_ += delta_t;
36         track_l_->add(delta_t, &note );
37     }
38 }
39
40 void
41 Midi_walker::process_requests()
42 {
43     do_stop_notes(ptr()->when());
44     for ( int i = 0; i < ptr()->musicalreq_l_arr_.size(); i++ )  {
45
46         Rhythmic_req *n = ptr()->musicalreq_l_arr_[i]->rhythmic();
47         if ( !n || !(n->note() || n->rest()) )
48             continue;
49         
50         Midi_note note(n->melodic(), track_l_->number_i_, true);
51         stop_notes.enter(n->melodic(), n->duration() + ptr()->when() );
52         Moment dt = 0;
53         track_l_->add(dt, &note);
54     }
55 }
56
57 Midi_walker::~Midi_walker()
58 {
59     do_stop_notes( last_moment_ + Moment(10,1)); // ugh
60 }