]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-def.cc
release: 1.1.5
[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--1998 Jan Nieuwenhuizen <janneke@gnu.org>
7
8 */
9 #include <math.h>
10 #include "misc.hh"
11 #include "midi-def.hh"
12 #include "translator.hh"
13 #include "performance.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 Midi_def::Midi_def()
25 {
26   // ugh
27   set_tempo (Moment (1, 4), 60);
28 }
29
30 Midi_def::~Midi_def()
31 {
32 }
33
34 Real
35 Midi_def::duration_to_seconds_f (Moment mom)
36 {
37   if (!mom)
38     return 0;
39   
40   return Moment (whole_in_seconds_mom_) * mom;
41 }
42
43
44 int
45 Midi_def::get_tempo_i (Moment one_beat_mom)
46 {
47   Moment wholes_per_min = Moment(60) /Moment(whole_in_seconds_mom_);
48   int beats_per_min = wholes_per_min / one_beat_mom;
49   return int (beats_per_min);
50 }
51
52 void
53 Midi_def::set_tempo (Moment one_beat_mom, int beats_per_minute_i)
54 {
55   Moment beats_per_second = Moment (beats_per_minute_i) / Moment (60);
56   whole_in_seconds_mom_ = Moment(1)/Moment(beats_per_second * one_beat_mom);
57 }
58
59 void
60 Midi_def::print() const
61 {
62 #ifndef NPRINT
63   Music_output_def::print ();
64   DOUT << "Midi {";
65   DOUT << "4/min: " << Moment (60) / (whole_in_seconds_mom_ * Moment (4));
66   DOUT << "}\n";
67 #endif
68 }
69
70
71 IMPLEMENT_IS_TYPE_B1(Midi_def, Music_output_def);
72
73 int Midi_def::default_count_i_=0;
74 int
75 Midi_def::get_next_default_count () const
76 {
77   return default_count_i_++;
78 }
79
80 void
81 Midi_def::reset_default_count ()
82 {
83   default_count_i_ = 0;
84 }