]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-def.cc
release: 1.3.71
[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 "performance.hh"
13 #include "debug.hh"
14 #include "scope.hh"
15
16 Midi_def::Midi_def()
17 {
18   // ugh
19   set_tempo (Moment (1, 4), 60);
20 }
21
22 Midi_def::~Midi_def()
23 {
24 }
25
26
27
28 int
29 Midi_def::get_tempo_i (Moment one_beat_mom)
30 {
31   Moment w = *unsmob_moment (scope_p_->scm_elem ("whole-in-seconds"));
32   Moment wholes_per_min = Moment(60) /w;
33   int beats_per_min = wholes_per_min / one_beat_mom;
34   return int (beats_per_min);
35 }
36
37 void
38 Midi_def::set_tempo (Moment one_beat_mom, int beats_per_minute_i)
39 {
40   Moment beats_per_second = Moment (beats_per_minute_i) / Moment (60);
41
42   Moment *m = new Moment (Moment(1)/Moment(beats_per_second * one_beat_mom));
43   scope_p_->set ("whole-in-seconds", smobify (m));
44 }
45
46
47 int Midi_def::default_count_i_=0;
48
49 int
50 Midi_def::get_next_default_count () const
51 {
52   return default_count_i_++;
53 }
54
55 void
56 Midi_def::reset_default_count ()
57 {
58   default_count_i_ = 0;
59 }