]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-def.cc
e42f2dce6e4e7c3fab47266dd8cb937566fda09b
[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--2003 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 "warn.hh"
14 #include "scm-hash.hh"
15
16 Midi_def::Midi_def ()
17 {
18   // ugh
19   set_tempo (Moment (Rational (1, 4)), 60);
20 }
21
22 int
23 Midi_def::get_tempo (Moment one_beat_mom)
24 {
25   SCM wis  = ly_symbol2scm ("whole-in-seconds");
26   Moment *w = unsmob_moment (lookup_variable (wis));
27
28   Moment wholes_per_min = Moment (60);
29   if (!w)
30     {
31       programming_error  ("wholes-in-seconds not set.");
32       wholes_per_min /= 4;
33     }
34   else
35     {
36       wholes_per_min /= *w; 
37     }
38   
39   int beats_per_min =  int ((wholes_per_min / one_beat_mom).main_part_);
40   return int (beats_per_min);
41 }
42
43 void
44 Midi_def::set_tempo (Moment one_beat_mom, int beats_per_minute_i)
45 {
46   Moment beats_per_second = Moment (beats_per_minute_i) / Moment (60);
47
48   Moment m = Moment (1)/Moment (beats_per_second * one_beat_mom);
49   set_variable (ly_symbol2scm ("whole-in-seconds"), m.smobbed_copy ());
50 }
51