]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-walker.cc
partial: 0.0.39-1.hanjan
[lilypond.git] / lily / midi-walker.cc
1 /*
2   midi-walker.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 "midi-walker.hh"
13 #include "midi-item.hh"
14 #include "midi-stream.hh"
15 #include "debug.hh"
16 #include "staff-column.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 /**
26   output notestop events for all notes which end before #max_moment#
27  */
28 void
29 Midi_walker::do_stop_notes(Moment max_moment)
30 {
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();
34         
35         Midi_note note(req_l, track_l_->number_i_, false);
36         output_event(note, stop_moment);
37     }
38 }
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)
43 {
44     Moment delta_t = now - last_moment_ ;
45     last_moment_ += delta_t;
46     track_l_->add(delta_t, &i );    
47 }
48
49 void
50 Midi_walker::process_requests()
51 {
52     do_stop_notes(ptr()->when());
53     for ( int i = 0; i < ptr()->musicalreq_l_arr_.size(); i++ )  {
54
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;
61         
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());
65     }
66 }
67
68 Midi_walker::~Midi_walker()
69 {
70     do_stop_notes( last_moment_ + Moment(10,1)); // ugh
71 }