]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-def.cc
release: 0.1.11
[lilypond.git] / lily / midi-def.cc
1 /*
2   midi-def.cc -- implement Midi_def
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
7
8 */
9 #include <math.h>
10 #include "misc.hh"
11 #include "midi-def.hh"
12 #include "input-translator.hh"
13 #include "audio-score.hh"
14 #include "assoc-iter.hh"
15 #include "score-performer.hh"
16 #include "debug.hh"
17
18 // classes, alphasorted
19 //     statics
20 //     constructors
21 //     destructor
22 //     routines, alphasorted
23
24 // statics Midi_def
25 // ugh
26
27 int Midi_def::den_i_s = 4;
28 int Midi_def::num_i_s = 4;
29
30 Midi_def::Midi_def()
31 {
32   outfile_str_ = ""; 
33   itrans_p_ = 0;
34   // ugh
35   set_tempo (Moment (1, 4), 60);
36 }
37
38 Midi_def::Midi_def (Midi_def const& s)
39 {
40   whole_seconds_f_ = s.whole_seconds_f_;
41   itrans_p_ = s.itrans_p_ ? new Input_translator (*s.itrans_p_) : 0;
42   outfile_str_ = s.outfile_str_;
43 }
44
45 Midi_def::~Midi_def()
46 {
47   delete itrans_p_;
48 }
49
50 Real
51 Midi_def::duration_to_seconds_f (Moment mom)
52 {
53   if (!mom)
54         return 0;
55   
56   return Moment (whole_seconds_f_) * mom;
57 }
58
59 Global_translator*
60 Midi_def::get_global_translator_p() 
61 {
62   Global_translator *g =     itrans_p_->get_group_performer_p()->global_l ();
63
64   assert (g->is_type_b (Score_performer::static_name()));
65   Score_performer * perf = (Score_performer*)g;
66   perf->performance_p_ = new Audio_score;
67   perf->performance_p_->midi_l_ = this;
68   return g;
69 }
70
71 int
72 Midi_def::get_tempo_i (Moment moment)
73 {
74   return Moment (whole_seconds_f_) * Moment (60) * moment;
75 }
76
77 void
78 Midi_def::print() const
79 {
80 #ifndef NPRINT
81   DOUT << "Midi {";
82   DOUT << "4/min: " << Real (60) / (whole_seconds_f_ * 4);
83   DOUT << "out: " << outfile_str_;
84   DOUT << "}\n";
85 #endif
86 }
87
88 void
89 Midi_def::set (Input_translator* itrans_p)
90 {
91   delete itrans_p_;
92   itrans_p_ = itrans_p;
93 }
94
95 void
96 Midi_def::set_tempo (Moment moment, int count_per_minute_i)
97 {
98   whole_seconds_f_ = Moment (count_per_minute_i) / Moment (60) / moment;
99 }
100
101 IMPLEMENT_IS_TYPE_B1( Midi_def, Music_output_def);