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 static Mudela_key key_c (0, 0);
18 static Mudela_meter meter_4 (4, 2, 24, 8);
19 // useconds per 4: 250000 === 60 4 per minute
20 static Mudela_tempo tempo_60 (1000000);
22 Mudela_score::Mudela_score (int format_i, int tracks_i, int tempo_i)
27 column_l_array_.push (new Mudela_column (this, Moment (0)));
28 mudela_key_l_ = &key_c;
29 mudela_meter_l_ = &meter_4;
30 mudela_tempo_l_ = &tempo_60;
33 Mudela_score::~Mudela_score()
38 Mudela_score::add_item (Mudela_item* mudela_item_p)
40 mudela_staff_p_list_.bottom()->add_item (mudela_item_p);
44 Mudela_score::add_staff (Mudela_staff* mudela_staff_p)
46 mudela_staff_p_list_.bottom().add (mudela_staff_p);
50 Mudela_score::find_column_l (Moment mom)
52 // should do binary search
53 for (int i = 0; i < column_l_array_.size (); i++ )
54 if ( column_l_array_[i]->at_mom () == mom )
55 return column_l_array_[i];
60 Mudela_score::get_column_l (Moment mom)
62 if ( column_l_array_ [column_l_array_.size() - 1]->at_mom () > mom )
67 if ( column_l_array_[column_l_array_.size() - 1]->at_mom () < mom )
68 column_l_array_.push (new Mudela_column (this, mom));
70 return column_l_array_ [column_l_array_.size() - 1];
74 Mudela_score::output (String filename_str)
76 LOGOUT(NORMAL_ver) << "Lily output to " << filename_str << " ..." << endl;
78 // ugh, ugly midi type 1 fix
79 if ( (mudela_staff_p_list_.size() == 1) && !mudela_staff_p_list_.top()->number_i_)
80 mudela_staff_p_list_.top()->number_i_ = 1;
83 Mudela_stream mudela_stream (filename_str);
84 for (PCursor<Mudela_staff*> i (mudela_staff_p_list_); i.ok(); i++)
86 LOGOUT(NORMAL_ver) << "track " << track_i++ << ": " << flush;
87 i->output (mudela_stream);
88 mudela_stream << "\n";
89 LOGOUT(NORMAL_ver) << endl;
92 mudela_stream << "\\score{\n";
93 if (mudela_staff_p_list_.size() > 1)
94 mudela_stream << "<\n\\multi 3;\n";
95 for (PCursor<Mudela_staff*> i (mudela_staff_p_list_); i.ok(); i++)
97 if ( (mudela_staff_p_list_.size() != 1)
98 && (i == mudela_staff_p_list_.top()))
100 mudela_stream << "\\melodic{ ";
101 mudela_stream << "\\$" << i->id_str();
102 mudela_stream << " }\n";
104 if (mudela_staff_p_list_.size() > 1)
105 mudela_stream << ">\n";
107 mudela_stream << "\\paper{}\n";
109 mudela_stream << "\\midi{\n";
110 // let's not use silly 0 track
111 mudela_staff_p_list_.bottom()->mudela_tempo_p_->output (mudela_stream);
112 mudela_stream << "}\n";
114 mudela_stream << "}\n";
118 Mudela_score::process()
120 LOGOUT(NORMAL_ver) << "\nProcessing..." << endl;
122 LOGOUT(DEBUG_ver) << "columns\n";
123 // for (PCursor<Mudela_column*> i (mudela_column_p_list_); i.ok(); i++)
124 // LOGOUT(DEBUG_ver) << "At: " << i->at_mom() << "\n";
129 quantify_durations();
131 LOGOUT(NORMAL_ver) << "\nCreating voices..." << endl;
133 for (PCursor<Mudela_staff*> i (mudela_staff_p_list_); i.ok(); i++)
135 LOGOUT(NORMAL_ver) << "track " << track_i++ << ": " << flush;
137 LOGOUT(NORMAL_ver) << endl;
142 Mudela_score::filter_tempo()
144 LOGOUT(NORMAL_ver) << "\nNOT Filtering tempo..." << endl;
148 Mudela_score::quantify_columns()
151 if (Duration_convert::no_quantify_b_s)
153 LOGOUT(NORMAL_ver) << "\nNOT Quantifying columns..." << endl;
157 LOGOUT(NORMAL_ver) << "\nQuantifying columns..." << endl;
159 int n = 5 >? Duration_convert::no_smaller_than_i_s;
160 Moment s = Moment (1, n);
161 Moment sh = Moment (1, 2 * n);
162 for (int i = 0; i < column_l_array_.size(); i++)
164 // Moment mom = column_l_array_[ i ]->at_mom();
165 // column_l_array_[ i ]->at_mom_ = Duration_convert::dur2_mom (dur);
166 column_l_array_[ i ]->at_mom_ =
167 // s * (int) ( (sh + column_l_array_[ i ]->at_mom()) / s);
168 s * (int) ( (column_l_array_[ i ]->at_mom()) / s);
169 LOGOUT(NORMAL_ver) << '.';
171 LOGOUT(NORMAL_ver) << endl;
175 Mudela_score::quantify_durations()
177 // LOGOUT(NORMAL_ver) << "\nQuantifying durations..." << endl;
181 Mudela_score::settle_columns()
183 // LOGOUT(NORMAL_ver) << "\nNOT Settling columns..." << endl;
185 LOGOUT(NORMAL_ver) << "\nSettling columns..." << endl;
188 assert (!column_l_array_.size());
189 int n = mudela_column_p_list_.size();
191 // column_l_array_.set_size (n);
192 for (PCursor<Mudela_column*> i (mudela_column_p_list_); i.ok(); i++)
193 column_l_array_.push (*i);
196 int n = column_l_array_.size();
200 Moment start_mom = 0;
201 Duration smallest_dur;
202 smallest_dur.durlog_i_ = 6;
203 Moment const noise_mom = Duration_convert::dur2_mom (smallest_dur)
205 for (int i = 0; i < n; i++)
210 start_mom = column_l_array_[ i ]->at_mom();
214 // find all columns within noise's distance
216 && (column_l_array_[ i ]->at_mom() - start_mom < noise_mom))
219 // bluntly set all to time of first in group
220 for (int j = start_i; j < end_i; j++)
221 column_l_array_[ j ]->at_mom_ = start_mom;