]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-def.cc
release: 1.3.61
[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--2000 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 "score-performer.hh"
15 #include "debug.hh"
16
17 Midi_def::Midi_def()
18 {
19   // ugh
20   set_tempo (Moment (1, 4), 60);
21 }
22
23 Midi_def::~Midi_def()
24 {
25 }
26
27 Real
28 Midi_def::length_mom_to_seconds_f (Moment mom)
29 {
30   if (!mom)
31     return 0;
32   
33   return Moment (whole_in_seconds_mom_) * mom;
34 }
35
36
37 int
38 Midi_def::get_tempo_i (Moment one_beat_mom)
39 {
40   Moment wholes_per_min = Moment(60) /Moment(whole_in_seconds_mom_);
41   int beats_per_min = wholes_per_min / one_beat_mom;
42   return int (beats_per_min);
43 }
44
45 void
46 Midi_def::set_tempo (Moment one_beat_mom, int beats_per_minute_i)
47 {
48   Moment beats_per_second = Moment (beats_per_minute_i) / Moment (60);
49   whole_in_seconds_mom_ = Moment(1)/Moment(beats_per_second * one_beat_mom);
50 }
51
52 void
53 Midi_def::print() const
54 {
55 #ifndef NPRINT
56   DEBUG_OUT << "MIDI {\n";
57   Music_output_def::print ();
58   DEBUG_OUT << "4/min: " << Moment (60) / (whole_in_seconds_mom_ * Moment (4));
59   DEBUG_OUT << "}\n";  
60 #endif
61 }
62
63 int Midi_def::default_count_i_=0;
64
65 int
66 Midi_def::get_next_default_count () const
67 {
68   return default_count_i_++;
69 }
70
71 void
72 Midi_def::reset_default_count ()
73 {
74   default_count_i_ = 0;
75 }