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