Mudela_score::Mudela_score (int format_i, int tracks_i, int tempo_i)
{
- format_i_ = format_i;
- tracks_i_ = tracks_i;
- tempo_i_ = tempo_i;
- mudela_column_p_list_.bottom().add (new Mudela_column (this, Moment (0)));
+ format_i_ = format_i;
+ tracks_i_ = tracks_i;
+ tempo_i_ = tempo_i;
+ mudela_column_p_list_.bottom().add (new Mudela_column (this, Moment (0)));
}
Mudela_score::~Mudela_score()
void
Mudela_score::add_item (Mudela_item* mudela_item_p)
{
- mudela_staff_p_list_.bottom()->add_item (mudela_item_p);
+ mudela_staff_p_list_.bottom()->add_item (mudela_item_p);
}
void
Mudela_score::add_staff (Mudela_staff* mudela_staff_p)
{
- mudela_staff_p_list_.bottom().add (mudela_staff_p);
+ mudela_staff_p_list_.bottom().add (mudela_staff_p);
}
Mudela_column*
Mudela_score::mudela_column_l (Moment mom)
{
- for (PCursor<Mudela_column*> i (mudela_column_p_list_); i.ok(); i++) {
- if (i->at_mom() > mom) {
+ for (PCursor<Mudela_column*> i (mudela_column_p_list_); i.ok(); i++)
+ {
+ if (i->at_mom() > mom)
+ {
Mudela_column* p = new Mudela_column (this, mom);
i.insert (p);
return p;
- }
+ }
if (i->at_mom() == mom)
return *i;
}
- Mudela_column* p = new Mudela_column (this, mom);
- mudela_column_p_list_.bottom().add (p);
- return p;
+ Mudela_column* p = new Mudela_column (this, mom);
+ mudela_column_p_list_.bottom().add (p);
+ return p;
}
void
Mudela_score::output (String filename_str)
{
- LOGOUT(NORMAL_ver) << "Lily output to " << filename_str << " ..." << endl;
-
- // ugh, ugly midi type 1 fix
- if ( (mudela_staff_p_list_.size() == 1) && !mudela_staff_p_list_.top()->number_i_)
+ LOGOUT(NORMAL_ver) << "Lily output to " << filename_str << " ..." << endl;
+
+ // ugh, ugly midi type 1 fix
+ if ( (mudela_staff_p_list_.size() == 1) && !mudela_staff_p_list_.top()->number_i_)
mudela_staff_p_list_.top()->number_i_ = 1;
- int track_i = 0;
- Mudela_stream mudela_stream (filename_str);
- for (PCursor<Mudela_staff*> i (mudela_staff_p_list_); i.ok(); i++) {
+ int track_i = 0;
+ Mudela_stream mudela_stream (filename_str);
+ for (PCursor<Mudela_staff*> i (mudela_staff_p_list_); i.ok(); i++)
+ {
LOGOUT(NORMAL_ver) << "track " << track_i++ << ": " << flush;
i->output (mudela_stream);
mudela_stream << "\n";
LOGOUT(NORMAL_ver) << endl;
}
- mudela_stream << "\\score{\n";
- if (mudela_staff_p_list_.size() > 1)
+ mudela_stream << "\\score{\n";
+ if (mudela_staff_p_list_.size() > 1)
mudela_stream << "<\n\\multi 3;\n";
- for (PCursor<Mudela_staff*> i (mudela_staff_p_list_); i.ok(); i++) {
+ for (PCursor<Mudela_staff*> i (mudela_staff_p_list_); i.ok(); i++)
+ {
if ( (mudela_staff_p_list_.size() != 1)
&& (i == mudela_staff_p_list_.top()))
continue;
mudela_stream << "\\$" << i->id_str();
mudela_stream << " }\n";
}
- if (mudela_staff_p_list_.size() > 1)
+ if (mudela_staff_p_list_.size() > 1)
mudela_stream << ">\n";
- mudela_stream << "\\paper{}\n";
+ mudela_stream << "\\paper{}\n";
- mudela_stream << "\\midi{ ";
+ mudela_stream << "\\midi{ ";
// let's not use silly 0 track
mudela_staff_p_list_.bottom()->mudela_tempo_p_->output (mudela_stream);
- mudela_stream << "}\n";
+ mudela_stream << "}\n";
- mudela_stream << "}\n";
+ mudela_stream << "}\n";
}
void
Mudela_score::process()
{
- LOGOUT(NORMAL_ver) << "\nProcessing..." << endl;
+ LOGOUT(NORMAL_ver) << "\nProcessing..." << endl;
- LOGOUT(DEBUG_ver) << "columns\n";
- for (PCursor<Mudela_column*> i (mudela_column_p_list_); i.ok(); i++)
+ LOGOUT(DEBUG_ver) << "columns\n";
+ for (PCursor<Mudela_column*> i (mudela_column_p_list_); i.ok(); i++)
LOGOUT(DEBUG_ver) << "At: " << i->at_mom() << "\n";
- settle_columns();
- filter_tempo();
- quantify_columns();
- quantify_durations();
+ settle_columns();
+ filter_tempo();
+ quantify_columns();
+ quantify_durations();
- LOGOUT(NORMAL_ver) << "\nCreating voices..." << endl;
- int track_i = 0;
- for (PCursor<Mudela_staff*> i (mudela_staff_p_list_); i.ok(); i++) {
+ LOGOUT(NORMAL_ver) << "\nCreating voices..." << endl;
+ int track_i = 0;
+ for (PCursor<Mudela_staff*> i (mudela_staff_p_list_); i.ok(); i++)
+ {
LOGOUT(NORMAL_ver) << "track " << track_i++ << ": " << flush;
i->process();
LOGOUT(NORMAL_ver) << endl;
void
Mudela_score::filter_tempo()
{
- LOGOUT(NORMAL_ver) << "\nNOT Filtering tempo..." << endl;
+ LOGOUT(NORMAL_ver) << "\nNOT Filtering tempo..." << endl;
}
void
Mudela_score::quantify_columns()
{
- // ugh
- if (Duration_convert::no_quantify_b_s) {
+ // ugh
+ if (Duration_convert::no_quantify_b_s)
+ {
LOGOUT(NORMAL_ver) << "\nNOT Quantifying columns..." << endl;
return;
}
- LOGOUT(NORMAL_ver) << "\nQuantifying columns..." << endl;
+ LOGOUT(NORMAL_ver) << "\nQuantifying columns..." << endl;
- int n = 32 >? Duration_convert::no_smaller_than_i_s;
- Moment s = Moment (1, n);
- Moment sh = Moment (1, 2 * n);
- for (int i = 0; i < column_l_array_.size(); i++) {
+ int n = 5 >? Duration_convert::no_smaller_than_i_s;
+ Moment s = Moment (1, n);
+ Moment sh = Moment (1, 2 * n);
+ for (int i = 0; i < column_l_array_.size(); i++)
+ {
// Moment mom = column_l_array_[ i ]->at_mom();
// column_l_array_[ i ]->at_mom_ = Duration_convert::dur2_mom (dur);
column_l_array_[ i ]->at_mom_ =
// s * (int) ( (sh + column_l_array_[ i ]->at_mom()) / s);
s * (int) ( (column_l_array_[ i ]->at_mom()) / s);
LOGOUT(NORMAL_ver) << '.';
- }
- LOGOUT(NORMAL_ver) << endl;
+ }
+ LOGOUT(NORMAL_ver) << endl;
}
void
{
// LOGOUT(NORMAL_ver) << "\nNOT Settling columns..." << endl;
// return;
- LOGOUT(NORMAL_ver) << "\nSettling columns..." << endl;
+ LOGOUT(NORMAL_ver) << "\nSettling columns..." << endl;
- assert (!column_l_array_.size());
- int n = mudela_column_p_list_.size();
+ assert (!column_l_array_.size());
+ int n = mudela_column_p_list_.size();
// huh?
// column_l_array_.set_size (n);
- for (PCursor<Mudela_column*> i (mudela_column_p_list_); i.ok(); i++)
+ for (PCursor<Mudela_column*> i (mudela_column_p_list_); i.ok(); i++)
column_l_array_.push (*i);
- int start_i = 0;
- int end_i = 0;
- Moment start_mom = 0;
- Duration smallest_dur;
- smallest_dur.type_i_ = 64;
- Moment const noise_mom = Duration_convert::dur2_mom (smallest_dur)
+ int start_i = 0;
+ int end_i = 0;
+ Moment start_mom = 0;
+ Duration smallest_dur;
+ smallest_dur.durlog_i_ = 6;
+ Moment const noise_mom = Duration_convert::dur2_mom (smallest_dur)
/ Moment (2);
- for (int i = 0; i < n; i++) {
- if (!start_i) {
+ for (int i = 0; i < n; i++)
+ {
+ if (!start_i)
+ {
start_i = end_i = i;
start_mom = column_l_array_[ i ]->at_mom();
continue;
- }
+ }
// find all columns within noise's distance
while ( (i < n)
#include "mudela-staff.hh"
#include "mudela-stream.hh"
#include "mudela-voice.hh"
+#include "my-midi-parser.hh"
+#include "mudela-score.hh"
+
Mudela_staff::Mudela_staff (int number_i, String copyright_str, String track_name_str, String instrument_str)
{
- number_i_ = number_i;
- copyright_str_ = copyright_str;
- instrument_str_ = instrument_str;
- name_str_ = track_name_str;
- mudela_meter_p_ = new Mudela_meter (4, 2, 24, 8);
- mudela_tempo_p_ = new Mudela_tempo (1000000);
+ number_i_ = number_i;
+ copyright_str_ = copyright_str;
+ instrument_str_ = instrument_str;
+ name_str_ = track_name_str;
+ mudela_meter_p_ = new Mudela_meter (4, 2, 24, 8);
+ mudela_tempo_p_ = new Mudela_tempo (1000000);
}
Mudela_staff::~Mudela_staff()
{
- delete mudela_meter_p_;
- delete mudela_tempo_p_;
+ delete mudela_meter_p_;
+ delete mudela_tempo_p_;
}
void
Mudela_staff::add_item (Mudela_item* mudela_item_p)
{
- mudela_item_p_list_.bottom().add (mudela_item_p);
- if (mudela_item_p->mudela_column_l_)
- mudela_item_p->mudela_column_l_->add_item (mudela_item_p);
+ mudela_item_p_list_.bottom().add (mudela_item_p);
+ if (mudela_item_p->mudela_column_l_)
+ mudela_item_p->mudela_column_l_->add_item (mudela_item_p);
}
void
Mudela_staff::eat_voice (Link_list<Mudela_item*>& items)
{
- Mudela_voice* voice_p = new Mudela_voice (this);
- mudela_voice_p_list_.bottom().add (voice_p);
-
-// Moment mom = items.top()->at_mom();
- Moment mom = 0;
-
- for (PCursor<Mudela_item*> i (items); i.ok();) {
- LOGOUT(DEBUG_ver) << "At: " << i->at_mom() << "; ";
- LOGOUT(DEBUG_ver) << "dur: " << i->duration_mom() << "; ";
- LOGOUT(DEBUG_ver) << "mom: " << mom << " -> ";
- if (i->at_mom() > mom) {
- // ugh, liek
- voice_p->add_item (new Mudela_skip (i->mudela_column_l_, i->at_mom() - mom));
- mom = i->at_mom();
+ Mudela_voice* voice_p = new Mudela_voice (this);
+ mudela_voice_p_list_.bottom().add (voice_p);
+
+ // Moment mom = items.top()->at_mom();
+ Moment mom = 0;
+
+ for (PCursor<Mudela_item*> i (items); i.ok();)
+ {
+ LOGOUT(DEBUG_ver) << "At: " << i->at_mom() << "; ";
+ LOGOUT(DEBUG_ver) << "dur: " << i->duration_mom() << "; ";
+ LOGOUT(DEBUG_ver) << "mom: " << mom << " -> ";
+ if (i->at_mom() > mom)
+ {
+ Moment dur = i->at_mom() - mom;
+ // ugh, need score
+ Mudela_column* start = midi_parser_l_g->mudela_score_p_->mudela_column_l (mom);
+ voice_p->add_item (new Mudela_skip (start, dur));
+ mom = i->at_mom();
}
- if (i->at_mom() == mom) {
- mom = i->at_mom() + i->duration_mom();
- voice_p->add_item (i.remove_p());
- // ugh
+ if (i->at_mom() == mom)
+ {
+ mom = i->at_mom() + i->duration_mom();
+ voice_p->add_item (i.remove_p());
+ // ugh
}
- else if (i.ok())
- i++;
- LOGOUT(DEBUG_ver) << "mom: " << mom << "\n";
+ else if (i.ok())
+ i++;
+ LOGOUT(DEBUG_ver) << "mom: " << mom << "\n";
}
}
String
Mudela_staff::id_str()
{
- String str = name_str();
- for (int i = 0; i < str.length_i(); i++)
- if ( (!i && !isalpha (str[ i ]))
- || !isalnum (str[ i ]))
- * (str.ch_l() + i) = '_';
- return str;
+ String str = name_str();
+ for (int i = 0; i < str.length_i(); i++)
+ if ( (!i && !isalpha (str[ i ]))
+ || !isalnum (str[ i ]))
+ * (str.ch_l() + i) = '_';
+ return str;
}
String
Mudela_staff::name_str()
{
- if (name_str_.length_i())
- return name_str_;
- return String ("track") + String (number_i_);
+ if (name_str_.length_i())
+ return name_str_;
+ return String ("track") + String (number_i_);
}
void
Mudela_staff::output (Mudela_stream& mudela_stream_r)
{
- mudela_stream_r << "$" << id_str() << " = \\melodic";
- mudela_stream_r << (mudela_voice_p_list_.size() > 1 ? "<" : "{");
- mudela_stream_r << "\n";
- mudela_stream_r << "% midi copyright:" << copyright_str_ << "\n";
- mudela_stream_r << "% instrument:" << instrument_str_ << "\n";
-
- if (mudela_voice_p_list_.size() == 1)
- mudela_voice_p_list_.top()->output (mudela_stream_r);
- else
- for (PCursor<Mudela_voice*> i (mudela_voice_p_list_); i.ok(); i++) {
- mudela_stream_r << "{ ";
- i->output (mudela_stream_r);
- mudela_stream_r << "} ";
- }
-
- mudela_stream_r << (mudela_voice_p_list_.size() > 1 ? "\n>" : "\n}");
- mudela_stream_r << " % " << name_str() << "\n";
+ mudela_stream_r << "$" << id_str() << " = \\melodic";
+ mudela_stream_r << (mudela_voice_p_list_.size() > 1 ? "<" : "{");
+ mudela_stream_r << "\n";
+ mudela_stream_r << "% midi copyright:" << copyright_str_ << "\n";
+ mudela_stream_r << "% instrument:" << instrument_str_ << "\n";
+
+ if (mudela_voice_p_list_.size() == 1)
+ mudela_voice_p_list_.top()->output (mudela_stream_r);
+ else
+ for (PCursor<Mudela_voice*> i (mudela_voice_p_list_); i.ok(); i++)
+ {
+ mudela_stream_r << "{ ";
+ i->output (mudela_stream_r);
+ mudela_stream_r << "} ";
+ }
+
+ mudela_stream_r << (mudela_voice_p_list_.size() > 1 ? "\n>" : "\n}");
+ mudela_stream_r << " % " << name_str() << "\n";
}
void
Mudela_staff::output_mudela_begin_bar (Mudela_stream& mudela_stream_r, Moment now_mom, int bar_i)
{
- Moment bar_mom = mudela_meter_p_->bar_mom();
- Moment into_bar_mom = now_mom - Moment (bar_i - 1) * bar_mom;
- if (bar_i > 1) {
- if (!into_bar_mom)
- mudela_stream_r << "|\n";
+ Moment bar_mom = mudela_meter_p_->bar_mom();
+ Moment into_bar_mom = now_mom - Moment (bar_i - 1) * bar_mom;
+ if (bar_i > 1)
+ {
+ if (!into_bar_mom)
+ mudela_stream_r << "|\n";
}
- mudela_stream_r << "% " << String_convert::i2dec_str (bar_i, 0, ' ');
- if (into_bar_mom)
- mudela_stream_r << ":" << Duration_convert::dur2_str (Duration_convert::mom2_dur (into_bar_mom));
- mudela_stream_r << "\n";
+ mudela_stream_r << "% " << String_convert::i2dec_str (bar_i, 0, ' ');
+ if (into_bar_mom)
+ mudela_stream_r << ":" << Duration_convert::dur2_str (Duration_convert::mom2_dur (into_bar_mom));
+ mudela_stream_r << "\n";
}
void
Mudela_staff::output_mudela_rest (Mudela_stream& mudela_stream_r, Moment begin_mom, Moment end_mom)
{
- Moment bar_mom = mudela_meter_p_->bar_mom();
- Moment now_mom = begin_mom;
+ Moment bar_mom = mudela_meter_p_->bar_mom();
+ Moment now_mom = begin_mom;
- int begin_bar_i = (int) (now_mom / bar_mom) + 1;
- int end_bar_i = (int) (end_mom / bar_mom) + 1;
+ int begin_bar_i = (int) (now_mom / bar_mom) + 1;
+ int end_bar_i = (int) (end_mom / bar_mom) + 1;
- if (end_bar_i == begin_bar_i) {
- output_mudela_rest_remain (mudela_stream_r, end_mom - begin_mom);
- return;
+ if (end_bar_i == begin_bar_i)
+ {
+ output_mudela_rest_remain (mudela_stream_r, end_mom - begin_mom);
+ return;
}
- // multiple bars involved
- int bar_i = (int) (now_mom / bar_mom) + 1;
-
- //fill current bar
- Moment begin_bar_mom = Moment (begin_bar_i - 1) * bar_mom;
- if (now_mom > begin_bar_mom) {
- int next_bar_i = (int) (now_mom / bar_mom) + 2;
- Moment next_bar_mom = Moment (next_bar_i - 1) * bar_mom;
- assert (next_bar_mom <= end_mom);
-
- Moment remain_mom = next_bar_mom - now_mom;
- if (remain_mom > Moment (0)) {
- output_mudela_rest_remain (mudela_stream_r, remain_mom);
- now_mom += remain_mom;
+ // multiple bars involved
+ int bar_i = (int) (now_mom / bar_mom) + 1;
+
+ //fill current bar
+ Moment begin_bar_mom = Moment (begin_bar_i - 1) * bar_mom;
+ if (now_mom > begin_bar_mom)
+ {
+ int next_bar_i = (int) (now_mom / bar_mom) + 2;
+ Moment next_bar_mom = Moment (next_bar_i - 1) * bar_mom;
+ assert (next_bar_mom <= end_mom);
+
+ Moment remain_mom = next_bar_mom - now_mom;
+ if (remain_mom > Moment (0))
+ {
+ output_mudela_rest_remain (mudela_stream_r, remain_mom);
+ now_mom += remain_mom;
}
- bar_i = check_end_bar_i (now_mom, bar_i);
+ bar_i = check_end_bar_i (now_mom, bar_i);
}
- // fill whole bars
- int count_i = end_bar_i - bar_i;
- for (int i = 0; i < count_i; i++) {
- int begin_bar_i = check_begin_bar_i (now_mom, bar_i);
- if (begin_bar_i)
- output_mudela_begin_bar (mudela_stream_r, now_mom, begin_bar_i);
- mudela_stream_r << "r1 ";
-// *mudela_stream_r.os_p_ << flush;
- if (begin_bar_i)
- LOGOUT(NORMAL_ver) << begin_bar_i << flush;
- bar_i = check_end_bar_i (now_mom, bar_i);
- now_mom += bar_mom;
+ // fill whole bars
+ int count_i = end_bar_i - bar_i;
+ for (int i = 0; i < count_i; i++)
+ {
+ int begin_bar_i = check_begin_bar_i (now_mom, bar_i);
+ if (begin_bar_i)
+ output_mudela_begin_bar (mudela_stream_r, now_mom, begin_bar_i);
+ mudela_stream_r << "r1 ";
+ // *mudela_stream_r.os_p_ << flush;
+ if (begin_bar_i)
+ LOGOUT(NORMAL_ver) << begin_bar_i << flush;
+ bar_i = check_end_bar_i (now_mom, bar_i);
+ now_mom += bar_mom;
}
- // use "int i" here, and gcc 2.7.2 hits internal compiler error
- int ii = check_begin_bar_i (now_mom, bar_i);
- if (ii)
- output_mudela_begin_bar (mudela_stream_r, now_mom, ii);
+ // use "int i" here, and gcc 2.7.2 hits internal compiler error
+ int ii = check_begin_bar_i (now_mom, bar_i);
+ if (ii)
+ output_mudela_begin_bar (mudela_stream_r, now_mom, ii);
-// bar_i = check_end_bar_i (now_mom, bar_i);
+ // bar_i = check_end_bar_i (now_mom, bar_i);
- Moment remain_mom = end_mom - Moment (end_bar_i - 1) * bar_mom;
- if (remain_mom > Moment (0)) {
- output_mudela_rest_remain (mudela_stream_r, remain_mom);
- now_mom += remain_mom;
+ Moment remain_mom = end_mom - Moment (end_bar_i - 1) * bar_mom;
+ if (remain_mom > Moment (0))
+ {
+ output_mudela_rest_remain (mudela_stream_r, remain_mom);
+ now_mom += remain_mom;
}
- assert (now_mom == end_mom);
+ assert (now_mom == end_mom);
}
void
Mudela_staff::output_mudela_rest_remain (Mudela_stream& mudela_stream_r, Moment mom)
{
- if (Duration_convert::no_quantify_b_s) {
- Duration dur = Duration_convert::mom2_dur (mom);
- mudela_stream_r << "r" << dur.str() << " ";
-// assert (mom == dur.mom());
- assert (mom == dur.length());
- return;
+ if (Duration_convert::no_quantify_b_s)
+ {
+ Duration dur = Duration_convert::mom2_dur (mom);
+ mudela_stream_r << "r" << dur.str() << " ";
+ // assert (mom == dur.mom());
+ assert (mom == dur.length());
+ return;
}
- Duration dur = Duration_convert::mom2standardised_dur (mom);
- if (dur.type_i_)
- mudela_stream_r << "r" << dur.str() << " ";
+ Duration dur = Duration_convert::mom2standardised_dur (mom);
+ if (dur.type_i_>-10)
+ mudela_stream_r << "r" << dur.str() << " ";
}
#endif
void
Mudela_staff::process()
{
- /*
- group items into voices
+ /*
+ group items into voices
*/
- Link_list<Mudela_item*> items;
- for (PCursor<Mudela_item*> i (mudela_item_p_list_); i.ok(); i++)
- items.bottom().add (*i);
-
- while (items.size())
- eat_voice (items);
+ Link_list<Mudela_item*> items;
+ for (PCursor<Mudela_item*> i (mudela_item_p_list_); i.ok(); i++)
+ items.bottom().add (*i);
+
+ while (items.size())
+ eat_voice (items);
}
void
Mudela_staff::set_tempo (int useconds_per_4_i)
{
- delete mudela_tempo_p_;
- mudela_tempo_p_ = new Mudela_tempo (useconds_per_4_i);
+ delete mudela_tempo_p_;
+ mudela_tempo_p_ = new Mudela_tempo (useconds_per_4_i);
}
void
Mudela_staff::set_meter (int num_i, int den_i, int clocks_i, int count_32_i)
{
- delete mudela_meter_p_;
- mudela_meter_p_ = new Mudela_meter (num_i, den_i, clocks_i, count_32_i);
+ delete mudela_meter_p_;
+ mudela_meter_p_ = new Mudela_meter (num_i, den_i, clocks_i, count_32_i);
}