2 // mudela-score.cc -- implement Mudela_score
4 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
9 #include "duration-convert.hh"
10 #include "mi2mu-global.hh"
11 #include "mudela-column.hh"
12 #include "mudela-item.hh"
13 #include "mudela-score.hh"
14 #include "mudela-staff.hh"
15 #include "mudela-stream.hh"
17 // ugh, cygnus' b19 gcc
21 //static Mudela_key key_c (0, 0);
22 static Mudela_meter meter_4 (4, 2, 24, 8);
23 // useconds per 4: 250000 === 60 4 per minute
24 static Mudela_tempo tempo_60 (1000000);
26 Mudela_score::Mudela_score (int format_i, int tracks_i, int tempo_i)
31 column_l_array_.push (new Mudela_column (this, Moment (0)));
32 // mudela_key_l_ = &key_c;
34 mudela_meter_l_ = &meter_4;
35 mudela_tempo_l_ = &tempo_60;
38 Mudela_score::~Mudela_score()
43 Mudela_score::add_item (Mudela_item* mudela_item_p)
45 mudela_staff_p_list_.bottom()->add_item (mudela_item_p);
49 Mudela_score::add_staff (Mudela_staff* mudela_staff_p)
51 mudela_staff_p_list_.bottom().add (mudela_staff_p);
55 Mudela_score::find_column_l (Moment mom)
58 // should do binary search
59 for (int i = 0; i < column_l_array_.size (); i++ )
60 if ( column_l_array_[i]->at_mom () == mom )
61 return column_l_array_[i];
64 int upper_i = max (0, column_l_array_.size () - 1);
69 Moment i_mom = column_l_array_ [i]->at_mom ();
71 return column_l_array_ [i];
76 if ((upper_i == lower_i) || (i == column_l_array_.size () - 1))
78 // we don't do inserts
80 Mudela_column* col_p = new Mudela_column (this, mom);
81 column_l_array_.push (col_p);
84 i = (upper_i + lower_i + 1 ) / 2;
92 Mudela_score::get_column_l (Moment mom)
94 if ( column_l_array_ [column_l_array_.size() - 1]->at_mom () > mom )
99 if ( column_l_array_[column_l_array_.size() - 1]->at_mom () < mom )
100 column_l_array_.push (new Mudela_column (this, mom));
102 return column_l_array_ [column_l_array_.size() - 1];
106 Mudela_score::output (String filename_str)
108 LOGOUT(NORMAL_ver) << _("Lily output to ") << filename_str << " ..." << endl;
110 // ugh, ugly midi type 1 fix
111 if ( (mudela_staff_p_list_.size() == 1) && !mudela_staff_p_list_.top()->number_i_)
112 mudela_staff_p_list_.top()->number_i_ = 1;
115 Mudela_stream mudela_stream (filename_str);
116 for (PCursor<Mudela_staff*> i (mudela_staff_p_list_); i.ok(); i++)
118 LOGOUT(NORMAL_ver) << _("track ") << track_i++ << ": " << flush;
119 i->output (mudela_stream);
120 mudela_stream << "\n";
121 LOGOUT(NORMAL_ver) << endl;
124 mudela_stream << "\\score{\n";
125 if (mudela_staff_p_list_.size() > 1)
126 mudela_stream << "\\multi 3 < \\type Staff\n";
127 for (PCursor<Mudela_staff*> i (mudela_staff_p_list_); i.ok(); i++)
129 if ( (mudela_staff_p_list_.size() != 1)
130 && (i == mudela_staff_p_list_.top()))
132 mudela_stream << "< \\melodic{ ";
133 mudela_stream << "\\$" << i->id_str();
134 mudela_stream << " } >\n";
136 if (mudela_staff_p_list_.size() > 1)
137 mudela_stream << ">\n";
139 mudela_stream << "\\paper{}\n";
141 mudela_stream << "\\midi{\n";
142 // let's not use silly 0 track
143 mudela_staff_p_list_.bottom()->mudela_tempo_l_->output (mudela_stream);
144 mudela_stream << "}\n";
146 mudela_stream << "}\n";
150 Mudela_score::process()
152 LOGOUT(NORMAL_ver) << _("\nProcessing...") << endl;
154 LOGOUT(DEBUG_ver) << "columns\n";
155 // for (PCursor<Mudela_column*> i (mudela_column_p_list_); i.ok(); i++)
156 // LOGOUT(DEBUG_ver) << "At: " << i->at_mom() << "\n";
161 quantify_durations();
163 LOGOUT(NORMAL_ver) << _("\nCreating voices...") << endl;
165 for (PCursor<Mudela_staff*> i (mudela_staff_p_list_); i.ok(); i++)
167 LOGOUT(NORMAL_ver) << _("track ") << track_i++ << ": " << flush;
169 LOGOUT(NORMAL_ver) << endl;
174 Mudela_score::filter_tempo()
176 LOGOUT(NORMAL_ver) << _("\nNOT Filtering tempo...") << endl;
180 Mudela_score::quantify_columns()
183 if (Duration_convert::no_quantify_b_s)
185 LOGOUT(NORMAL_ver) << _("\nNOT Quantifying columns...") << endl;
189 LOGOUT(NORMAL_ver) << _("\nQuantifying columns...") << endl;
191 int current_bar_i = 0;
192 Moment bar_mom = mudela_meter_l_->bar_mom();
194 int n = 5 >? Duration_convert::no_smaller_than_i_s;
195 n = Duration_convert::type2_i (n);
196 Moment s = Moment (1, n);
197 Moment sh = Moment (1, 2 * n);
198 for (int i = 0; i < column_l_array_.size(); i++)
200 column_l_array_ [i]->at_mom_ =
201 s * Moment( (int) ( (column_l_array_ [i]->at_mom()) / s));
203 int bar_i = (int) (column_l_array_ [i]->at_mom () / bar_mom) + 1;
204 if (bar_i > current_bar_i)
206 LOGOUT (NORMAL_ver) << '[' << bar_i << ']' << flush;
207 current_bar_i = bar_i;
210 LOGOUT(NORMAL_ver) << endl;
214 Mudela_score::quantify_durations()
216 // LOGOUT(NORMAL_ver) << "\nQuantifying durations..." << endl;
220 Mudela_score::settle_columns()
222 // LOGOUT(NORMAL_ver) << "\nNOT Settling columns..." << endl;
224 LOGOUT(NORMAL_ver) << _("\nSettling columns...") << endl;
227 assert (!column_l_array_.size());
228 int n = mudela_column_p_list_.size();
230 // column_l_array_.set_size (n);
231 for (PCursor<Mudela_column*> i (mudela_column_p_list_); i.ok(); i++)
232 column_l_array_.push (*i);
235 int n = column_l_array_.size();
239 Moment start_mom = 0;
240 Duration smallest_dur;
241 smallest_dur.durlog_i_ = 6;
242 Moment const noise_mom = Duration_convert::dur2_mom (smallest_dur)
244 for (int i = 0; i < n; i++)
249 start_mom = column_l_array_ [i]->at_mom();
253 // find all columns within noise's distance
255 && (column_l_array_ [i]->at_mom() - start_mom < noise_mom))
258 // bluntly set all to time of first in group
259 for (int j = start_i; j < end_i; j++)
260 column_l_array_ [j]->at_mom_ = start_mom;