]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-def.cc
release: 0.1.9
[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 "performer-group-performer.hh"
14 #include "assoc-iter.hh"
15
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() const
61 {
62   return  itrans_p_->get_group_performer_p()->global_l ();
63 }
64
65 int
66 Midi_def::get_tempo_i (Moment moment)
67 {
68   return Moment (whole_seconds_f_) * Moment (60 ) * moment;
69 }
70
71 void
72 Midi_def::print() const
73 {
74 #ifndef NPRINT
75   DOUT << "Midi {";
76   DOUT << "4/min: " << Real (60) / ( whole_seconds_f_ * 4 );
77   DOUT << "out: " << outfile_str_;
78   DOUT << "}\n";
79 #endif
80 }
81
82 void
83 Midi_def::set (Input_translator* itrans_p)
84 {
85   delete itrans_p_;
86   itrans_p_ = itrans_p;
87 }
88
89 void
90 Midi_def::set_tempo (Moment moment, int count_per_minute_i)
91 {
92   whole_seconds_f_ = Moment (count_per_minute_i) / Moment (60 ) / moment;
93 }
94