lilypond-1.3.8
[lilypond.git] / src / midi-track.cc
blob6fccd518ec365ad958ed50bcddeca5e531266cbd
1 //
2 // midi-track.cc -- implement Midi_track
3 //
4 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
6 #include "proto.hh"
7 #include "plist.hh"
8 #include "string.hh"
9 #include "source-file.hh"
10 #include "source.hh"
11 #include "midi-main.hh" // *tors
13 #include "moment.hh"
14 #include "duration.hh"
15 #include "midi-event.hh"
16 #include "lily-stream.hh"
17 #include "track-column.hh"
18 #include "midi-track.hh"
20 Midi_track::Midi_track( int track_i )
22 name_str_ = String( "track" ) + String( track_i );
23 tcol_p_list_.bottom().add( new Track_column( Moment( 0 ) ) );
26 Midi_track::~Midi_track()
30 void
31 Midi_track::add_event( Moment mom, Midi_event* midi_event_p )
33 if ( ! midi_event_p )
34 return;
35 tcol_l( mom - midi_event_p->mom() )->add_event( midi_event_p );
38 // too much red tape ?
39 String
40 Midi_track::name_str()
42 return name_str_;
45 void
46 Midi_track::output_mudela( Lily_stream& lily_stream_r )
48 lily_stream_r << name_str_ << " = music { $\n";
49 lily_stream_r << "\t";
50 int column_i = 8;
52 for ( PCursor<Track_column*> tcol_l_pcur( tcol_p_list_.top() ); tcol_l_pcur.ok(); tcol_l_pcur++ ) {
53 if ( tcol_l_pcur->midi_event_p_list_.size() > 1 )
54 warning( "oeps, chord: can-t do that yet", 0 );
55 if ( !tcol_l_pcur->midi_event_p_list_.size() )
56 continue;
57 lily_stream_r << **tcol_l_pcur->midi_event_p_list_.top();
58 column_i += tcol_l_pcur->midi_event_p_list_.top()->mudela_str().length_i();
59 if ( column_i > 40 ) {
60 lily_stream_r << "\n\t";
61 column_i = 8;
64 lily_stream_r << "\n$} % " << name_str_ << "\n";
67 Track_column*
68 Midi_track::tcol_l( Moment mom )
70 for ( PCursor<Track_column*> tcol_l_pcur( tcol_p_list_.top() ); tcol_l_pcur.ok(); tcol_l_pcur++ ) {
71 if ( tcol_l_pcur->mom() == mom )
72 return *tcol_l_pcur;
73 if ( tcol_l_pcur->mom() > mom ) {
74 Track_column* tcol_p = new Track_column( mom );
75 tcol_l_pcur.insert( tcol_p );
76 return tcol_p;
80 Track_column* tcol_p = new Track_column( mom );
81 tcol_p_list_.bottom().add( tcol_p );
82 return tcol_p;