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