Mudela_item::Mudela_item (Mudela_column* mudela_column_l)
{
- mudela_column_l_ = mudela_column_l;
+ mudela_column_l_ = mudela_column_l;
}
Moment
Mudela_item::at_mom()
{
- return mudela_column_l_->at_mom();
+ return mudela_column_l_->at_mom();
}
Moment
Mudela_item::duration_mom()
{
- return Moment (0);
+ return Moment (0);
}
void
Mudela_item::output (Mudela_stream& mudela_stream_r)
{
- mudela_stream_r << str() << String (" ");
+ mudela_stream_r << str() << String (" ");
}
Mudela_key::Mudela_key (int accidentals_i, int minor_i)
- : Mudela_item (0)
+ : Mudela_item (0)
{
- accidentals_i_ = accidentals_i;
- minor_i_ = minor_i;
- if (accidentals_i >= 0)
+ accidentals_i_ = accidentals_i;
+ minor_i_ = minor_i;
+ if (accidentals_i >= 0)
key_i_ = ((accidentals_i % 7)[ "cgdaebf" ] - 'a' - 2) % 7;
- else
+ else
key_i_ = ((-accidentals_i % 7)[ "cfbeadg" ] - 'a' - 2) % 7;
}
String
Mudela_key::str()
{
- String str = "\\key ";
- if (!minor_i_)
+ String str = "\\key ";
+ if (!minor_i_)
str += String ((char) ((key_i_ + 2) % 7 + 'A'));
- else // heu, -2: should be - 1 1/2: A -> fis
+ else // heu, -2: should be - 1 1/2: A -> fis
str += String ((char) ((key_i_ + 2 - 2) % 7 + 'a'));
- str = String ("% \"") + str
+ str = String ("% \"") + str
+ String('"') + "; % not supported yet\n";
- return str;
+ return str;
}
String
Mudela_key::notename_str (int pitch_i)
{
- // this may seem very smart,
- // but it-s only an excuse not to read a notename table
-
- // major scale: do-do
- // minor scale: la-la (= + 5)
- static int notename_i_a[ 12 ] = { 0, 0, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6 };
- int notename_i = notename_i_a[ (minor_i_ * 5 + pitch_i) % 12 ];
-
- static int accidentals_i_a[ 12 ] = { 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0 };
- int accidental_i = accidentals_i_a[ minor_i_ * 5 + pitch_i % 12 ];
- if (accidental_i && (accidentals_i_ < 0)) {
+ // this may seem very smart,
+ // but it-s only an excuse not to read a notename table
+
+ // major scale: do-do
+ // minor scale: la-la (= + 5)
+ static int notename_i_a[ 12 ] = { 0, 0, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6 };
+ int notename_i = notename_i_a[ (minor_i_ * 5 + pitch_i) % 12 ];
+
+ static int accidentals_i_a[ 12 ] = { 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0 };
+ int accidental_i = accidentals_i_a[ minor_i_ * 5 + pitch_i % 12 ];
+ if (accidental_i && (accidentals_i_ < 0))
+ {
accidental_i = - accidental_i;
notename_i = (notename_i + 1) % 7;
}
- String notename_str = (char) ( ((notename_i + 2) % 7) + 'a');
- while (accidental_i-- > 0)
+ String notename_str = (char) ( ((notename_i + 2) % 7) + 'a');
+ while (accidental_i-- > 0)
notename_str += "is";
- accidental_i++;
- while (accidental_i++ < 0)
+ accidental_i++;
+ while (accidental_i++ < 0)
if ((notename_str == "a") || (notename_str == "e"))
notename_str += "s";
else
notename_str += "es";
- accidental_i--;
+ accidental_i--;
- String de_octavate_str = String ('\'', (Mudela_note::c0_pitch_i_c_ + 11 - pitch_i) / 12);
- String octavate_str = String ('\'', (pitch_i - Mudela_note::c0_pitch_i_c_) / 12);
- return de_octavate_str + notename_str + octavate_str;
+ String de_octavate_str = String ('\'', (Mudela_note::c0_pitch_i_c_ + 11 - pitch_i) / 12);
+ String octavate_str = String ('\'', (pitch_i - Mudela_note::c0_pitch_i_c_) / 12);
+ return de_octavate_str + notename_str + octavate_str;
}
Mudela_meter::Mudela_meter (int num_i, int den_i, int clocks_4_i, int count_32_i)
: Mudela_item (0)
{
- sync_dur_.type_i_ = 8 ;
- sync_f_ = 1.0;
- if (count_32_i != 8)
+ sync_dur_.durlog_i_ = 3 ;
+ sync_f_ = 1.0;
+ if (count_32_i != 8)
warning (String ("#32 in quarter: ") + String (count_32_i));
- num_i_ = num_i;
- den_i_ = den_i;
- clocks_1_i_ = clocks_4_i * 4;
+ num_i_ = num_i;
+ den_i_ = den_i;
+ clocks_1_i_ = clocks_4_i * 4;
}
Moment
Mudela_meter::bar_mom()
{
- Duration d;
- d.type_i_ = (1 << den_i_);
- return Moment (num_i_) * Duration_convert::dur2_mom (d);
+ Duration d;
+ d.durlog_i_ = den_i_;
+ return Moment (num_i_) * Duration_convert::dur2_mom (d);
}
int
Mudela_meter::clocks_1_i()
{
- return clocks_1_i_;
+ return clocks_1_i_;
}
int
Mudela_meter::den_i()
{
- return den_i_;
+ return den_i_;
}
int
Mudela_meter::num_i()
{
- return num_i_;
+ return num_i_;
}
String
Mudela_meter::str()
{
- String str = "\\meter "
+ String str = "\\meter "
+ String (num_i_) + "/" + String (1 << den_i_)
+ ";\n";
- return str;
+ return str;
}
// statics Mudela_note
/*
this switch can be used to write simple plets like
- c4*2/3
+ c4*2/3
as
- \plet 2/3; c4 \plet 1/1;
+ \plet 2/3; c4 \plet 1/1;
*/
bool const Mudela_note::simple_plet_b_s = true;
Mudela_note::Mudela_note (Mudela_column* mudela_column_l, int channel_i, int pitch_i, int dyn_i)
- : Mudela_item (mudela_column_l)
+ : Mudela_item (mudela_column_l)
{
- // junk dynamics
- (void)dyn_i;
- channel_i_ = channel_i;
- pitch_i_ = pitch_i;
- end_column_l_ = 0;
+ // junk dynamics
+ (void)dyn_i;
+ channel_i_ = channel_i;
+ pitch_i_ = pitch_i;
+ end_column_l_ = 0;
}
String
Mudela_note::str()
{
- Duration dur = duration();
- if (!dur.type_i_)
+ Duration dur = duration();
+ if (dur.durlog_i_ < -10)
return "";
- String name_str = mudela_column_l_->mudela_score_l_->mudela_key_l_->notename_str (pitch_i_);
+ String name_str
+ = mudela_column_l_->mudela_score_l_->mudela_key_l_->notename_str (pitch_i_);
- if (simple_plet_b_s)
+ if (simple_plet_b_s)
return name_str + Duration_convert::dur2_str (dur) + " ";
- //ugh
- String str;
- if (dur.plet_b())
+ //ugh
+ String str;
+ if (dur.plet_b())
str += String ("\\plet ")
+ String_convert::i2dec_str (dur.plet_.iso_i_, 0, 0)
+ "/"
+ String_convert::i2dec_str (dur.plet_.type_i_, 0, 0)
+ "; ";
- str += name_str;
+ str += name_str;
- Duration tmp = dur;
- tmp.set_plet (1,1);
- str += Duration_convert::dur2_str (tmp);
+ Duration tmp = dur;
+ tmp.set_plet (1,1);
+ str += Duration_convert::dur2_str (tmp);
- if (dur.plet_b())
+ if (dur.plet_b())
str += String (" \\plet 1/1;");
- return str + " ";
+ return str + " ";
}
Duration
Mudela_note::duration()
{
- assert (end_column_l_);
- Moment mom = end_column_l_->at_mom() - at_mom();
- if (Duration_convert::no_quantify_b_s)
- return Duration_convert::mom2_dur (mom);
-
- return Duration_convert::mom2standardised_dur (mom);
+ assert (end_column_l_);
+ Moment mom = end_column_l_->at_mom() - at_mom();
+ return Duration_convert::mom2_dur (mom);
}
Moment
{
// ugh
// return Duration_convert::dur2_mom (duration());
- return end_column_l_->at_mom() - at_mom();
+ return end_column_l_->at_mom() - at_mom();
}
Mudela_skip::Mudela_skip (Mudela_column* mudela_column_l, Moment skip_mom)
- : Mudela_item (mudela_column_l)
+ : Mudela_item (mudela_column_l)
{
- mom_ = skip_mom;
+ mom_ = skip_mom;
}
Duration
Mudela_skip::duration()
{
- if (Duration_convert::no_quantify_b_s)
return Duration_convert::mom2_dur (mom_);
-
- return Duration_convert::mom2standardised_dur (mom_);
}
Moment
Mudela_skip::duration_mom()
{
- return Duration_convert::dur2_mom (duration());
+ return Duration_convert::dur2_mom (duration());
}
String
Mudela_skip::str()
{
- if (!mom_)
+ if (!mom_)
return String ("");
- Duration dur = duration();
- if (!dur.type_i_)
+ Duration dur = duration();
+ if (dur.durlog_i_<-10)
return "";
- String str = "\\skip ";
- str += Duration_convert::dur2_str (dur) + "; ";
+ String str = "\\skip ";
+ str += Duration_convert::dur2_str (dur) + "; ";
- return str;
+ return str;
}
Mudela_tempo::Mudela_tempo (int useconds_per_4_i)
: Mudela_item (0)
{
- useconds_per_4_i_ = useconds_per_4_i;
- seconds_per_1_f_ = (Real)useconds_per_4_i_ * 4 / 1e6;
+ useconds_per_4_i_ = useconds_per_4_i;
+ seconds_per_1_f_ = (Real)useconds_per_4_i_ * 4 / 1e6;
}
String
Mudela_tempo::str()
{
- String str = "\\tempo 4=";
- str += String (get_tempo_i (Moment (1, 4)));
- str += ";\n";
- return str;
+ String str = "\\tempo 4=";
+ str += String (get_tempo_i (Moment (1, 4)));
+ str += ";\n";
+ return str;
}
int
Mudela_tempo::useconds_per_4_i()
{
- return useconds_per_4_i_;
+ return useconds_per_4_i_;
}
int
Mudela_tempo::get_tempo_i (Moment moment)
{
- return Moment (60) / moment / Moment (seconds_per_1_f_);
+ return Moment (60) / moment / Moment (seconds_per_1_f_);
}
Mudela_text::Mudela_text (Mudela_text::Type type, String text_str)
: Mudela_item (0)
{
- type_ = type;
- text_str_ = text_str;
+ type_ = type;
+ text_str_ = text_str;
}
String
Mudela_text::str()
{
- if (!text_str_.length_i()
+ if (!text_str_.length_i()
|| (text_str_.length_i() != (int)strlen (text_str_.ch_C())))
return "";
- return "% " + text_str_ + "\n";
+ return "% " + text_str_ + "\n";
}
void
yyerror(char const* sz_l)
{
- midi_parser_l_g->error (sz_l);
+ midi_parser_l_g->error (sz_l);
}
My_midi_parser::My_midi_parser (String filename_str, Sources *sources_l)
{
- filename_str_ = filename_str;
- midi_lexer_p_ = new My_midi_lexer (filename_str_,sources_l);
- midi_lexer_l_g = midi_lexer_p_; // ugh
+ filename_str_ = filename_str;
+ midi_lexer_p_ = new My_midi_lexer (filename_str_,sources_l);
+ midi_lexer_l_g = midi_lexer_p_; // ugh
- bar_i_ = 1;
+ bar_i_ = 1;
- defined_ch_C_ = 0;
- fatal_error_i_ = 0;
-
- mudela_column_l_ = 0;
- mudela_score_p_ = new Mudela_score (1, 1, 1);
+ defined_ch_C_ = 0;
+ fatal_error_i_ = 0;
+
+ mudela_column_l_ = 0;
+ mudela_score_p_ = new Mudela_score (1, 1, 1);
- // ugh, belong to Mudela_{score,staff}
- track_i_ = 0;
- mudela_staff_l_ = 0;
- mudela_key_p_ = 0;
- mudela_tempo_p_ = 0;
- mudela_meter_p_ = 0;
+ // ugh, belong to Mudela_{score,staff}
+ track_i_ = 0;
+ mudela_staff_l_ = 0;
+ mudela_key_p_ = 0;
+ mudela_tempo_p_ = 0;
+ mudela_meter_p_ = 0;
- reset();
+ reset();
}
My_midi_parser::~My_midi_parser()
{
- midi_lexer_l_g = 0; // ugh
+ midi_lexer_l_g = 0; // ugh
- delete midi_lexer_p_;
- delete mudela_key_p_;
- delete mudela_tempo_p_;
- delete mudela_meter_p_;
- delete mudela_score_p_;
+ delete midi_lexer_p_;
+ delete mudela_key_p_;
+ delete mudela_tempo_p_;
+ delete mudela_meter_p_;
+ delete mudela_score_p_;
}
void
My_midi_parser::reset()
{
// open_mudela_note_l_list_.clear();
- open_mudela_note_l_list_.junk_links();
+ open_mudela_note_l_list_.junk_links();
- // ugh
- delete mudela_key_p_;
- mudela_key_p_ = new Mudela_key (0, 0);
- // useconds per 4: 250000 === 60 4 per minute
- delete mudela_tempo_p_;
- mudela_tempo_p_ = new Mudela_tempo (1000000);
- delete mudela_meter_p_;
- mudela_meter_p_ = new Mudela_meter (4, 2, 24, 8);
+ // ugh
+ delete mudela_key_p_;
+ mudela_key_p_ = new Mudela_key (0, 0);
+ // useconds per 4: 250000 === 60 4 per minute
+ delete mudela_tempo_p_;
+ mudela_tempo_p_ = new Mudela_tempo (1000000);
+ delete mudela_meter_p_;
+ mudela_meter_p_ = new Mudela_meter (4, 2, 24, 8);
- bar_i_ = 1;
- mudela_column_l_ = mudela_score_p_->mudela_column_l (0);
+ bar_i_ = 1;
+ mudela_column_l_ = mudela_score_p_->mudela_column_l (0);
- // ugh
- copyright_str_ = "";
- track_name_str_ = "";
- instrument_str_ = "";
+ // ugh
+ copyright_str_ = "";
+ track_name_str_ = "";
+ instrument_str_ = "";
}
void
My_midi_parser::add_score (Mudela_score* mudela_score_p)
{
- assert (mudela_score_p_);
+ assert (mudela_score_p_);
#if 0 // ugh, already constructed
- mudela_score_p_ = mudela_score_p;
- if (!mudela_column_l_)
+ mudela_score_p_ = mudela_score_p;
+ if (!mudela_column_l_)
mudela_column_l_ = mudela_score_p_->mudela_column_l (0);
#endif
- mudela_score_p_->mudela_key_l_ = mudela_key_p_;
- mudela_score_p_->mudela_meter_l_ = mudela_meter_p_;
- mudela_score_p_->mudela_tempo_l_ = mudela_tempo_p_;
- bar_i_ = 1;
+ mudela_score_p_->mudela_key_l_ = mudela_key_p_;
+ mudela_score_p_->mudela_meter_l_ = mudela_meter_p_;
+ mudela_score_p_->mudela_tempo_l_ = mudela_tempo_p_;
+ bar_i_ = 1;
}
void
My_midi_parser::error (char const* sz_l)
{
- midi_lexer_l_g->error (sz_l);
+ midi_lexer_l_g->error (sz_l);
- if (fatal_error_i_)
+ if (fatal_error_i_)
exit (fatal_error_i_);
}
void
My_midi_parser::forward (int i)
{
- if (!i)
+ if (!i)
return;
- Duration dur;
- dur.type_i_ = (0);
- dur.set_ticks (i);
- Moment mom = at_mom() + Duration_convert::dur2_mom (dur);
+ Duration dur;
+ dur.durlog_i_ = -100;
+ dur.set_ticks (i);
+ Moment mom = at_mom() + Duration_convert::dur2_mom (dur);
- mudela_column_l_ = mudela_score_p_->mudela_column_l (mom);
+ mudela_column_l_ = mudela_score_p_->mudela_column_l (mom);
- if (i) {
+ if (i)
+ {
int bars_i = (int) (mom / mudela_meter_p_->bar_mom());
if (bars_i > bar_i_)
LOGOUT(NORMAL_ver) << '[' << bar_i_ << ']' << flush;
Moment
My_midi_parser::at_mom()
{
- assert (mudela_column_l_);
+ assert (mudela_column_l_);
// return mudela_column_l_ ? mudela_column_l_->at_mom() : 0;
- return mudela_column_l_->at_mom();
+ return mudela_column_l_->at_mom();
}
void
My_midi_parser::note_begin (int channel_i, int pitch_i, int dyn_i)
{
- // junk dynamics
- (void)dyn_i;
+ // junk dynamics
+ (void)dyn_i;
- Mudela_note* p = new Mudela_note (mudela_column_l_, channel_i, pitch_i, dyn_i);
+ Mudela_note* p = new Mudela_note (mudela_column_l_, channel_i, pitch_i, dyn_i);
// ugh, score doesn't know about last staff yet...
// mudela_score_p_->add_item (p);
- mudela_staff_l_->add_item (p);
- open_mudela_note_l_list_.bottom().add (p);
+ mudela_staff_l_->add_item (p);
+ open_mudela_note_l_list_.bottom().add (p);
}
void
My_midi_parser::note_end (int channel_i, int pitch_i, int aftertouch_i)
{
- // junk dynamics
- (void)aftertouch_i;
+ // junk dynamics
+ (void)aftertouch_i;
- // find
- for (PCursor<Mudela_note*> i (open_mudela_note_l_list_); i.ok(); i++) {
- if ( (i->pitch_i_ == pitch_i) && (i->channel_i_ == channel_i)) {
+ // find
+ for (PCursor<Mudela_note*> i (open_mudela_note_l_list_); i.ok(); i++)
+ {
+ if ( (i->pitch_i_ == pitch_i) && (i->channel_i_ == channel_i))
+ {
i->end_column_l_ = mudela_column_l_;
LOGOUT(DEBUG_ver) << "Note: " << pitch_i;
LOGOUT(DEBUG_ver) << "; " << i->mudela_column_l_->at_mom_;
LOGOUT(DEBUG_ver) << ", " << i->end_column_l_->at_mom_ << "\n";
i.remove_p();
return;
- }
+ }
}
- warning (String ("junking note-end event: ")
+ warning (String ("junking note-end event: ")
+ " channel = " + String_convert::i2dec_str (channel_i, 0, ' ')
+ ", pitch = " + String_convert::i2dec_str (pitch_i, 0, ' '));
}
void
My_midi_parser::note_end_all()
{
- // find
- for (PCursor<Mudela_note*> i (open_mudela_note_l_list_); i.ok(); i++) {
+ // find
+ for (PCursor<Mudela_note*> i (open_mudela_note_l_list_); i.ok(); i++)
+ {
i->end_column_l_ = mudela_column_l_;
i.remove_p();
// ugh
int
My_midi_parser::parse()
{
- LOGOUT(NORMAL_ver) << "\nParsing..." << flush;
- int i = ::yyparse();
- if (!i)
+ LOGOUT(NORMAL_ver) << "\nParsing..." << flush;
+ int i = ::yyparse();
+ if (!i)
note_end_all();
- return i;
+ return i;
}
void
My_midi_parser::set_division_4 (int division_4_i)
{
- division_1_i_ = division_4_i * 4;
- // ugh
- Duration::division_1_i_s = division_1_i_;
- if (division_4_i < 0)
+ division_1_i_ = division_4_i * 4;
+ // ugh
+ Duration::division_1_i_s = division_1_i_;
+ if (division_4_i < 0)
warning ("seconds iso metrical time");
}
void
My_midi_parser::set_key (int accidentals_i, int minor_i)
{
- delete mudela_key_p_;
- mudela_key_p_ = new Mudela_key (accidentals_i, minor_i);
+ delete mudela_key_p_;
+ mudela_key_p_ = new Mudela_key (accidentals_i, minor_i);
}
void
My_midi_parser::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);
}
void
My_midi_parser::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);
}