]> git.donarmstrong.com Git - lilypond.git/blob - lily/performance.cc
unsmob_pitch -> Pitch::unsmob and related
[lilypond.git] / lily / performance.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2014 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 using namespace std;
24
25 #include "audio-column.hh"
26 #include "audio-item.hh"
27 #include "audio-staff.hh"
28 #include "file-name.hh"
29 #include "international.hh"
30 #include "lily-version.hh"
31 #include "main.hh"
32 #include "midi-chunk.hh"
33 #include "midi-stream.hh"
34 #include "score.hh"
35 #include "string-convert.hh"
36 #include "warn.hh"
37
38 Performance::Performance (bool ports)
39   : midi_ (0),
40     ports_ (ports)
41 {
42 }
43
44 Performance::~Performance ()
45 {
46   junk_pointers (audio_elements_);
47 }
48
49 void
50 Performance::output (Midi_stream &midi_stream) const
51 {
52   int tracks_ = audio_staffs_.size ();
53
54   midi_stream.write (Midi_header (1, tracks_, 384));
55   debug_output (_ ("Track...") + " ", false);
56
57   //Find the first Audio_item in the performance, so all staves start
58   //at the same tick.
59   Moment start_mom = 0;
60   for (vsize i = 0; i < audio_elements_.size (); i++)
61     if (Audio_item *item = dynamic_cast<Audio_item *>(audio_elements_[i]))
62       start_mom = min (start_mom, item->audio_column_->when ());
63
64   for (vsize i = 0; i < audio_staffs_.size (); i++)
65     {
66       Audio_staff *s = audio_staffs_[i];
67       debug_output ("[" + ::to_string (i), true);
68       s->output (midi_stream, i, ports_, moment_to_ticks (start_mom));
69       debug_output ("]", false);
70     }
71 }
72
73 void
74 Performance::add_element (Audio_element *p)
75 {
76   audio_elements_.push_back (p);
77 }
78
79 void
80 Performance::write_output (string out) const
81 {
82   if (out == "-")
83     out = "lelie.midi";
84
85   /* Maybe a bit crude, but we had this before */
86   File_name file_name (out);
87   out = file_name.to_string ();
88
89   Midi_stream midi_stream (out);
90   message (_f ("MIDI output to `%s'...", out));
91
92   output (midi_stream);
93   progress_indication ("\n");
94 }
95
96 void
97 Performance::process ()
98 {
99 }
100
101 Performance *
102 unsmob_performance (SCM x)
103 {
104   return dynamic_cast<Performance *> (Music_output::unsmob (x));
105 }