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