]> git.donarmstrong.com Git - lilypond.git/blob - lily/performance.cc
Admin: run yearly grand-replace.
[lilypond.git] / lily / performance.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2011 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-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 Performance::Performance ()
38 {
39   midi_ = 0;
40 }
41
42 Performance::~Performance ()
43 {
44   junk_pointers (audio_elements_);
45 }
46
47 void
48 Performance::output (Midi_stream &midi_stream) const
49 {
50   int tracks_ = audio_staffs_.size ();
51
52   midi_stream.write (Midi_header (1, tracks_, 384));
53   if (be_verbose_global)
54     progress_indication (_ ("Track...") + " ");
55   
56   int channel = 0;
57   for (vsize i = 0; i < audio_staffs_.size (); i++)
58     {
59       Audio_staff *s = audio_staffs_[i];
60       if (be_verbose_global)
61         progress_indication ("[" + to_string (i));
62
63       int midi_channel =  s->channel_;
64
65       if (midi_channel < 0)
66         {
67           midi_channel = channel;
68           channel ++;
69           /*
70             MIDI players tend to ignore instrument settings on
71             channel 10, the percussion channel.
72           */
73           if (channel % 16 == 9)
74             channel ++;
75         }
76
77       /*
78         Huh? Why does each staff also have a separate channel? We
79         should map channels to voices, not staves. --hwn.
80       */
81       if (midi_channel > 15)
82         {
83           warning (_ ("MIDI channel wrapped around"));
84           warning (_ ("remapping modulo 16"));
85
86           midi_channel = midi_channel % 16; 
87         }
88
89       s->output (midi_stream, midi_channel);
90       if (be_verbose_global)
91         progress_indication ("]");
92     }
93 }
94 void
95 Performance::add_element (Audio_element *p)
96 {
97   audio_elements_.push_back (p);
98 }
99
100 void
101 Performance::write_output (string out) const
102 {
103   if (out == "-")
104     out = "lelie.midi";
105
106   /* Maybe a bit crude, but we had this before */
107   File_name file_name (out);
108   out = file_name.to_string ();
109
110   Midi_stream midi_stream (out);
111   message (_f ("MIDI output to `%s'...", out));
112
113   output (midi_stream);
114   progress_indication ("\n");
115 }
116
117
118 void
119 Performance::process ()
120 {
121 }
122
123 Performance *
124 unsmob_performance (SCM x)
125 {
126   return dynamic_cast<Performance*> (unsmob_music_output (x));
127 }