]> git.donarmstrong.com Git - lilypond.git/blob - m2m/midi-voice.cc
release: 0.0.39-1
[lilypond.git] / m2m / midi-voice.cc
1 //
2 // midi-voice.cc -- implement midi_voice
3 //
4 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
5
6 #include "m2m.hh"
7
8 Midi_voice::Midi_voice( Moment begin_mom )
9 {
10         begin_mom_ = begin_mom;
11 }
12
13 void
14 Midi_voice::add_event( Midi_event* midi_event_p )
15 {
16         midi_event_p_list_.bottom().add( midi_event_p );
17 }
18
19 Moment 
20 Midi_voice::begin_mom()
21 {
22         return begin_mom_;
23 }
24
25 Moment 
26 Midi_voice::end_mom()
27 {
28         Moment now_mom = begin_mom_;
29         dtor << now_mom << ", ";
30         for ( PCursor<Midi_event*> i( midi_event_p_list_.top() ); i.ok(); i++ ) {
31                 dtor << now_mom << ", ";
32                 now_mom += i->mom();
33         }
34         dtor << endl;
35         return now_mom;
36 }
37
38 String 
39 Midi_voice::mudela_str( Moment from_mom, Moment to_mom, bool multiple_bo )
40 {
41         String str;
42
43         if ( begin_mom() >= to_mom )
44                 return "";
45         if ( end_mom() <= from_mom )
46                 return "";
47         
48         Moment now_mom = begin_mom();
49         PCursor<Midi_event*> i( midi_event_p_list_.top() );
50         for ( ; i.ok() && now_mom < from_mom ; i++ )
51                 now_mom += i->mom();
52         
53         for ( ; i.ok() && now_mom < to_mom ; i++ ) {
54                 now_mom += i->mom();
55                 str += i->mudela_str( false ) + " ";
56         }
57         
58         if ( str.length_i() && multiple_bo )
59                 str = "\\music{ " + str + "} ";
60         return str;
61 }
62