lilypond-0.1.57
[lilypond.git] / lily / audio-score.cc
blob37125f6fc3222fcc9fbff71af0886646f1f56f5b
1 /*
2 audio-score.cc -- implement Audio_score
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
7 */
9 #include <time.h>
10 #include "debug.hh"
11 #include "string.hh"
12 #include "string-convert.hh"
13 #include "main.hh"
14 #include "midi-def.hh"
15 #include "midi-item.hh"
16 #include "midi-stream.hh"
17 #include "audio-column.hh"
18 #include "audio-staff.hh"
19 #include "audio-score.hh"
20 #include "score.hh"
22 Audio_score::Audio_score ()
24 midi_l_ =0;
27 void
28 Audio_score::add (Audio_column* p)
30 p->audio_score_l_ = this;
31 audio_column_p_list_.bottom().add (p);
34 void
35 Audio_score::output (Midi_stream& midi_stream_r)
37 int tracks_i = audio_staff_l_list_.size() + 1;
38 // ugh
39 int clocks_per_4_i = 384;
40 midi_stream_r << Midi_header (1, tracks_i, clocks_per_4_i);
41 output_header_track (midi_stream_r);
42 int n = 1;
43 for (PCursor<Audio_staff*> i (audio_staff_l_list_); i.ok(); i++)
44 i->output (midi_stream_r, n++);
47 void
48 Audio_score::output_header_track (Midi_stream& midi_stream_r)
50 Midi_track midi_track;
52 time_t t = time (0);
54 // perhaps multiple text events?
55 String str = String ("Creator: ") + get_version_str() + "\n";
57 Midi_text creator (Midi_text::TEXT, str);
58 midi_track.add (Moment (0), &creator);
60 str = "Automatically generated at ";
61 str += ctime (&t);
62 str = str.left_str (str.length_i() - 1);
63 str += "\n";
64 Midi_text generate (Midi_text::TEXT, str);
65 midi_track.add (Moment (0), &generate);
67 str = "from musical definition: ";
69 str += origin_str_;
70 Midi_text from (Midi_text::TEXT, str);
71 midi_track.add (Moment (0), &from);
73 Midi_text track_name (Midi_text::TRACK_NAME, "Track "
74 + String_convert::i2dec_str (0, 0, '0'));
75 midi_track.add (Moment (0), &track_name);
77 Midi_tempo tempo (midi_l_->get_tempo_i (Moment (1, 4)));
78 midi_track.add (Moment (0), &tempo);
80 midi_stream_r << midi_track;
83 void
84 Audio_score::add_staff (Audio_staff* l)
86 audio_staff_l_list_.bottom().add (l);
89 void
90 Audio_score::add (Audio_element *p)
92 audio_elem_p_list_.bottom().add (p);
95 void
96 Audio_score::print() const
98 #ifndef NPRINT
99 DOUT << "Audio_score { ";
100 DOUT << "\ncolumns: ";
101 for (PCursor<Audio_column*> i (audio_column_p_list_); i.ok(); i++)
102 i->print();
103 DOUT << "}\n";
104 #endif
107 void
108 Audio_score::process()
110 String out=midi_l_->outfile_str_;
111 if (out == "")
112 out = default_out_str_ + ".midi";
114 Midi_stream midi_stream (out);
115 *mlog << "MIDI output to " << out<< " ..." << endl;
117 output (midi_stream);
118 *mlog << endl;