2 // mudela-item.cc -- implement Mudela_item
4 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
6 #include "mi2mu-global.hh"
7 #include "string-convert.hh"
8 #include "duration-convert.hh"
9 #include "mudela-column.hh"
10 #include "mudela-item.hh"
11 #include "mudela-stream.hh"
12 #include "mudela-score.hh"
14 Mudela_item::Mudela_item (Mudela_column* mudela_column_l)
16 mudela_column_l_ = mudela_column_l;
22 return mudela_column_l_->at_mom();
26 Mudela_item::duration_mom()
32 Mudela_item::output (Mudela_stream& mudela_stream_r)
34 mudela_stream_r << str() << String (" ");
37 Mudela_key::Mudela_key (int accidentals_i, int minor_i)
40 accidentals_i_ = accidentals_i;
42 if (accidentals_i >= 0)
43 key_i_ = ((accidentals_i % 7)[ "cgdaebf" ] - 'a' - 2) % 7;
45 key_i_ = ((-accidentals_i % 7)[ "cfbeadg" ] - 'a' - 2) % 7;
51 String str = "\\key ";
53 str += String ((char) ((key_i_ + 2) % 7 + 'A'));
54 else // heu, -2: should be - 1 1/2: A -> fis
55 str += String ((char) ((key_i_ + 2 - 2) % 7 + 'a'));
56 str = String ("% \"") + str
57 + String('"') + "; % not supported yet\n";
62 Mudela_key::notename_str (int pitch_i)
64 // this may seem very smart,
65 // but it-s only an excuse not to read a notename table
68 // minor scale: la-la (= + 5)
69 static int notename_i_a[ 12 ] = { 0, 0, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6 };
70 int notename_i = notename_i_a[ (minor_i_ * 5 + pitch_i) % 12 ];
72 static int accidentals_i_a[ 12 ] = { 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0 };
73 int accidental_i = accidentals_i_a[ minor_i_ * 5 + pitch_i % 12 ];
74 if (accidental_i && (accidentals_i_ < 0))
76 accidental_i = - accidental_i;
77 notename_i = (notename_i + 1) % 7;
80 String notename_str = (char) ( ((notename_i + 2) % 7) + 'a');
81 while (accidental_i-- > 0)
84 while (accidental_i++ < 0)
85 if ((notename_str == "a") || (notename_str == "e"))
91 String de_octavate_str = String ('\'', (Mudela_note::c0_pitch_i_c_ + 11 - pitch_i) / 12);
92 String octavate_str = String ('\'', (pitch_i - Mudela_note::c0_pitch_i_c_) / 12);
93 return de_octavate_str + notename_str + octavate_str;
96 Mudela_meter::Mudela_meter (int num_i, int den_i, int clocks_4_i, int count_32_i)
99 sync_dur_.durlog_i_ = 3 ;
102 warning (String ("#32 in quarter: ") + String (count_32_i));
105 clocks_1_i_ = clocks_4_i * 4;
109 Mudela_meter::bar_mom()
112 d.durlog_i_ = den_i_;
113 return Moment (num_i_) * Duration_convert::dur2_mom (d);
117 Mudela_meter::clocks_1_i()
123 Mudela_meter::den_i()
129 Mudela_meter::num_i()
137 String str = "\\meter "
138 + String (num_i_) + "/" + String (1 << den_i_)
144 // statics Mudela_note
146 this switch can be used to write simple plets like
149 \plet 2/3; c4 \plet 1/1;
151 bool const Mudela_note::simple_plet_b_s = true;
153 Mudela_note::Mudela_note (Mudela_column* mudela_column_l, int channel_i, int pitch_i, int dyn_i)
154 : Mudela_item (mudela_column_l)
158 channel_i_ = channel_i;
166 Duration dur = duration();
167 if (dur.durlog_i_ < -10)
171 = mudela_column_l_->mudela_score_l_->mudela_key_l_->notename_str (pitch_i_);
174 return name_str + Duration_convert::dur2_str (dur) + " ";
179 str += String ("\\plet ")
180 + String_convert::i2dec_str (dur.plet_.iso_i_, 0, 0)
182 + String_convert::i2dec_str (dur.plet_.type_i_, 0, 0)
189 str += Duration_convert::dur2_str (tmp);
192 str += String (" \\plet 1/1;");
198 Mudela_note::duration()
200 assert (end_column_l_);
201 Moment mom = end_column_l_->at_mom() - at_mom();
202 return Duration_convert::mom2_dur (mom);
206 Mudela_note::duration_mom()
209 // return Duration_convert::dur2_mom (duration());
210 return end_column_l_->at_mom() - at_mom();
213 Mudela_skip::Mudela_skip (Mudela_column* mudela_column_l, Moment skip_mom)
214 : Mudela_item (mudela_column_l)
220 Mudela_skip::duration()
222 return Duration_convert::mom2_dur (mom_);
226 Mudela_skip::duration_mom()
228 return Duration_convert::dur2_mom (duration());
237 Duration dur = duration();
238 if (dur.durlog_i_<-10)
241 String str = "\\skip ";
242 str += Duration_convert::dur2_str (dur) + "; ";
247 Mudela_tempo::Mudela_tempo (int useconds_per_4_i)
250 useconds_per_4_i_ = useconds_per_4_i;
251 seconds_per_1_f_ = (Real)useconds_per_4_i_ * 4 / 1e6;
257 String str = "\\tempo 4=";
258 str += String (get_tempo_i (Moment (1, 4)));
264 Mudela_tempo::useconds_per_4_i()
266 return useconds_per_4_i_;
270 Mudela_tempo::get_tempo_i (Moment moment)
272 return Moment (60) / moment / Moment (seconds_per_1_f_);
275 Mudela_text::Mudela_text (Mudela_text::Type type, String text_str)
279 text_str_ = text_str;
285 if (!text_str_.length_i()
286 || (text_str_.length_i() != (int)strlen (text_str_.ch_C())))
289 return "% " + text_str_ + "\n";