2 // mudela-score.cc -- implement Mudela_score
4 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
8 #include "duration-convert.hh"
9 #include "mi2mu-global.hh"
10 #include "mudela-column.hh"
11 #include "mudela-item.hh"
12 #include "mudela-score.hh"
13 #include "mudela-staff.hh"
14 #include "mudela-stream.hh"
16 Mudela_score::Mudela_score (int format_i, int tracks_i, int tempo_i)
21 mudela_column_p_list_.bottom().add (new Mudela_column (this, Moment (0)));
24 Mudela_score::~Mudela_score()
29 Mudela_score::add_item (Mudela_item* mudela_item_p)
31 mudela_staff_p_list_.bottom()->add_item (mudela_item_p);
35 Mudela_score::add_staff (Mudela_staff* mudela_staff_p)
37 mudela_staff_p_list_.bottom().add (mudela_staff_p);
41 Mudela_score::mudela_column_l (Moment mom)
43 for (PCursor<Mudela_column*> i (mudela_column_p_list_); i.ok(); i++) {
44 if (i->at_mom() > mom) {
45 Mudela_column* p = new Mudela_column (this, mom);
49 if (i->at_mom() == mom)
53 Mudela_column* p = new Mudela_column (this, mom);
54 mudela_column_p_list_.bottom().add (p);
59 Mudela_score::output (String filename_str)
61 LOGOUT(NORMAL_ver) << "Lily output to " << filename_str << " ..." << endl;
63 // ugh, ugly midi type 1 fix
64 if ( (mudela_staff_p_list_.size() == 1) && !mudela_staff_p_list_.top()->number_i_)
65 mudela_staff_p_list_.top()->number_i_ = 1;
68 Mudela_stream mudela_stream (filename_str);
69 for (PCursor<Mudela_staff*> i (mudela_staff_p_list_); i.ok(); i++) {
70 LOGOUT(NORMAL_ver) << "track " << track_i++ << ": " << flush;
71 i->output (mudela_stream);
72 mudela_stream << "\n";
73 LOGOUT(NORMAL_ver) << endl;
76 mudela_stream << "\\score{\n";
77 if (mudela_staff_p_list_.size() > 1)
78 mudela_stream << "<\n\\multi 3;\n";
79 for (PCursor<Mudela_staff*> i (mudela_staff_p_list_); i.ok(); i++) {
80 if ( (mudela_staff_p_list_.size() != 1)
81 && (i == mudela_staff_p_list_.top()))
83 mudela_stream << "\\melodic{ ";
84 mudela_stream << "\\$" << i->id_str();
85 mudela_stream << " }\n";
87 if (mudela_staff_p_list_.size() > 1)
88 mudela_stream << ">\n";
90 mudela_stream << "\\paper{}\n";
92 mudela_stream << "\\midi{ ";
93 // let's not use silly 0 track
94 mudela_staff_p_list_.bottom()->mudela_tempo_p_->output (mudela_stream);
95 mudela_stream << "}\n";
97 mudela_stream << "}\n";
101 Mudela_score::process()
103 LOGOUT(NORMAL_ver) << "\nProcessing..." << endl;
105 LOGOUT(DEBUG_ver) << "columns\n";
106 for (PCursor<Mudela_column*> i (mudela_column_p_list_); i.ok(); i++)
107 LOGOUT(DEBUG_ver) << "At: " << i->at_mom() << "\n";
112 quantify_durations();
114 LOGOUT(NORMAL_ver) << "\nCreating voices..." << endl;
116 for (PCursor<Mudela_staff*> i (mudela_staff_p_list_); i.ok(); i++) {
117 LOGOUT(NORMAL_ver) << "track " << track_i++ << ": " << flush;
119 LOGOUT(NORMAL_ver) << endl;
124 Mudela_score::filter_tempo()
126 LOGOUT(NORMAL_ver) << "\nNOT Filtering tempo..." << endl;
130 Mudela_score::quantify_columns()
133 if (Duration_convert::no_quantify_b_s) {
134 LOGOUT(NORMAL_ver) << "\nNOT Quantifying columns..." << endl;
138 LOGOUT(NORMAL_ver) << "\nQuantifying columns..." << endl;
140 int n = 32 >? Duration_convert::no_smaller_than_i_s;
141 Moment s = Moment (1, n);
142 Moment sh = Moment (1, 2 * n);
143 for (int i = 0; i < column_l_array_.size(); i++) {
144 // Moment mom = column_l_array_[ i ]->at_mom();
145 // column_l_array_[ i ]->at_mom_ = Duration_convert::dur2_mom (dur);
146 column_l_array_[ i ]->at_mom_ =
147 // s * (int) ( (sh + column_l_array_[ i ]->at_mom()) / s);
148 s * (int) ( (column_l_array_[ i ]->at_mom()) / s);
149 LOGOUT(NORMAL_ver) << '.';
151 LOGOUT(NORMAL_ver) << endl;
155 Mudela_score::quantify_durations()
157 // LOGOUT(NORMAL_ver) << "\nQuantifying durations..." << endl;
161 Mudela_score::settle_columns()
163 // LOGOUT(NORMAL_ver) << "\nNOT Settling columns..." << endl;
165 LOGOUT(NORMAL_ver) << "\nSettling columns..." << endl;
167 assert (!column_l_array_.size());
168 int n = mudela_column_p_list_.size();
170 // column_l_array_.set_size (n);
171 for (PCursor<Mudela_column*> i (mudela_column_p_list_); i.ok(); i++)
172 column_l_array_.push (*i);
176 Moment start_mom = 0;
177 Duration smallest_dur;
178 smallest_dur.type_i_ = 64;
179 Moment const noise_mom = Duration_convert::dur2_mom (smallest_dur)
181 for (int i = 0; i < n; i++) {
184 start_mom = column_l_array_[ i ]->at_mom();
188 // find all columns within noise's distance
190 && (column_l_array_[ i ]->at_mom() - start_mom < noise_mom))
193 // bluntly set all to time of first in group
194 for (int j = start_i; j < end_i; j++)
195 column_l_array_[ j ]->at_mom_ = start_mom;