new file. (Thanks Hendrik Maryns)
[lilypond.git] / lily / midi-def.cc
blobd30e94e599a37407ce6961c735ced9e4d28ae346
1 /*
2 midi-def.cc -- implement midi output def functions
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9 #include <math.h>
11 #include "misc.hh"
12 #include "output-def.hh"
13 #include "moment.hh"
14 #include "warn.hh"
15 #include "scm-hash.hh"
19 int
20 get_tempo (Output_def * def,
21 Moment one_beat_mom)
23 SCM wis = ly_symbol2scm ("whole-in-seconds");
24 Moment *w = unsmob_moment (def->lookup_variable (wis));
26 Moment wholes_per_min = Moment (60);
27 if (!w)
29 programming_error ("wholes-in-seconds not set.");
30 wholes_per_min /= 4;
32 else
34 wholes_per_min /= *w;
37 int beats_per_min = int ((wholes_per_min / one_beat_mom).main_part_);
38 return int (beats_per_min);
41 void
42 set_tempo (Output_def * def,
43 Moment one_beat_mom,
44 int beats_per_minute_i)
46 Moment beats_per_second = Moment (beats_per_minute_i) / Moment (60);
48 Moment m = Moment (1)/Moment (beats_per_second * one_beat_mom);
49 def->set_variable (ly_symbol2scm ("whole-in-seconds"), m.smobbed_copy ());