]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-def.cc
* flower
[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--2005 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include <math.h>
10
11 #include "misc.hh"
12 #include "output-def.hh"
13 #include "moment.hh"
14 #include "warn.hh"
15 #include "scm-hash.hh"
16
17 int
18 get_tempo (Output_def *def,
19            Moment one_beat_mom)
20 {
21   SCM wis = ly_symbol2scm ("whole-in-seconds");
22   Moment *w = unsmob_moment (def->lookup_variable (wis));
23
24   Moment wholes_per_min = Moment (60);
25   if (!w)
26     {
27       programming_error ("wholes-in-seconds not set.");
28       wholes_per_min /= 4;
29     }
30   else
31     {
32       wholes_per_min /= *w;
33     }
34
35   int beats_per_min = int ((wholes_per_min / one_beat_mom).main_part_);
36   return int (beats_per_min);
37 }
38
39 void
40 set_tempo (Output_def *def,
41            Moment one_beat_mom,
42            int beats_per_minute_i)
43 {
44   Moment beats_per_second = Moment (beats_per_minute_i) / Moment (60);
45
46   Moment m = Moment (1) / Moment (beats_per_second * one_beat_mom);
47   def->set_variable (ly_symbol2scm ("whole-in-seconds"), m.smobbed_copy ());
48 }
49