]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-def.cc
release: 0.0.77.jcn1
[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 Jan Nieuwenhuizen <jan@digicash.com>
7
8 */
9 #include <math.h>
10 #include "misc.hh"
11 #include "midi-def.hh"
12 #include "input-translator.hh"
13 #include "performer-group-performer.hh"
14 #include "assoc-iter.hh"
15
16 #include "debug.hh"
17
18 // classes, alphasorted
19 //     statics
20 //     constructors
21 //     destructor
22 //     routines, alphasorted
23
24 // statics Midi_def
25 // ugh
26 int Midi_def::den_i_s = 4;
27 int Midi_def::num_i_s = 4;
28
29 Midi_def::Midi_def()
30 {
31     outfile_str_ = "lelie.midi"; 
32     itrans_p_ = 0;
33     real_vars_p_ = new Assoc<String,Real>;
34     // ugh
35     set_tempo( Moment( 1, 4 ), 60 );
36 }
37
38 Midi_def::Midi_def( Midi_def const& s )
39 {
40     whole_seconds_f_ = s.whole_seconds_f_;
41     itrans_p_ = s.itrans_p_ ? new Input_translator( *s.itrans_p_ ) : 0;
42     real_vars_p_ = new Assoc<String,Real> ( *s.real_vars_p_ );
43     outfile_str_ = s.outfile_str_;
44 }
45
46 Midi_def::~Midi_def()
47 {
48     delete itrans_p_;
49     delete real_vars_p_;
50 }
51
52 Real
53 Midi_def::duration_to_seconds_f( Moment mom )
54 {
55     if ( !mom )
56         return 0;
57     
58     return Moment( whole_seconds_f_ ) * mom;
59 }
60
61 Global_translator*
62 Midi_def::get_global_translator_p() const
63 {
64     return  itrans_p_->get_group_performer_p()->global_l();
65 }
66
67 Real
68 Midi_def::get_var( String s ) const
69 {
70     if ( !real_vars_p_->elt_b( s ) )
71         error ( "unknown midi variable `"  + s + "'" );
72     return real_vars_p_->elem( s );
73 }
74
75 int
76 Midi_def::get_tempo_i( Moment moment )
77 {
78     return Moment( whole_seconds_f_ ) * Moment( 60 ) * moment;
79 }
80
81 void
82 Midi_def::print() const
83 {
84 #ifndef NPRINT
85     mtor << "Midi {";
86     mtor << "4/min: " << Real( 60 ) / ( whole_seconds_f_ * 4 );
87     mtor << "out: " << outfile_str_;
88     for (Assoc_iter<String,Real> i( *real_vars_p_ ); i.ok(); i++) {
89         mtor << i.key() << "= " << i.val() << "\n";
90     }
91     mtor << "}\n";
92 #endif
93 }
94
95 void
96 Midi_def::set( Input_translator* itrans_p )
97 {
98     delete itrans_p_;
99     itrans_p_ = itrans_p;
100 }
101
102 void
103 Midi_def::set_tempo( Moment moment, int count_per_minute_i )
104 {
105     whole_seconds_f_ = Moment( count_per_minute_i ) / Moment( 60 ) / moment;
106 }
107
108 void
109 Midi_def::set_var( String s, Real r )
110 {
111    real_vars_p_->elem( s ) = r;
112 }
113