]> git.donarmstrong.com Git - lilypond.git/blob - lily/performance.cc
0bfe37ee826581ccab7815b50afd71930725740f
[lilypond.git] / lily / performance.cc
1 /*
2   performance.cc -- implement Performance
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2006 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "performance.hh"
10
11 #include <ctime>
12 using namespace std;
13
14 #include "audio-column.hh"
15 #include "audio-staff.hh"
16 #include "file-name.hh"
17 #include "international.hh"
18 #include "lily-version.hh"
19 #include "main.hh"
20 #include "midi-item.hh"
21 #include "midi-stream.hh"
22 #include "score.hh"
23 #include "string-convert.hh"
24 #include "warn.hh"
25
26 Performance::Performance ()
27 {
28   midi_ = 0;
29 }
30
31 Performance::~Performance ()
32 {
33   junk_pointers (audio_elements_);
34 }
35
36 void
37 Performance::output (Midi_stream &midi_stream)
38 {
39   int tracks_ = audio_staffs_.size ();
40
41   // ugh
42   int clocks_per_4 = 384;
43
44   midi_stream << Midi_header (1, tracks_, clocks_per_4);
45   message (_ ("Track...") + " ");
46   int channel = 0;
47   for (vsize i = 0; i < audio_staffs_.size (); i++)
48     {
49       Audio_staff *s = audio_staffs_[i];
50       if (be_verbose_global)
51         progress_indication ("[" + to_string (i));
52
53       /*
54         MIDI players tend to ignore instrument settings on
55         channel 10, the percussion channel by default.
56       */
57       if (channel % 16 == 9)
58         channel++;
59
60       /*
61         Huh? Why does each staff also have a separate channel? We
62         should map channels to voices, not staves. --hwn.
63       */
64       if (channel > 15)
65         {
66           warning (_ ("MIDI channel wrapped around"));
67           warning (_ ("remapping modulo 16"));
68         }
69
70       s->output (midi_stream, channel);
71       channel ++;
72       if (be_verbose_global)
73         progress_indication ("]");
74     }
75 }
76
77 void
78 Performance::add_element (Audio_element *p)
79 {
80   audio_elements_.push_back (p);
81 }
82
83 void
84 Performance::write_output (string out)
85 {
86   if (out == "-")
87     out = "lelie.midi";
88
89   /* Maybe a bit crude, but we had this before */
90   File_name file_name (out);
91   file_name.ext_ = "midi";
92   out = file_name.to_string ();
93
94   Midi_stream midi_stream (out);
95   message (_f ("MIDI output to `%s'...", out));
96
97   output (midi_stream);
98   progress_indication ("\n");
99 }
100
101