]> git.donarmstrong.com Git - lilypond.git/blob - lily/performance.cc
af083021cea180bd35f215ad5ed7b519db921834
[lilypond.git] / lily / performance.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2015 Jan Nieuwenhuizen <janneke@gnu.org>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "performance.hh"
21
22 #include <ctime>
23
24 #include "audio-column.hh"
25 #include "audio-item.hh"
26 #include "audio-staff.hh"
27 #include "file-name.hh"
28 #include "international.hh"
29 #include "lily-version.hh"
30 #include "main.hh"
31 #include "midi-chunk.hh"
32 #include "midi-stream.hh"
33 #include "score.hh"
34 #include "string-convert.hh"
35 #include "warn.hh"
36
37 using std::string;
38
39 Performance::Performance (bool ports)
40   : midi_ (0),
41     ports_ (ports),
42     header_ (SCM_EOL)
43 {
44 }
45
46 Performance::~Performance ()
47 {
48   junk_pointers (audio_elements_);
49 }
50
51 void
52 Performance::derived_mark () const
53 {
54   scm_gc_mark (header_);
55 }
56
57 SCM
58 Performance::get_header () const
59 {
60   return header_;
61 }
62
63 void
64 Performance::set_header (SCM module)
65 {
66   assert (ly_is_module (module));
67   header_ = module;
68 }
69
70 void
71 Performance::output (Midi_stream &midi_stream,
72                      const string &performance_name) const
73 {
74   int tracks_ = audio_staffs_.size ();
75
76   midi_stream.write (Midi_header (1, tracks_, 384));
77   debug_output (_ ("Track...") + " ", false);
78
79   //Find the first Audio_item in the performance, so all staves start
80   //at the same tick.
81   Moment start_mom = 0;
82   for (vsize i = 0; i < audio_elements_.size (); i++)
83     if (Audio_item *item = dynamic_cast<Audio_item *>(audio_elements_[i]))
84       start_mom = std::min (start_mom, item->audio_column_->when ());
85
86   for (vsize i = 0; i < audio_staffs_.size (); i++)
87     {
88       Audio_staff *s = audio_staffs_[i];
89       if (Audio_control_track_staff *c =
90           dynamic_cast<Audio_control_track_staff *>(s))
91         {
92           // The control track, created by Control_track_performer, should
93           // contain a placeholder for the name of the MIDI sequence as its
94           // initial audio element.  Fill in the name of the sequence to
95           // this element before outputting MIDI.
96           assert (!c->audio_items_.empty ());
97           Audio_text *text =
98             dynamic_cast<Audio_text *>(c->audio_items_.front ());
99           assert (text != 0);
100           assert (text->type_ == Audio_text::TRACK_NAME);
101           assert (text->text_string_ == "control track");
102           text->text_string_ = performance_name;
103         }
104       debug_output ("[" + ::to_string (i), true);
105       s->output (midi_stream, i, ports_, moment_to_ticks (start_mom));
106       debug_output ("]", false);
107     }
108 }
109
110 void
111 Performance::add_element (Audio_element *p)
112 {
113   audio_elements_.push_back (p);
114 }
115
116 void
117 Performance::write_output (string out, const string &performance_name) const
118 {
119   if (out == "-")
120     out = "lelie.midi";
121
122   /* Maybe a bit crude, but we had this before */
123   File_name file_name (out);
124   out = file_name.to_string ();
125
126   Midi_stream midi_stream (out);
127   message (_f ("MIDI output to `%s'...", out));
128
129   output (midi_stream, performance_name);
130   progress_indication ("\n");
131 }
132
133 void
134 Performance::process ()
135 {
136 }