lilypond-0.1.32
[lilypond.git] / mi2mu / midi-voice.cc
blob77a6526ef855320830ce2b0892b6ebad6da06672
1 //
2 // midi-voice.cc -- implement midi_voice
3 //
4 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
6 #include "mi2mu.hh"
8 Midi_voice::Midi_voice( Moment begin_mom )
10 begin_mom_ = begin_mom;
11 end_mom_ = begin_mom;
12 events_i_ = 0;
15 void
16 Midi_voice::add_event( Midi_event* midi_event_p )
18 #ifdef MEVENT_LIST
19 midi_event_p_list_.bottom().add( midi_event_p );
20 #else
21 midi_event_p_array_.push( midi_event_p );
22 #endif
25 Moment
26 Midi_voice::begin_mom()
28 return begin_mom_;
31 Moment
32 Midi_voice::end_mom()
34 #ifdef MEVENT_LIST
35 // if ( events_i_ == midi_event_p_list_.length_i() )
36 if ( events_i_ == midi_event_p_list_.size() )
37 return end_mom_;
38 Moment now_mom = begin_mom_;
39 tor( DEBUG_ver ) << now_mom << ", ";
40 for ( PCursor<Midi_event*> i( midi_event_p_list_.top() ); i.ok(); i++ ) {
41 tor( DEBUG_ver ) << now_mom << ", ";
42 now_mom += i->mom();
44 tor( DEBUG_ver ) << endl;
45 end_mom_ = now_mom;
46 // events_i_ = midi_event_p_list_.length_i();
47 events_i_ = midi_event_p_list_.size();
48 return end_mom_;
49 #else
50 if ( events_i_ == midi_event_p_array_.size() )
51 return end_mom_;
52 Moment now_mom = begin_mom_;
53 tor( DEBUG_ver ) << now_mom << ", ";
54 for ( int i = 0; i < midi_event_p_array_.size(); i++ ) {
55 tor( DEBUG_ver ) << now_mom << ", ";
56 now_mom += midi_event_p_array_[ i ]->mom();
58 tor( DEBUG_ver ) << endl;
59 end_mom_ = now_mom;
60 events_i_ = midi_event_p_array_.size();
61 return end_mom_;
62 #endif
65 String
66 Midi_voice::mudela_str( Moment from_mom, Moment to_mom, bool multiple_bo )
68 String str;
70 // if ( begin_mom() >= to_mom )
71 if ( begin_mom() > to_mom )
72 return "";
73 // if ( end_mom() <= from_mom )
74 if ( end_mom() < from_mom )
75 return "";
77 Moment now_mom = begin_mom();
78 #ifdef MEVENT_LIST
79 PCursor<Midi_event*> i( midi_event_p_list_.top() );
80 for ( ; i.ok() && now_mom < from_mom ; i++ )
81 now_mom += i->mom();
83 for ( ; i.ok() && now_mom < to_mom ; i++ ) {
84 now_mom += i->mom();
85 str += i->mudela_str( false ) + " ";
87 #else
88 int i = 0;
89 for ( ; i < midi_event_p_array_.size() && now_mom < from_mom ; i++ )
90 now_mom += midi_event_p_array_[ i ]->mom();
92 for ( ; i < midi_event_p_array_.size() && now_mom < to_mom ; i++ ) {
93 now_mom += midi_event_p_array_[ i ]->mom();
94 str += midi_event_p_array_[ i ]->mudela_str( false ) + " ";
96 #endif
98 if ( str.length_i() && multiple_bo )
99 str = "{ " + str + "} ";
100 return str;