]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-def.cc
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / lily / midi-def.cc
1 /*
2   midi-def.cc -- implement midi output def functions
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2006 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9
10 #include "misc.hh"
11 #include "output-def.hh"
12 #include "moment.hh"
13 #include "warn.hh"
14 #include "scm-hash.hh"
15
16 int
17 get_tempo (Output_def *def,
18            Moment one_beat_mom)
19 {
20   SCM wis = ly_symbol2scm ("whole-in-seconds");
21   Moment *w = unsmob_moment (def->lookup_variable (wis));
22
23   Moment wholes_per_min = Moment (60);
24   if (!w)
25     {
26       programming_error ("wholes-in-seconds not set.");
27       wholes_per_min /= 4;
28     }
29   else
30     wholes_per_min /= *w;
31
32   Rational beats_per_min =  (wholes_per_min / one_beat_mom).main_part_;
33   return beats_per_min.to_int ();
34 }
35
36 void
37 set_tempo (Output_def *def,
38            Moment one_beat_mom,
39            int beats_per_minute_i)
40 {
41   Moment beats_per_second = Moment (beats_per_minute_i) / Moment (60);
42
43   Moment m = Moment (1) / Moment (beats_per_second * one_beat_mom);
44   def->set_variable (ly_symbol2scm ("whole-in-seconds"), m.smobbed_copy ());
45 }
46