From: fred Date: Sun, 24 Mar 2002 19:54:02 +0000 (+0000) Subject: lilypond-0.1.8 X-Git-Tag: release/1.5.59~4103 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=eb16da0238461728452aca8ff67ebd72a7300311;p=lilypond.git lilypond-0.1.8 --- diff --git a/mi2mu/include/mi2mu-global.hh b/mi2mu/include/mi2mu-global.hh new file mode 100644 index 0000000000..cb577d0bdf --- /dev/null +++ b/mi2mu/include/mi2mu-global.hh @@ -0,0 +1,32 @@ +// +// mi2mu-global.hh -- declare global (sic) stuff for mi2mu +// +// copyright 1997 Jan Nieuwenhuizen + +#ifndef MI2MU_GLOBAL_HH +#define MI2MU_GLOBAL_HH + +#include "string.hh" +#include "proto.hh" + +#define monitor_p_g &cout +enum Verbose { QUIET_ver, BRIEF_ver, NORMAL_ver, VERBOSE_ver, DEBUG_ver }; +extern Verbose level_ver; +#if 0 // NPRINT + // not what i want, all output goes through tors. + // set verbosity level. + #define LOGOUT(threshold) if (0) *monitor_p_g +#else + #define LOGOUT(threshold) if (level_ver >= threshold) *monitor_p_g +#endif + +extern Sources* source_l_g; +// huh? +void message (String message_str); //, char const* context_ch_C); +void warning (String message_str); //, char const* context_ch_C); +void error (String message_str); //, char const* context_ch_C); + +String mi2mu_version_str(); + +#endif // MI2MU_GLOBAL_HH + diff --git a/mi2mu/include/mi2mu-proto.hh b/mi2mu/include/mi2mu-proto.hh index af0d543033..5aa6579ae3 100644 --- a/mi2mu/include/mi2mu-proto.hh +++ b/mi2mu/include/mi2mu-proto.hh @@ -11,18 +11,18 @@ #define MI2MU_PROTO_HH -struct Lily_stream ; -class Midi_event ; -class Midi_key ; -class Midi_note ; -class Midi_tempo ; -class Midi_text ; -class Midi_time ; -class Midi_score ; -class Midi_track ; -class Midi_voice ; -class My_midi_lexer ; -class My_midi_parser ; -class Track_column ; +class Mudela_stream; +class Mudela_item; +class Mudela_key; +class Mudela_meter; +class Mudela_note; +class Mudela_tempo; +class Mudela_text; +class Mudela_score; +class Mudela_staff; +class Mudela_voice; +class My_midi_lexer; +class My_midi_parser; +class Mudela_column; #endif // MI2MU_PROTO_HH diff --git a/mi2mu/include/mudela-column.hh b/mi2mu/include/mudela-column.hh new file mode 100644 index 0000000000..24d5196308 --- /dev/null +++ b/mi2mu/include/mudela-column.hh @@ -0,0 +1,29 @@ +// +// mudela-column.hh -- declare Mudela_column +// +// copyright 1997 Jan Nieuwenhuizen + +#ifndef MUDELA_COLUMN_HH +#define MUDELA_COLUMN_HH + +#include "proto.hh" +#include "mi2mu-proto.hh" +#include "moment.hh" +#include "plist.hh" + +/// (mudela_column) +class Mudela_column +{ +public: + Mudela_column (Mudela_score* mudela_score_l, Moment mom); + + void add_item (Mudela_item* mudela_item_l); + Moment at_mom(); + + Link_list mudela_item_l_list_; + Moment at_mom_; + Mudela_score* mudela_score_l_; +}; + +#endif // MUDELA_COLUMN_HH + diff --git a/mi2mu/include/mudela-item.hh b/mi2mu/include/mudela-item.hh new file mode 100644 index 0000000000..ba0d77c518 --- /dev/null +++ b/mi2mu/include/mudela-item.hh @@ -0,0 +1,130 @@ +// +// mudela-item.hh -- declare mudela_item +// +// copyright 1997 Jan Nieuwenhuizen + +#ifndef MUDELA_ITEM_HH +#define MUDELA_ITEM_HH + +#include "mi2mu-proto.hh" +#include "string.hh" +#include "moment.hh" +#include "duration.hh" + +// should these: +// * be Mudela_items +// * be Voice_elements/requests +// * get a name-change +// ? + +/// (mudela_item) +class Mudela_item +{ +public: + Mudela_item (Mudela_column* mudela_column_l); + + virtual Moment at_mom(); + virtual Moment duration_mom(); + void output (Mudela_stream& mudela_stream_r); + virtual String str() = 0; + + Mudela_column* mudela_column_l_; +}; + +class Mudela_key : public Mudela_item +{ +public: + Mudela_key (int accidentals_i, int minor_i); + + String notename_str (int pitch_i); + virtual String str(); + +private: + int accidentals_i_; + int minor_i_; + int key_i_; +}; + +class Mudela_meter : public Mudela_item +{ +public: + Mudela_meter (int num_i, int den_i, int division_4_i, int count_32_i); + + Duration i2_dur (int time_i, int division_1_i); + int clocks_1_i(); + int den_i(); + int num_i(); + virtual String str(); + Moment bar_mom(); + +private: + Real sync_f_; + Duration sync_dur_; + int clocks_1_i_; + int num_i_; + int den_i_; +}; + +class Mudela_note : public Mudela_item +{ +public: + Mudela_note (Mudela_column* mudela_column_l, int channel_i, int pitch_i, int dyn_i); + + Duration duration(); + virtual Moment duration_mom(); + virtual String str(); + +// int const c0_pitch_i_c_ = 60; // huh? + int const c0_pitch_i_c_ = 48; + + static bool const simple_plet_b_s = false; + int channel_i_; + int pitch_i_; + Mudela_column* end_column_l_; +}; + +class Mudela_skip : public Mudela_item +{ +public: + Mudela_skip (Mudela_column* mudela_column_l, Moment skip_mom); + + Duration duration(); + virtual Moment duration_mom(); + virtual String str(); + +private: + Moment mom_; +}; + + +class Mudela_tempo : public Mudela_item +{ +public: + Mudela_tempo (int useconds_per_4_i); + + int get_tempo_i (Moment moment); + virtual String str(); + int useconds_per_4_i(); + +private: + int useconds_per_4_i_; + Real seconds_per_1_f_; +}; + +class Mudela_text : public Mudela_item +{ +public: + enum Type { + TEXT = 1, COPYRIGHT, TRACK_NAME, INSTRUMENT_NAME, LYRIC, + MARKER, CUE_POINT + }; + Mudela_text (Mudela_text::Type type, String str); + virtual String str(); + +private: + Type type_; + String text_str_; +}; + +#endif // MUDELA_ITEM_HH + diff --git a/mi2mu/include/mudela-score.hh b/mi2mu/include/mudela-score.hh new file mode 100644 index 0000000000..6d752fe1d6 --- /dev/null +++ b/mi2mu/include/mudela-score.hh @@ -0,0 +1,53 @@ +// +// mudela-score.hh -- declare Mudela_score +// +// copyright 1997 Jan Nieuwenhuizen + +#ifndef MUDELA_SCORE_HH +#define MUDELA_SCORE_HH + +#include "mi2mu-proto.hh" +#include "proto.hh" +#include "plist.hh" +#include "parray.hh" + +/// (mudela_score) +class Mudela_score { +public: + Mudela_score (int format_i, int tracks_i, int tempo_i); + ~Mudela_score(); + + void add_item (Mudela_item* mudela_item_p); + void add_staff (Mudela_staff* mudela_staff_p); + + Mudela_column* mudela_column_l (Moment mom); + + void output (String filename_str); + void process(); + + // ugh + Mudela_key* mudela_key_l_; + Mudela_meter* mudela_meter_l_; + Mudela_tempo* mudela_tempo_l_; + +private: + void filter_tempo(); + void quantify_columns(); + void quantify_durations(); + void settle_columns(); + + Pointer_list mudela_column_p_list_; + Pointer_list mudela_staff_p_list_; +// Link_array column_l_array_; + // huh? + Link_array column_l_array_; + +// ugh, ugh, ugh +public: + int format_i_; + int tracks_i_; + int tempo_i_; +}; + +#endif // MUDELA_SCORE_HH + diff --git a/mi2mu/include/mudela-staff.hh b/mi2mu/include/mudela-staff.hh new file mode 100644 index 0000000000..06fc8b25c7 --- /dev/null +++ b/mi2mu/include/mudela-staff.hh @@ -0,0 +1,48 @@ +// +// mudela-staff.hh -- declare mudela_staff +// +// copyright 1997 Jan Nieuwenhuizen + +#ifndef MUDELA_STAFF_HH +#define MUDELA_STAFF_HH + +#include "mi2mu-proto.hh" +#include "proto.hh" +#include "plist.hh" +#include "string.hh" + +/// (mudela_staff) +class Mudela_staff { +public: + Mudela_staff (int number_i, String copyright_str, String track_name_str, String instrument_str); + ~Mudela_staff(); + + void add_item (Mudela_item* mudela_item_p); + void eat_voice (Link_list& items); + String id_str(); + String name_str(); + void output (Mudela_stream& mudela_stream_r); + void process(); + void set_meter (int num_i, int den_i, int clocks_i, int count_32_i); + void set_tempo (int useconds_i); + + String copyright_str_; + String instrument_str_; + String name_str_; + Mudela_meter* mudela_meter_p_; + Mudela_tempo* mudela_tempo_p_; + int number_i_; + +private: + void output_mudela_begin_bar (Mudela_stream& mudela_stream_r, Moment now_mom, int bar_i); +#if 0 + void output_mudela_rest (Mudela_stream& mudela_stream_r, Moment begin_mom, Moment end_mom); + void output_mudela_rest_remain (Mudela_stream& mudela_stream_r, Moment mom); +#endif + + Pointer_list mudela_voice_p_list_; + Pointer_list mudela_item_p_list_; +}; + +#endif // MUDELA_STAFF_HH + diff --git a/mi2mu/include/mudela-stream.hh b/mi2mu/include/mudela-stream.hh new file mode 100644 index 0000000000..f353838ea6 --- /dev/null +++ b/mi2mu/include/mudela-stream.hh @@ -0,0 +1,40 @@ +// +// mudela-stream.hh -- part of LilyPond +// +// copyright 1997 Jan Nieuwenhuizen + +// should i be named Mudela_stream? + +#ifndef MUDELA_STREAM_HH +#define MUDELA_STREAM_HH + +#include "mi2mu-proto.hh" +#include "string.hh" + +/// Lily output +class Mudela_stream { +public: + Mudela_stream (String filename_str); + ~Mudela_stream(); + + Mudela_stream& operator << (String str); + Mudela_stream& operator << (Mudela_item& mudela_item_r); + +private: + void handle_pending_indent(); + void header(); + void open(); + void output (String str); + void output_wrapped (String str); + + ostream* os_p_; + String filename_str_; + int indent_i_; + int column_i_; + int pending_indent_i_; + int wrap_column_i_; + bool comment_mode_b_; +}; + +#endif // MUDELA_STREAM_HH + diff --git a/mi2mu/include/mudela-voice.hh b/mi2mu/include/mudela-voice.hh new file mode 100644 index 0000000000..ab4aef142d --- /dev/null +++ b/mi2mu/include/mudela-voice.hh @@ -0,0 +1,29 @@ +// +// mudela-voice.hh -- declare Mudela_voice +// +// copyright 1997 Jan Nieuwenhuizen + +#ifndef MUDELA_VOICE_HH +#define MUDELA_VOICE_HH + +#include "mi2mu-proto.hh" +#include "plist.hh" + +/// (mudela_voice) +class Mudela_voice { +public: + Mudela_voice (Mudela_staff* mudela_staff_l); + + void add_item (Mudela_item* mudela_item_l); + Moment begin_mom(); + Moment end_mom(); + + void output (Mudela_stream& mudela_stream_r); + +private: + Mudela_staff* mudela_staff_l_; + Link_list mudela_item_l_list_; +}; + +#endif // MUDELA_VOICE_HH + diff --git a/mi2mu/include/my-midi-lexer.hh b/mi2mu/include/my-midi-lexer.hh index fb6bf62926..7b8b809aa7 100644 --- a/mi2mu/include/my-midi-lexer.hh +++ b/mi2mu/include/my-midi-lexer.hh @@ -8,7 +8,6 @@ #include #include "proto.hh" -// #include "fproto.hh" #include "varray.hh" #include "string.hh" @@ -18,22 +17,22 @@ void yyerror(const char *s); /// (midi_lexer) class My_midi_lexer : yyFlexLexer { public: - My_midi_lexer( String& filename_str, Sources* ); - ~My_midi_lexer(); + My_midi_lexer (String& filename_str, Sources*); + ~My_midi_lexer(); - int close_i(); - void error( char const* sz_l ); - char const* here_ch_C(); - static int varint2_i( String str ); - int yylex(); - Source_file* source_file_l_ ; + int close_i(); + void error (char const* sz_l); + char const* here_ch_C(); + static int varint2_i (String str); + int yylex(); + Source_file* source_file_l_ ; private: - int char_count_; - int running_status_i_; + int char_count_; + int running_status_i_; public: // ugh - int errorlevel_i_; + int errorlevel_i_; }; extern My_midi_lexer* midi_lexer_l_g; diff --git a/mi2mu/include/my-midi-parser.hh b/mi2mu/include/my-midi-parser.hh index 95367f3fa0..bcebb14ff6 100644 --- a/mi2mu/include/my-midi-parser.hh +++ b/mi2mu/include/my-midi-parser.hh @@ -6,6 +6,14 @@ #ifndef MY_MIDI_PARSER_HH #define MY_MIDI_PARSER_HH +#include "mi2mu-proto.hh" +#include "proto.hh" +#include "plist.hh" +#include "string.hh" +#include "moment.hh" + +#include "string.hh" +#include "moment.hh" int yyparse(); @@ -15,42 +23,45 @@ int yyparse(); */ class My_midi_parser { public: - My_midi_parser( String filename_str,Sources * ); + My_midi_parser (String filename_str,Sources *); ~My_midi_parser(); - void add_score( Midi_score* midi_score_p ); - void error( char const* sz_l ); + void add_score (Mudela_score* mudela_score_p); + void error (char const* sz_l); int parse(); - void forward( int i ); - Moment mom(); - void note_begin( int channel_i, int pitch_i, int dyn_i ); - Midi_event* note_end_midi_event_p( int channel_i, int pitch_i, int dyn_i ); - int output_mudela( String filename_str ); + void forward (int i); + Moment at_mom(); + void note_begin (int channel_i, int pitch_i, int dyn_i); + void note_end (int channel_i, int pitch_i, int aftertouch_i); + void note_end_all(); + void reset(); - void set_division_4( int division_4_i ); - void set_key( int accidentals_i, int minor_i ); - void set_tempo( int useconds_per_4_i ); - void set_time( int num_i, int den_i, int clocks_i, int count_32_i ); + void set_division_4 (int division_4_i); + void set_key (int accidentals_i, int minor_i); + void set_meter (int num_i, int den_i, int clocks_i, int count_32_i); + void set_tempo (int useconds_per_4_i); int bar_i_; + + // ugh int track_i_; String filename_str_; String copyright_str_; String instrument_str_; String track_name_str_; - Midi_key* midi_key_p_; - Midi_tempo* midi_tempo_p_; - Midi_time* midi_time_p_; + // ugh + Mudela_key* mudela_key_p_; + Mudela_meter* mudela_meter_p_; + Mudela_tempo* mudela_tempo_p_; -private: - I64 now_i64_; // 31 bits yields tipically about 1000 bars + Mudela_staff* mudela_staff_l_; + Mudela_score* mudela_score_p_; + Mudela_column* mudela_column_l_; - static int const CHANNELS_i = 16; - static int const PITCHES_i = 128; - I64 running_i64_i64_a_[ CHANNELS_i ][ PITCHES_i ]; +private: + Link_list open_mudela_note_l_list_; - Midi_score* midi_score_p_; int division_1_i_; char const* defined_ch_C_; diff --git a/mi2mu/main.cc b/mi2mu/main.cc index a50cf55ff6..26d92bcafb 100644 --- a/mi2mu/main.cc +++ b/mi2mu/main.cc @@ -4,173 +4,187 @@ // // copyright 1997 Jan Nieuwenhuizen -#include "mi2mu.hh" +#include "string-convert.hh" +#include "lgetopt.hh" #include "path.hh" +#include "duration-convert.hh" +#include "source.hh" + +#include "mi2mu-global.hh" +#include "my-midi-parser.hh" +#include "mudela-score.hh" +#include "version.hh" Sources source; Sources* source_l_g = &source; +static File_path path; + Verbose level_ver = NORMAL_ver; -// ugh, another global -String -find_file( String str ) -{ - return str; -} +/// just to make sure print_rat is linked in +static void (*rat_printer)(Moment const&); void usage() { - tor( NORMAL_ver ) << - "Usage: mi2mu [options] midi-file\n" - "Translate midi-file to mudela\n" - "\n" - "Options:\n" - " -b, --no-quantify write exact durations, e.g.: a4*385/384\n" - " -d, --debug print lots of debugging stuff\n" - " -h, --help this help\n" - " -I, --include=DIR add DIR to search path\n" - " -n, --no-silly assume no plets or double dots, smallest is 32\n" - " -o, --output=FILE set FILE as default output\n" - " -p, --no-plets assume no plets\n" - " -q, --quiet be quiet\n" - " -s, --smallest=N assume no shorter (reciprocal) durations than N\n" - " -v, --verbose be verbose\n" - " -w, --warranty show warranty and copyright\n" - " -x, --no-double-dots assume no double dotted notes\n" - ; + LOGOUT(NORMAL_ver) << + "Usage: mi2mu [options] midi-file\n" + "Translate midi-file to mudela\n" + "\n" + "Options:\n" + " -b, --no-quantify write exact durations, e.g.: a4*385/384\n" + " -d, --debug print lots of debugging stuff\n" + " -h, --help this help\n" + " -I, --include=DIR add DIR to search path\n" + " -n, --no-silly assume no plets or double dots, smallest is 32\n" + " -o, --output=FILE set FILE as default output\n" + " -p, --no-plets assume no plets\n" + " -q, --quiet be quiet\n" + " -s, --smallest=N assume no shorter (reciprocal) durations than N\n" + " -v, --verbose be verbose\n" + " -w, --warranty show warranty and copyright\n" + " -x, --no-double-dots assume no double dotted notes\n" + ; } void identify() { - tor( NORMAL_ver ) << mi2mu_version_str() << endl; + LOGOUT(NORMAL_ver) << mi2mu_version_str() << endl; } void notice() { - tor( NORMAL_ver ) << - "\n" - "Mi2mu, translate midi to mudela.\n" - "Copyright (C) 1997 by\n" - " Jan Nieuwenhuizen \n" - " Han-Wen Nienhuys \n" - "\n" - " This program is free software; you can redistribute it and/or\n" - "modify it under the terms of the GNU General Public License version 2\n" - "as published by the Free Software Foundation.\n" - "\n" - " This program is distributed in the hope that it will be useful,\n" - "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" - "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n" - "General Public License for more details.\n" - "\n" - " You should have received a copy (refer to the file COPYING) of the\n" - "GNU General Public License along with this program; if not, write to\n" - "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n" - "USA.\n"; + LOGOUT(NORMAL_ver) << + "\n" + "Mi2mu, translate midi to mudela.\n" + "Copyright (C) 1997 by\n" + " Jan Nieuwenhuizen \n" + " Han-Wen Nienhuys \n" + "\n" + " This program is free software; you can redistribute it and/or\n" + "modify it under the terms of the GNU General Public License version 2\n" + "as published by the Free Software Foundation.\n" + "\n" + " This program is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n" + "General Public License for more details.\n" + "\n" + " You should have received a copy (refer to the file COPYING) of the\n" + "GNU General Public License along with this program; if not, write to\n" + "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n" + "USA.\n"; } int -main( int argc_i, char* argv_sz_a[] ) +main (int argc_i, char* argv_sz_a[]) { - Long_option_init long_option_init_a[] = { - {0, "no-quantify", 'b'}, - {0, "debug", 'd'}, - {0, "help", 'h'}, - {0, "no-silly", 'n'}, - {1, "output", 'o'}, - {0, "no-plets", 'p'}, - {0, "quiet", 'q'}, - {1, "smallest", 's'}, - {0, "verbose", 'v'}, - {0, "warranty", 'w'}, - {0, "no-double-dots", 'x'}, - {0,0,0} - }; - Getopt_long getopt_long( argc_i, argv_sz_a, long_option_init_a ); - - String output_str; - while ( Long_option_init const* long_option_init_p = getopt_long() ) - switch ( long_option_init_p->shortname ) { - case 'b': - Duration_convert::no_quantify_b_s = true; - break; - case 'd': - level_ver = DEBUG_ver; - break; - case 'h': - identify(); - usage(); - exit( 0 ); - break; -// case 'I': -// path->push( getopt_long.optarg ); -// break; - case 'n': - Duration_convert::no_double_dots_b_s = true; - Duration_convert::no_triplets_b_s = true; - Duration_convert::no_smaller_than_i_s = 32; - break; - case 'o': - output_str = getopt_long.optional_argument_ch_C_; - break; - case 'p': - Duration_convert::no_triplets_b_s = true; - break; - case 'q': - level_ver = QUIET_ver; - break; - case 's': { - int i = String_convert::dec2_i( getopt_long.optional_argument_ch_C_ ); - if ( !i ) { - identify(); - usage(); - exit( 2 ); //usage - } - Duration_convert::no_smaller_than_i_s = i; - } - break; - case 'v': - level_ver = VERBOSE_ver; - break; - case 'w': - identify(); - notice(); - exit( 0 ); - break; - case 'x': - Duration_convert::no_double_dots_b_s = true; - break; - default: - assert( 0 ); - break; - } - - // flag -q must be checked first - identify(); - - char const* arg_sz = 0; - while ( ( arg_sz = getopt_long.get_next_arg() ) ) { - My_midi_parser midi_parser( arg_sz, & source ); - midi_parser_l_g = &midi_parser; - - int error_i = midi_parser.parse(); - if ( error_i ) - return error_i; - if ( !output_str.length_i() ) { - String d, dir, base, ext; - - split_path(arg_sz, d, dir, base, ext); - - output_str = base + ext + ".ly"; + rat_printer = print_rat; + + Long_option_init long_option_init_a[] = { + {0, "no-quantify", 'b'}, + {0, "debug", 'd'}, + {0, "help", 'h'}, + {0, "no-silly", 'n'}, + {1, "output", 'o'}, + {0, "no-plets", 'p'}, + {0, "quiet", 'q'}, + {1, "smallest", 's'}, + {0, "verbose", 'v'}, + {0, "warranty", 'w'}, + {0, "no-double-dots", 'x'}, + {0,0,0} + }; + Getopt_long getopt_long (argc_i, argv_sz_a, long_option_init_a); + + String output_str; + while (Long_option_init const* long_option_init_p = getopt_long()) + switch (long_option_init_p->shortname) { + case 'b': + Duration_convert::no_quantify_b_s = true; + break; + case 'd': + level_ver = DEBUG_ver; + break; + case 'h': + identify(); + usage(); + exit (0); + break; +// case 'I': +// path->push (getopt_long.optional_argument_ch_C_); +// break; + case 'n': + Duration_convert::no_double_dots_b_s = true; + Duration_convert::no_triplets_b_s = true; + Duration_convert::no_smaller_than_i_s = 32; + break; + case 'o': + output_str = getopt_long.optional_argument_ch_C_; + break; + case 'p': + Duration_convert::no_triplets_b_s = true; + break; + case 'q': + level_ver = QUIET_ver; + break; + case 's': { + int i = String_convert::dec2_i (getopt_long.optional_argument_ch_C_); + if (!i) { + identify(); + usage(); + exit (2); //usage } - error_i = midi_parser.output_mudela( output_str ); - if ( error_i ) - return error_i; - midi_parser_l_g = 0; + Duration_convert::no_smaller_than_i_s = i; + } + break; + case 'v': + level_ver = VERBOSE_ver; + break; + case 'w': + identify(); + notice(); + exit (0); + break; + case 'x': + Duration_convert::no_double_dots_b_s = true; + break; + default: + assert (0); + break; + } + + // flag -q must be checked first + identify(); + + path.add (""); + source_l_g->set_path (&path); + + char const* arg_sz = 0; + while ( (arg_sz = getopt_long.get_next_arg())) { + My_midi_parser midi_parser (arg_sz, & source); + midi_parser_l_g = &midi_parser; + + int error_i = midi_parser.parse(); + if (error_i) + return error_i; + + if (!output_str.length_i()) { + String d, dir, base, ext; + + split_path (arg_sz, d, dir, base, ext); + + output_str = base + ext + ".ly"; } - return 0; + + assert (midi_parser.mudela_score_p_); + midi_parser.mudela_score_p_->process(); + midi_parser.mudela_score_p_->output (output_str); + + midi_parser_l_g = 0; + } + return 0; } diff --git a/mi2mu/mi2mu-version.cc b/mi2mu/mi2mu-version.cc index 78773e7208..a2bdd3f6cf 100644 --- a/mi2mu/mi2mu-version.cc +++ b/mi2mu/mi2mu-version.cc @@ -2,6 +2,7 @@ // version.cc -- implement inexpensive versioning // // copyright 1997 Jan Nieuwenhuizen + #include #include "version.hh" diff --git a/mi2mu/midi-lexer.l b/mi2mu/midi-lexer.l index 825f74453b..485312b974 100644 --- a/mi2mu/midi-lexer.l +++ b/mi2mu/midi-lexer.l @@ -22,7 +22,10 @@ (don-t forget to rm lex.yy.cc :-) */ -#include "mi2mu.hh" +#include "string-convert.hh" +#include "mi2mu-global.hh" +#include "mi2mu-proto.hh" +#include "my-midi-lexer.hh" #include "midi-parser.hh" #define YY_USER_ACTION char_count_ += YYLeng(); // ugh @@ -101,87 +104,87 @@ SSME [\0x7f][\x03] %% {HEADER} { - tor( DEBUG_ver ) << "lex: header" << endl; - yy_push_state( int16 ); - yy_push_state( int16 ); - yy_push_state( int16 ); - yy_push_state( int32 ); + LOGOUT(DEBUG_ver) << "lex: header" << endl; + yy_push_state(int16); + yy_push_state(int16); + yy_push_state(int16); + yy_push_state(int32); return HEADER; } {TRACK} { - tor( DEBUG_ver ) << "lex: track" << endl; - yy_push_state( track ); - yy_push_state( int32 ); + LOGOUT(DEBUG_ver) << "lex: track" << endl; + yy_push_state(track); + yy_push_state(int32); return TRACK; } {U8} { - error( String( "top level: header expected: " ) - + String_convert::bin2hex_str( String( *YYText() ) ) ); - exit( 1 ); + error(String("top level: header expected: ") + + String_convert::bin2hex_str(String(*YYText()))); + exit(1); } {BACKUP_TOP_0} { - error( String( "top level: header expected: " ) - + String_convert::bin2hex_str( String( *( YYText() ) ) ) ); - exit( 1 ); + error(String("top level: header expected: ") + + String_convert::bin2hex_str(String(*(YYText())))); + exit(1); } {BACKUP_TOP_1} { - error( String( "top level: header expected: " ) - + String_convert::bin2hex_str( String( *( YYText() ) ) ) ); - exit( 1 ); + error(String("top level: header expected: ") + + String_convert::bin2hex_str(String(*(YYText())))); + exit(1); } {BACKUP_TOP_2} { - error( String( "top level: header expected: " ) - + String_convert::bin2hex_str( String( *( YYText() ) ) ) ); - exit( 1 ); + error(String("top level: header expected: ") + + String_convert::bin2hex_str(String(*(YYText())))); + exit(1); } {INT32} { // really signed? - tor( DEBUG_ver ) << "lex: int32" << endl; - assert( YYLeng() == 4 ); - String str( (Byte const*)YYText(), YYLeng() ); - yylval.i = String_convert::bin2_i( str ); + LOGOUT(DEBUG_ver) << "lex: int32" << endl; + assert(YYLeng() == 4); + String str((Byte const*)YYText(), YYLeng()); + yylval.i = String_convert::bin2_i(str); yy_pop_state(); return INT32; } {BACKUP_INT32_0} { - error( String( "int32: int32 expected: " ) - + String_convert::bin2hex_str( String( *( YYText() ) ) ) ); - exit( 1 ); + error(String("int32: int32 expected: ") + + String_convert::bin2hex_str(String(*(YYText())))); + exit(1); } {BACKUP_INT32_1} { - error( String( "int32: int32 expected: " ) - + String_convert::bin2hex_str( String( *( YYText() ) ) ) ); - exit( 1 ); + error(String("int32: int32 expected: ") + + String_convert::bin2hex_str(String(*(YYText())))); + exit(1); } {BACKUP_INT32_2} { - error( String( "int32: int32 expected: " ) - + String_convert::bin2hex_str( String( *( YYText() ) ) ) ); - exit( 1 ); + error(String("int32: int32 expected: ") + + String_convert::bin2hex_str(String(*(YYText())))); + exit(1); } {INT16} { // really signed? - tor( DEBUG_ver ) << "lex: int16" << endl; - assert( YYLeng() == 2 ); - String str( (Byte const*)YYText(), YYLeng() ); - yylval.i = (short)String_convert::bin2_i( str ); + LOGOUT(DEBUG_ver) << "lex: int16" << endl; + assert(YYLeng() == 2); + String str((Byte const*)YYText(), YYLeng()); + yylval.i = (short)String_convert::bin2_i(str); yy_pop_state(); return INT16; } {BACKUP_INT16_0} { - error( String( "int16: int16 expected: " ) - + String_convert::bin2hex_str( String( *( YYText() ) ) ) ); - exit( 1 ); + error(String("int16: int16 expected: ") + + String_convert::bin2hex_str(String(*(YYText())))); + exit(1); } {I8} { - tor( DEBUG_ver ) << "lex: i8" << endl; - assert( YYLeng() == 1 ); + LOGOUT(DEBUG_ver) << "lex: i8" << endl; + assert(YYLeng() == 1); // yylval.byte = *(signed char*)YYText(); yylval.i = *(signed char*)YYText(); yy_pop_state(); return I8; } {U8} { - tor( DEBUG_ver ) << "lex: u8" << endl; - assert( YYLeng() == 1 ); + LOGOUT(DEBUG_ver) << "lex: u8" << endl; + assert(YYLeng() == 1); // yylval.byte = *(Byte*)YYText(); yylval.i = *(Byte*)YYText(); yy_pop_state(); @@ -189,328 +192,329 @@ SSME [\0x7f][\x03] } {VARINT} { - String str( (Byte const*)YYText(), YYLeng() ); - yylval.i = My_midi_lexer::varint2_i( str ); - tor( DEBUG_ver ) << String( "lex: track: varint(" ) - + String( yylval.i ) + "): " - + String_convert::bin2hex_str( str ) << endl; - yy_push_state( event ); + String str((Byte const*)YYText(), YYLeng()); + yylval.i = My_midi_lexer::varint2_i(str); + LOGOUT(DEBUG_ver) << String("lex: track: varint(") + + String(yylval.i) + "): " + + String_convert::bin2hex_str(str) << endl; + yy_push_state(event); return VARINT; } {U8} { - error( String( "track: illegal byte: " ) - + String_convert::bin2hex_str( String( *YYText() ) ) ); - exit( 1 ); + error(String("track: illegal byte: ") + + String_convert::bin2hex_str(String(*YYText()))); + exit(1); } {BACKUP_VARINT_0}{U8} { - error( String( "track: varint expected: " ) - + String_convert::bin2hex_str( String( *( YYText() ) ) ) ); - exit( 1 ); + error(String("track: varint expected: ") + + String_convert::bin2hex_str(String(*(YYText())))); + exit(1); } {BACKUP_VARINT_1}{U8} { - error( String( "track: varint expected: " ) - + String_convert::bin2hex_str( String( *( YYText() ) ) ) ); - exit( 1 ); + error(String("track: varint expected: ") + + String_convert::bin2hex_str(String(*(YYText())))); + exit(1); } {BACKUP_VARINT_2}{U8} { - error( String( "track: varint expected: " ) - + String_convert::bin2hex_str( String( *( YYText() ) ) ) ); - exit( 1 ); + error(String("track: varint expected: ") + + String_convert::bin2hex_str(String(*(YYText())))); + exit(1); } {RUNNING_STATUS} { // yylval.byte = *(Byte*)YYText(); // yylval.i = *(Byte*)YYText(); yylval.i = running_status_i_; - tor( DEBUG_ver ) << String ( "lex: running status: " ) + String( yylval.i ) << endl; + LOGOUT(DEBUG_ver) << String ("lex: running status: ") + String(yylval.i) << endl; /* 'running status' rather means 'missing status'. we'll put the running status data back, prepend (unput) the running status, and try again. */ - yyless( 0 ); - unput( running_status_i_ ); + yyless(0); + unput(running_status_i_); return RUNNING_STATUS; } {DATA_ENTRY} { // yylval.byte = *(Byte*)YYText(); yylval.i = *(Byte*)YYText(); - tor( DEBUG_ver ) << String ( "lex: undefined data entry: " ) + String( yylval.i ) << endl; + LOGOUT(DEBUG_ver) << String ("lex: undefined data entry: ") + String(yylval.i) << endl; yy_pop_state(); - yy_push_state( u8 ); + yy_push_state(u8); return DATA_ENTRY; } {ALL_NOTES_OFF} { - tor( DEBUG_ver ) << "lex: all note off" << endl; + LOGOUT(DEBUG_ver) << "lex: all note off" << endl; // yylval.byte = *(Byte*)YYText(); yylval.i = *(Byte*)YYText(); - tor( DEBUG_ver ) << String ( "lex: all notes off: " ) + String( yylval.i ) << endl; + LOGOUT(DEBUG_ver) << String ("lex: all notes off: ") + String(yylval.i) << endl; yy_pop_state(); - yy_push_state( u8 ); - yy_push_state( u8 ); + yy_push_state(u8); + yy_push_state(u8); return ALL_NOTES_OFF; } {NOTE_OFF} { - tor( DEBUG_ver ) << "lex: note off" << endl; + LOGOUT(DEBUG_ver) << "lex: note off" << endl; // yylval.byte = *(Byte*)YYText(); yylval.i = *(Byte*)YYText(); running_status_i_ = yylval.i; yy_pop_state(); - yy_push_state( u8 ); - yy_push_state( u8 ); + yy_push_state(u8); + yy_push_state(u8); return NOTE_OFF; } {NOTE_ON} { - tor( DEBUG_ver ) << "lex: note on" << endl; + LOGOUT(DEBUG_ver) << "lex: note on" << endl; // yylval.byte = *(Byte*)YYText(); yylval.i = *(Byte*)YYText(); running_status_i_ = yylval.i; yy_pop_state(); - yy_push_state( u8 ); - yy_push_state( u8 ); + yy_push_state(u8); + yy_push_state(u8); return NOTE_ON; } {POLYPHONIC_AFTERTOUCH} { - tor( DEBUG_ver ) << "lex: polyphonic aftertouch" << endl; + LOGOUT(DEBUG_ver) << "lex: polyphonic aftertouch" << endl; // yylval.byte = *(Byte*)YYText(); yylval.i = *(Byte*)YYText(); running_status_i_ = yylval.i; yy_pop_state(); - yy_push_state( u8 ); - yy_push_state( u8 ); + yy_push_state(u8); + yy_push_state(u8); return POLYPHONIC_AFTERTOUCH; } {CONTROLMODE_CHANGE} { - tor( DEBUG_ver ) << "lex: controlmode change" << endl; + LOGOUT(DEBUG_ver) << "lex: controlmode change" << endl; // yylval.byte = *(Byte*)YYText(); yylval.i = *(Byte*)YYText(); running_status_i_ = yylval.i; yy_pop_state(); - yy_push_state( u8 ); - yy_push_state( u8 ); + yy_push_state(u8); + yy_push_state(u8); return CONTROLMODE_CHANGE; } {PROGRAM_CHANGE} { - tor( DEBUG_ver ) << "lex: program change" << endl; + LOGOUT(DEBUG_ver) << "lex: program change" << endl; // yylval.byte = *(Byte*)YYText(); yylval.i = *(Byte*)YYText(); running_status_i_ = yylval.i; yy_pop_state(); - yy_push_state( u8 ); + yy_push_state(u8); return PROGRAM_CHANGE; } {CHANNEL_AFTERTOUCH} { - tor( DEBUG_ver ) << "lex: channel aftertouch" << endl; + LOGOUT(DEBUG_ver) << "lex: channel aftertouch" << endl; // yylval.byte = *(Byte*)YYText(); yylval.i = *(Byte*)YYText(); running_status_i_ = yylval.i; yy_pop_state(); - yy_push_state( u8 ); - yy_push_state( u8 ); + yy_push_state(u8); + yy_push_state(u8); return CHANNEL_AFTERTOUCH; } {PITCHWHEEL_RANGE} { - tor( DEBUG_ver ) << "lex: pitchwheel range" << endl; + LOGOUT(DEBUG_ver) << "lex: pitchwheel range" << endl; // yylval.byte = *(Byte*)YYText(); yylval.i = *(Byte*)YYText(); running_status_i_ = yylval.i; yy_pop_state(); - yy_push_state( u8 ); - yy_push_state( u8 ); + yy_push_state(u8); + yy_push_state(u8); return PITCHWHEEL_RANGE; } {SYSEX_EVENT1} { // len data - tor( DEBUG_ver ) << "lex: sysex1" << endl; + LOGOUT(DEBUG_ver) << "lex: sysex1" << endl; yy_pop_state(); - yy_push_state( data ); + yy_push_state(data); return SYSEX_EVENT1; } {SYSEX_EVENT2} { // len data - tor( DEBUG_ver ) << "lex: sysex2" << endl; + LOGOUT(DEBUG_ver) << "lex: sysex2" << endl; yy_pop_state(); -// yy_push_state( u8 ); //? - yy_push_state( data ); +// yy_push_state(u8); //? + yy_push_state(data); return SYSEX_EVENT2; } {META_EVENT} { - tor( DEBUG_ver ) << "lex: meta" << endl; - yy_push_state( meta_event ); + LOGOUT(DEBUG_ver) << "lex: meta" << endl; + yy_push_state(meta_event); return META_EVENT; } {U8} { - error( String( "event: illegal byte: " ) - + String_convert::bin2hex_str( String( *YYText() ) ) ); - exit( 1 ); + error(String("event: illegal byte: ") + + String_convert::bin2hex_str(String(*YYText()))); + exit(1); } {SEQUENCE} { // ssss sequence number - tor( DEBUG_ver ) << "lex: sequence" << endl; + LOGOUT(DEBUG_ver) << "lex: sequence" << endl; yy_pop_state(); yy_pop_state(); - yy_push_state( int16 ); + yy_push_state(int16); return SEQUENCE; } {YYTEXT} { // len data - tor( DEBUG_ver ) << "lex: text" << endl; + LOGOUT(DEBUG_ver) << "lex: text" << endl; // yylval.byte = *(Byte*)YYText(); yylval.i = *(Byte*)YYText(); yy_pop_state(); yy_pop_state(); - yy_push_state( data ); + yy_push_state(data); return YYTEXT; } {YYCOPYRIGHT} { - tor( DEBUG_ver ) << "lex: copyright" << endl; + LOGOUT(DEBUG_ver) << "lex: copyright" << endl; // yylval.byte = *(Byte*)YYText(); yylval.i = *(Byte*)YYText(); yy_pop_state(); yy_pop_state(); - yy_push_state( data ); + yy_push_state(data); return YYCOPYRIGHT; } {YYTRACK_NAME} { - tor( DEBUG_ver ) << "lex: track name" << endl; + LOGOUT(DEBUG_ver) << "lex: track name" << endl; // yylval.byte = *(Byte*)YYText(); yylval.i = *(Byte*)YYText(); yy_pop_state(); yy_pop_state(); - yy_push_state( data ); + yy_push_state(data); return YYTRACK_NAME; } {YYINSTRUMENT_NAME} { - tor( DEBUG_ver ) << "lex: instrument name" << endl; + LOGOUT(DEBUG_ver) << "lex: instrument name" << endl; // yylval.byte = *(Byte*)YYText(); yylval.i = *(Byte*)YYText(); yy_pop_state(); yy_pop_state(); - yy_push_state( data ); + yy_push_state(data); return YYINSTRUMENT_NAME; } {YYLYRIC} { - tor( DEBUG_ver ) << "lex: lyric" << endl; + LOGOUT(DEBUG_ver) << "lex: lyric" << endl; // yylval.byte = *(Byte*)YYText(); yylval.i = *(Byte*)YYText(); yy_pop_state(); yy_pop_state(); - yy_push_state( data ); + yy_push_state(data); return YYLYRIC; } {YYMARKER} { - tor( DEBUG_ver ) << "lex: marker" << endl; + LOGOUT(DEBUG_ver) << "lex: marker" << endl; // yylval.byte = *(Byte*)YYText(); yylval.i = *(Byte*)YYText(); yy_pop_state(); yy_pop_state(); - yy_push_state( data ); + yy_push_state(data); return YYMARKER; } {YYCUE_POINT} { - tor( DEBUG_ver ) << "lex: cue point" << endl; + LOGOUT(DEBUG_ver) << "lex: cue point" << endl; // yylval.byte = *(Byte*)YYText(); yylval.i = *(Byte*)YYText(); yy_pop_state(); yy_pop_state(); - yy_push_state( data ); + yy_push_state(data); return YYCUE_POINT; } {TEMPO} { // tttttt usec - tor( DEBUG_ver ) << "lex: tempo" << endl; + LOGOUT(DEBUG_ver) << "lex: tempo" << endl; yy_pop_state(); yy_pop_state(); - yy_push_state( u8 ); - yy_push_state( u8 ); - yy_push_state( u8 ); + yy_push_state(u8); + yy_push_state(u8); + yy_push_state(u8); return TEMPO; } {SMPTE_OFFSET} { // hr mn se fr ff - tor( DEBUG_ver ) << "lex: smpte offset" << endl; + LOGOUT(DEBUG_ver) << "lex: smpte offset" << endl; yy_pop_state(); yy_pop_state(); - yy_push_state( u8 ); - yy_push_state( u8 ); - yy_push_state( u8 ); - yy_push_state( u8 ); - yy_push_state( u8 ); + yy_push_state(u8); + yy_push_state(u8); + yy_push_state(u8); + yy_push_state(u8); + yy_push_state(u8); return SMPTE_OFFSET; } {TIME} { // nn dd cc bb - tor( DEBUG_ver ) << "lex: time" << endl; + LOGOUT(DEBUG_ver) << "lex: time" << endl; yy_pop_state(); yy_pop_state(); - yy_push_state( u8 ); - yy_push_state( u8 ); - yy_push_state( u8 ); - yy_push_state( u8 ); + yy_push_state(u8); + yy_push_state(u8); + yy_push_state(u8); + yy_push_state(u8); return TIME; } {KEY} { // sf mi - tor( DEBUG_ver ) << "lex: key" << endl; + LOGOUT(DEBUG_ver) << "lex: key" << endl; yy_pop_state(); yy_pop_state(); - yy_push_state( i8 ); - yy_push_state( i8 ); + yy_push_state(i8); + yy_push_state(i8); return KEY; } {SSME} { // len data - tor( DEBUG_ver ) << "lex: smme" << endl; + LOGOUT(DEBUG_ver) << "lex: smme" << endl; yy_pop_state(); yy_pop_state(); - yy_push_state( data ); + yy_push_state(data); return SSME; } {END_OF_TRACK} { - tor( DEBUG_ver ) << "lex: end of track" << endl; + LOGOUT(DEBUG_ver) << "lex: end of track" << endl; yy_pop_state(); yy_pop_state(); yy_pop_state(); return END_OF_TRACK; } {U8} { - warning( String( "meta_event: unimplemented event: " ) - + String_convert::bin2hex_str( String( *YYText() ) ) -//, this->here_ch_C() + warning(String("meta_event: unimplemented event: ") + + String_convert::bin2hex_str(String(*YYText())) +// huh? +// ,this->here_ch_C() ); yy_pop_state(); yy_pop_state(); - yy_push_state( u8 ); - yy_push_state( u8 ); + yy_push_state(u8); + yy_push_state(u8); return U8; } {VARINT} { - tor( DEBUG_ver ) << "lex: data" << endl; - String str( (Byte const*)YYText(), YYLeng() ); - int i = My_midi_lexer::varint2_i( str ); + LOGOUT(DEBUG_ver) << "lex: data" << endl; + String str((Byte const*)YYText(), YYLeng()); + int i = My_midi_lexer::varint2_i(str); String* str_p = new String; - while ( i-- ) + while (i--) *str_p += (char)yyinput(); yylval.str_p = str_p; yy_pop_state(); return DATA; } {U8} { - error( String( "data: illegal byte: " ) - + String_convert::bin2hex_str( String( *YYText() ) ) ); - exit( 1 ); + error(String("data: illegal byte: ") + + String_convert::bin2hex_str(String(*YYText()))); + exit(1); } {BACKUP_VARINT_0}{U8} { - error( String( "data: varint expected: " ) - + String_convert::bin2hex_str( String( *( YYText() ) ) ) ); - exit( 1 ); + error(String("data: varint expected: ") + + String_convert::bin2hex_str(String(*(YYText())))); + exit(1); } {BACKUP_VARINT_1}{U8} { - error( String( "data: varint expected: " ) - + String_convert::bin2hex_str( String( *( YYText() ) ) ) ); - exit( 1 ); + error(String("data: varint expected: ") + + String_convert::bin2hex_str(String(*(YYText())))); + exit(1); } {BACKUP_VARINT_2}{U8} { - error( String( "data: varint expected: " ) - + String_convert::bin2hex_str( String( *( YYText() ) ) ) ); - exit( 1 ); + error(String("data: varint expected: ") + + String_convert::bin2hex_str(String(*(YYText())))); + exit(1); } <> { -// tor( NORMAL_ver ) << "<>"; +// LOGOUT(NORMAL_ver) << "<>"; - if ( !close_i() ) + if (!close_i()) yyterminate(); // can't move this, since it actually rets a YY_NULL } diff --git a/mi2mu/midi-parser.y b/mi2mu/midi-parser.y index d28e907340..c1ec3edfed 100644 --- a/mi2mu/midi-parser.y +++ b/mi2mu/midi-parser.y @@ -1,6 +1,18 @@ %{ -#include "mi2mu.hh" +#include "mi2mu-proto.hh" +#include "proto.hh" +#include "plist.hh" +#include "warn.hh" +#include "mi2mu-global.hh" +//#include "midi-parser.hh" +#include "my-midi-parser.hh" +#include "my-midi-lexer.hh" +#include "duration-convert.hh" +#include "string-convert.hh" +#include "mudela-item.hh" +#include "mudela-score.hh" +#include "mudela-staff.hh" #ifndef NDEBUG #define YYDEBUG 1 @@ -13,9 +25,9 @@ char c; int i; String* str_p; - Midi_event* midi_event_p; // Voice_element* ? - Midi_score* midi_score_p; // Input_score* ? - Midi_track* midi_track_p; // Input_music* ? + Mudela_item* mudela_item_p; // Voice_element* ? jup, just about :-) + Mudela_score* mudela_score_p; // Input_score* ? + Mudela_staff* mudela_staff_p; // Input_music* ? } %token HEADER TRACK @@ -33,39 +45,39 @@ %token DATA %type varint -%type header midi_score -%type track -%type event -%type the_event meta_event the_meta_event text_event midi_event sysex_event -%type running_status data_entry all_notes_off -%type note_off note_on -%type polyphonic_aftertouch controlmode_change program_change -%type channel_aftertouch pitchwheel_range +%type header mudela_score +%type track +%type item +%type the_item meta_item the_meta_item text_item mudela_item sysex_item +%type running_status data_entry all_notes_off +%type note_off note_on +%type polyphonic_aftertouch controlmode_change program_change +%type channel_aftertouch pitchwheel_range %% midi: /* empty */ - | midi midi_score { - midi_parser_l_g->add_score( $2 ); + | midi mudela_score { + midi_parser_l_g->add_score ($2); } ; -midi_score: +mudela_score: header { } - | midi_score track { - $$->add_track( $2 ); + | mudela_score track { + $$->add_staff ($2); // ugh - $2->set_tempo( midi_parser_l_g->midi_tempo_p_->useconds_per_4_i() ); - $2->set_time( midi_parser_l_g->midi_time_p_->num_i(), - midi_parser_l_g->midi_time_p_->den_i(), - midi_parser_l_g->midi_time_p_->clocks_1_i(), - 8 ); - if ( midi_parser_l_g->copyright_str_.length_i() ) + $2->set_tempo (midi_parser_l_g->mudela_tempo_p_->useconds_per_4_i()); + $2->set_meter (midi_parser_l_g->mudela_meter_p_->num_i(), + midi_parser_l_g->mudela_meter_p_->den_i(), + midi_parser_l_g->mudela_meter_p_->clocks_1_i(), + 8); + if (midi_parser_l_g->copyright_str_.length_i()) $2->copyright_str_ = midi_parser_l_g->copyright_str_; - if ( midi_parser_l_g->track_name_str_.length_i() ) + if (midi_parser_l_g->track_name_str_.length_i()) $2->name_str_ = midi_parser_l_g->track_name_str_; - if ( midi_parser_l_g->instrument_str_.length_i() ) + if (midi_parser_l_g->instrument_str_.length_i()) $2->instrument_str_ = midi_parser_l_g->instrument_str_; midi_parser_l_g->reset(); } @@ -73,60 +85,64 @@ midi_score: header: HEADER INT32 INT16 INT16 INT16 { - $$ = new Midi_score( $3, $4, $5 ); - midi_parser_l_g->set_division_4( $5 ); + // ugh, already constructed; + // need to have score in My_midi_parser... +// $$ = new Mudela_score ($3, $4, $5); + $$ = midi_parser_l_g->mudela_score_p_; + $$->format_i_ = $3; + $$->tracks_i_ = $4; + $$->tempo_i_ = $5; + midi_parser_l_g->set_division_4 ($5); } ; track: TRACK INT32 { - tor( NORMAL_ver ) << "\ntrack " << midi_parser_l_g->track_i_ << ": " << flush; - $$ = new Midi_track( midi_parser_l_g->track_i_++, + LOGOUT (NORMAL_ver) << "\ntrack " << midi_parser_l_g->track_i_ << ": " << flush; + $$ = new Mudela_staff (midi_parser_l_g->track_i_++, // silly, cause not set yet! midi_parser_l_g->copyright_str_, midi_parser_l_g->track_name_str_, - midi_parser_l_g->instrument_str_ ); - } - | track event { - $$->add_event( midi_parser_l_g->mom(), $2 ); + midi_parser_l_g->instrument_str_); + //ugh, need to know now! + midi_parser_l_g->mudela_staff_l_ = $$; + } + | track item { + if ($2) { + $2->mudela_column_l_ = midi_parser_l_g->mudela_column_l_; + $$->add_item ($2); + } } ; -event: - varint the_event { +item: + varint the_item { $$ = $2; - if ( $2 ) { - String str = $2->mudela_str( false ); - if ( str.length_i() ) - tor( DEBUG_ver ) << str << " " << flush; + if ($2) { + String str = $2->str(); + if (str.length_i()) + LOGOUT (DEBUG_ver) << str << " " << flush; } } ; varint: VARINT { - midi_parser_l_g->forward( $1 ); - if ( $1 ) { - int bars_i = (int)( midi_parser_l_g->mom() / midi_parser_l_g->midi_time_p_->bar_mom() ); - if ( bars_i > midi_parser_l_g->bar_i_ ) { - tor( NORMAL_ver ) << '[' << midi_parser_l_g->bar_i_ << ']' << flush; - midi_parser_l_g->bar_i_ = bars_i; - } - } + midi_parser_l_g->forward ($1); } ; -the_event: - meta_event { +the_item: + meta_item { } - | midi_event { + | mudela_item { } - | sysex_event { + | sysex_item { } ; -meta_event: - META_EVENT the_meta_event { +meta_item: + META_EVENT the_meta_item { $$ = $2; } | @@ -135,81 +151,81 @@ meta_event: } ; -the_meta_event: +the_meta_item: SEQUENCE INT16 { } - | text_event DATA { - Midi_text::Type type = (Midi_text::Type)$1; + | text_item DATA { + Mudela_text::Type type = (Mudela_text::Type)$1; $$ = 0; - switch ( type ) + switch (type) { - case Midi_text::COPYRIGHT: + case Mudela_text::COPYRIGHT: midi_parser_l_g->copyright_str_ = *$2; break; - case Midi_text::TRACK_NAME: + case Mudela_text::TRACK_NAME: midi_parser_l_g->track_name_str_ = *$2; break; - case Midi_text::INSTRUMENT_NAME: + case Mudela_text::INSTRUMENT_NAME: midi_parser_l_g->instrument_str_ = *$2; break; default: - $$ = new Midi_text( type, *$2 ); + $$ = new Mudela_text (type, *$2); break; } - tor( DEBUG_ver ) << *$2 << endl; + LOGOUT (DEBUG_ver) << *$2 << endl; delete $2; } | END_OF_TRACK { $$ = 0; } | TEMPO U8 U8 U8 { - $$ = new Midi_tempo( ( $2 << 16 ) + ( $3 << 8 ) + $4 ); - tor( DEBUG_ver ) << $$->mudela_str( false ) << endl; - midi_parser_l_g->set_tempo( ( $2 << 16 ) + ( $3 << 8 ) + $4 ); + $$ = new Mudela_tempo ( ($2 << 16) + ($3 << 8) + $4); + LOGOUT (DEBUG_ver) << $$->str() << endl; + midi_parser_l_g->set_tempo ( ($2 << 16) + ($3 << 8) + $4); } | SMPTE_OFFSET U8 U8 U8 U8 U8 { $$ = 0; } | TIME U8 U8 U8 U8 { - $$ = new Midi_time( $2, $3, $4, $5 ); - tor( DEBUG_ver ) << $$->mudela_str( true ) << endl; - midi_parser_l_g->set_time( $2, $3, $4, $5 ); + $$ = new Mudela_meter ($2, $3, $4, $5); + LOGOUT (DEBUG_ver) << $$->str() << endl; + midi_parser_l_g->set_meter ($2, $3, $4, $5); } | KEY I8 I8 { - $$ = new Midi_key( $2, $3 ); - midi_parser_l_g->set_key( $2, $3 ); + $$ = new Mudela_key ($2, $3); + midi_parser_l_g->set_key ($2, $3 ); } | SSME DATA { - $$ = new Midi_text( (Midi_text::Type)0, *$2 ); + $$ = new Mudela_text ((Mudela_text::Type)0, *$2); delete $2; } ; -text_event: +text_item: YYTEXT { - tor( DEBUG_ver ) << "\n% Text: "; + LOGOUT (DEBUG_ver) << "\n% Text: "; } | YYCOPYRIGHT { - tor( DEBUG_ver ) << "\n% Copyright: "; + LOGOUT (DEBUG_ver) << "\n% Copyright: "; } | YYTRACK_NAME { - tor( DEBUG_ver ) << "\n% Track name: "; + LOGOUT (DEBUG_ver) << "\n% Track name: "; } | YYINSTRUMENT_NAME { - tor( DEBUG_ver ) << "\n% Instrument name: "; + LOGOUT (DEBUG_ver) << "\n% Instrument name: "; } | YYLYRIC { - tor( DEBUG_ver ) << "\n% Lyric: "; + LOGOUT (DEBUG_ver) << "\n% Lyric: "; } | YYMARKER { - tor( DEBUG_ver ) << "\n% Marker: "; + LOGOUT (DEBUG_ver) << "\n% Marker: "; } | YYCUE_POINT { - tor( DEBUG_ver ) << "\n% Cue point: "; + LOGOUT (DEBUG_ver) << "\n% Cue point: "; } ; -midi_event: +mudela_item: running_status { } | data_entry { @@ -233,7 +249,7 @@ midi_event: ; running_status: - RUNNING_STATUS midi_event { + RUNNING_STATUS mudela_item { $$ = $2; } ; @@ -246,6 +262,7 @@ data_entry: all_notes_off: ALL_NOTES_OFF U8 U8 { + midi_parser_l_g->note_end_all(); $$ = 0; } ; @@ -254,7 +271,8 @@ note_off: NOTE_OFF U8 U8 { int i = $1; i = i & ~0x80; - $$ = midi_parser_l_g->note_end_midi_event_p( $1 & ~0x80, $2, $3 ); + midi_parser_l_g->note_end ($1 & ~0x80, $2, $3); + $$ = 0; } ; @@ -263,14 +281,14 @@ note_on: int i = $1; i = i & ~0x90; $$ = 0; - if ( $3 ) - midi_parser_l_g->note_begin( $1 & ~0x90, $2, $3 ); + if ($3) + midi_parser_l_g->note_begin ($1 & ~0x90, $2, $3); /* sss: some broken devices encode NOTE_OFF as NOTE_ON with zero volume */ else - $$ = midi_parser_l_g->note_end_midi_event_p( $1 & ~0x90, $2, $3 ); + midi_parser_l_g->note_end ($1 & ~0x90, $2, $3); } ; @@ -304,7 +322,7 @@ pitchwheel_range: } ; -sysex_event: +sysex_item: SYSEX_EVENT1 DATA { $$ = 0; } diff --git a/mi2mu/mudela-column.cc b/mi2mu/mudela-column.cc new file mode 100644 index 0000000000..871be0cc61 --- /dev/null +++ b/mi2mu/mudela-column.cc @@ -0,0 +1,24 @@ +// +// mudela-column.cc -- implement Mudela_column +// +// copyright 1997 Jan Nieuwenhuizen + +#include "mudela-column.hh" + +Mudela_column::Mudela_column (Mudela_score* mudela_score_l, Moment mom) +{ + mudela_score_l_ = mudela_score_l; + at_mom_ = mom; +} + +void +Mudela_column::add_item (Mudela_item* mudela_item_l) +{ + mudela_item_l_list_.bottom().add (mudela_item_l); +} + +Moment +Mudela_column::at_mom() +{ + return at_mom_; +} diff --git a/mi2mu/mudela-item.cc b/mi2mu/mudela-item.cc new file mode 100644 index 0000000000..4e8f7ccf98 --- /dev/null +++ b/mi2mu/mudela-item.cc @@ -0,0 +1,295 @@ +// +// mudela-item.cc -- implement Mudela_item +// +// copyright 1997 Jan Nieuwenhuizen + +#include "mi2mu-global.hh" +#include "string-convert.hh" +#include "duration-convert.hh" +#include "mudela-column.hh" +#include "mudela-item.hh" +#include "mudela-stream.hh" +#include "mudela-score.hh" + +Mudela_item::Mudela_item (Mudela_column* mudela_column_l) +{ + mudela_column_l_ = mudela_column_l; +} + +Moment +Mudela_item::at_mom() +{ + return mudela_column_l_->at_mom(); +} + +Moment +Mudela_item::duration_mom() +{ + return Moment (0); +} + +void +Mudela_item::output (Mudela_stream& mudela_stream_r) +{ + mudela_stream_r << str() << String (" "); +} + +Mudela_key::Mudela_key (int accidentals_i, int minor_i) + : Mudela_item (0) +{ + accidentals_i_ = accidentals_i; + minor_i_ = minor_i; + if (accidentals_i >= 0) + key_i_ = ((accidentals_i % 7)[ "cgdaebf" ] - 'a' - 2) % 7; + else + key_i_ = ((-accidentals_i % 7)[ "cfbeadg" ] - 'a' - 2) % 7; +} + +String +Mudela_key::str() +{ + String str = "\\key "; + if (!minor_i_) + str += String ((char) ((key_i_ + 2) % 7 + 'A')); + else // heu, -2: should be - 1 1/2: A -> fis + str += String ((char) ((key_i_ + 2 - 2) % 7 + 'a')); + str = String ("% \"") + str + + String('"') + "; % not supported yet\n"; + 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)) { + accidental_i = - accidental_i; + notename_i = (notename_i + 1) % 7; + } + + String notename_str = (char) ( ((notename_i + 2) % 7) + 'a'); + while (accidental_i-- > 0) + notename_str += "is"; + accidental_i++; + while (accidental_i++ < 0) + if ((notename_str == "a") || (notename_str == "e")) + notename_str += "s"; + else + notename_str += "es"; + 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; +} + +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) + warning (String ("#32 in quarter: ") + String (count_32_i)); + 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); +} + +int +Mudela_meter::clocks_1_i() +{ + return clocks_1_i_; +} + +int +Mudela_meter::den_i() +{ + return den_i_; +} + +int +Mudela_meter::num_i() +{ + return num_i_; +} + +String +Mudela_meter::str() +{ + String str = "\\meter " + + String (num_i_) + "/" + String (1 << den_i_) + + ";\n"; + return str; +} + + +// statics Mudela_note +/* + this switch can be used to write simple plets like + c4*2/3 + as + \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) +{ + // 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_) + return ""; + + String name_str = mudela_column_l_->mudela_score_l_->mudela_key_l_->notename_str (pitch_i_); + + if (simple_plet_b_s) + return name_str + Duration_convert::dur2_str (dur) + " "; + + //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; + + Duration tmp = dur; + tmp.set_plet (1,1); + str += Duration_convert::dur2_str (tmp); + + if (dur.plet_b()) + str += String (" \\plet 1/1;"); + + 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); +} + +Moment +Mudela_note::duration_mom() +{ +// ugh +// return Duration_convert::dur2_mom (duration()); + 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) +{ + 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()); +} + +String +Mudela_skip::str() +{ + if (!mom_) + return String (""); + + Duration dur = duration(); + if (!dur.type_i_) + return ""; + + String str = "\\skip "; + str += Duration_convert::dur2_str (dur) + "; "; + + 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; +} + +String +Mudela_tempo::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_; +} + +int +Mudela_tempo::get_tempo_i (Moment moment) +{ + 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; +} + +String +Mudela_text::str() +{ + if (!text_str_.length_i() + || (text_str_.length_i() != (int)strlen (text_str_.ch_C()))) + return ""; + + return "% " + text_str_ + "\n"; +} + diff --git a/mi2mu/mudela-score.cc b/mi2mu/mudela-score.cc new file mode 100644 index 0000000000..2a82a630c1 --- /dev/null +++ b/mi2mu/mudela-score.cc @@ -0,0 +1,200 @@ +// +// mudela-score.cc -- implement Mudela_score +// +// copyright 1997 Jan Nieuwenhuizen + +#include "moment.hh" +#include "duration.hh" +#include "duration-convert.hh" +#include "mi2mu-global.hh" +#include "mudela-column.hh" +#include "mudela-item.hh" +#include "mudela-score.hh" +#include "mudela-staff.hh" +#include "mudela-stream.hh" + +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))); +} + +Mudela_score::~Mudela_score() +{ +} + +void +Mudela_score::add_item (Mudela_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_column* +Mudela_score::mudela_column_l (Moment mom) +{ + for (PCursor 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; +} + +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_) + mudela_staff_p_list_.top()->number_i_ = 1; + + int track_i = 0; + Mudela_stream mudela_stream (filename_str); + for (PCursor 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 << "<\n\\multi 3;\n"; + for (PCursor i (mudela_staff_p_list_); i.ok(); i++) { + if ( (mudela_staff_p_list_.size() != 1) + && (i == mudela_staff_p_list_.top())) + continue; + mudela_stream << "\\melodic{ "; + mudela_stream << "\\$" << i->id_str(); + mudela_stream << " }\n"; + } + if (mudela_staff_p_list_.size() > 1) + mudela_stream << ">\n"; + + mudela_stream << "\\paper{}\n"; + + 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"; +} + +void +Mudela_score::process() +{ + LOGOUT(NORMAL_ver) << "\nProcessing..." << endl; + + LOGOUT(DEBUG_ver) << "columns\n"; + for (PCursor i (mudela_column_p_list_); i.ok(); i++) + LOGOUT(DEBUG_ver) << "At: " << i->at_mom() << "\n"; + + settle_columns(); + filter_tempo(); + quantify_columns(); + quantify_durations(); + + LOGOUT(NORMAL_ver) << "\nCreating voices..." << endl; + int track_i = 0; + for (PCursor 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; +} + +void +Mudela_score::quantify_columns() +{ + // ugh + if (Duration_convert::no_quantify_b_s) { + LOGOUT(NORMAL_ver) << "\nNOT Quantifying columns..." << endl; + return; + } + + 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++) { +// 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; +} + +void +Mudela_score::quantify_durations() +{ +// LOGOUT(NORMAL_ver) << "\nQuantifying durations..." << endl; +} + +void +Mudela_score::settle_columns() +{ +// LOGOUT(NORMAL_ver) << "\nNOT Settling columns..." << endl; +// return; + LOGOUT(NORMAL_ver) << "\nSettling columns..." << endl; + + assert (!column_l_array_.size()); + int n = mudela_column_p_list_.size(); +// huh? +// column_l_array_.set_size (n); + for (PCursor 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) + / Moment (2); + 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) + && (column_l_array_[ i ]->at_mom() - start_mom < noise_mom)) + end_i = ++i; + + // bluntly set all to time of first in group + for (int j = start_i; j < end_i; j++) + column_l_array_[ j ]->at_mom_ = start_mom; + + start_i = end_i = 0; + } +} + diff --git a/mi2mu/mudela-staff.cc b/mi2mu/mudela-staff.cc new file mode 100644 index 0000000000..0c13ec4aac --- /dev/null +++ b/mi2mu/mudela-staff.cc @@ -0,0 +1,237 @@ +// +// mudela-staff.cc -- implement Mudela_staff +// +// copyright 1997 Jan Nieuwenhuizen + +#include +#include "moment.hh" +#include "duration-convert.hh" +#include "string-convert.hh" +#include "mi2mu-proto.hh" +#include "mi2mu-global.hh" +#include "mudela-column.hh" +#include "mudela-item.hh" +#include "mudela-staff.hh" +#include "mudela-stream.hh" +#include "mudela-voice.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); +} + +Mudela_staff::~Mudela_staff() +{ + 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); +} + +void +Mudela_staff::eat_voice (Link_list& 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 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(); + } + 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"; + } +} + +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 +Mudela_staff::name_str() +{ + 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 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"; + } + 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"; +} + + +#if 0 // not used for now +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; + + 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; + } + + // 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); + } + + // 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); + +// 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; + } + 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; + } + + Duration dur = Duration_convert::mom2standardised_dur (mom); + if (dur.type_i_) + mudela_stream_r << "r" << dur.str() << " "; +} +#endif + + +void +Mudela_staff::process() +{ + /* + group items into voices + */ + + Link_list items; + for (PCursor 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); +} + +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); +} + diff --git a/mi2mu/mudela-stream.cc b/mi2mu/mudela-stream.cc new file mode 100644 index 0000000000..7b7dbb8244 --- /dev/null +++ b/mi2mu/mudela-stream.cc @@ -0,0 +1,165 @@ +// +// mudela-stream.cc +// +// source file of the LilyPond music typesetter +// +// (c) 1997 Jan Nieuwenhuizen + +#include +#include +#include "mi2mu-global.hh" +#include "my-midi-parser.hh" +#include "mudela-item.hh" +#include "mudela-stream.hh" + +static int const INDENT_i = 8; + +Mudela_stream::Mudela_stream (String filename_str) +{ + filename_str_ = filename_str; + os_p_ = 0; + indent_i_ = 0; + comment_mode_b_ = false; + column_i_ = 0; + wrap_column_i_ = 68; + open(); + header(); +} + +Mudela_stream::~Mudela_stream() +{ + delete os_p_; + if (indent_i_) + warning ("lily indent level: " + String (indent_i_)); +} + +Mudela_stream& +Mudela_stream::operator << (String str) +{ + static String word_sep_str = "{} \t\n"; + while (str.length_i()) { + int i = str.index_any_i (word_sep_str) + 1; + if (!i) + i = str.length_i(); + String word = str.left_str (i); + str = str.mid_str (i, str.length_i()); + output_wrapped (word); + } + return *this; +} + +Mudela_stream& +Mudela_stream::operator << (Mudela_item& mudela_item_r) +{ + mudela_item_r.output (*this); + *os_p_ << flush; + return *this; +} + +void +Mudela_stream::handle_pending_indent() +{ + *os_p_ << String ('\t', pending_indent_i_); + column_i_ += pending_indent_i_ * INDENT_i; + pending_indent_i_ = 0; +} + +void +Mudela_stream::header() +{ + *os_p_ << "% Creator: " << mi2mu_version_str() << "\n"; + *os_p_ << "% Automatically generated, at "; + time_t t (time (0)); + *os_p_ << ctime (&t); + *os_p_ << "% from input file: "; + *os_p_ << midi_parser_l_g->filename_str_; + *os_p_ << "\n\n"; + // ugh + *os_p_ << "\\version \"0.1.1\";\n"; +} + +void +Mudela_stream::open() +{ + os_p_ = new ofstream (filename_str_); + if (!*os_p_) + error ("can't open: `" + filename_str_ + "\'"); +} + +void +Mudela_stream::output (String str) +{ + for (int i = 0; i < str.length_i(); i++) { + char c = str[ i ]; + switch (c) { + case '{' : + case '<' : + handle_pending_indent(); + if (column_i_ == indent_i_ * INDENT_i) + output ("\t"); + indent_i_++; + *os_p_ << c; + column_i_++; + break; + case '}' : + case '>' : + assert (indent_i_); + indent_i_--; + if (pending_indent_i_) + pending_indent_i_--; + handle_pending_indent(); + *os_p_ << c; + column_i_++; + break; + case '%' : + handle_pending_indent(); + comment_mode_b_ = true; + *os_p_ << c; + column_i_++; + break; + case '\t' : + handle_pending_indent(); + *os_p_ << c; + column_i_ += INDENT_i; + break; + case '\n' : + *os_p_ << endl; + pending_indent_i_ = indent_i_; + column_i_ = 0; + comment_mode_b_ = false; + break; + default : + handle_pending_indent(); + *os_p_ << c; + column_i_++; + break; + } + } +} + +void +Mudela_stream::output_wrapped (String str) +{ + // enough room left -> doit + if (column_i_ + str.length_i() <= wrap_column_i_) { + output (str); + return; + } + + // we're at BOL already; this will never fit -> doit + if (column_i_ == indent_i_ * INDENT_i) { + output (str); + return; + } + + // ok, let's wrap + // preserve comment mode + if (comment_mode_b_) + output (String ("\n%")); + else + output (String ("\n")); + + output (str); +} + + diff --git a/mi2mu/mudela-voice.cc b/mi2mu/mudela-voice.cc new file mode 100644 index 0000000000..5fd2704726 --- /dev/null +++ b/mi2mu/mudela-voice.cc @@ -0,0 +1,74 @@ +// +// mudela-voice.cc -- implement Mudela_voice +// +// copyright 1997 Jan Nieuwenhuizen + +#include "string-convert.hh" +#include "mi2mu-global.hh" +#include "mudela-column.hh" +#include "mudela-item.hh" +#include "mudela-staff.hh" +#include "mudela-stream.hh" +#include "mudela-voice.hh" + +Mudela_voice::Mudela_voice (Mudela_staff* mudela_staff_l) +{ + mudela_staff_l_ = mudela_staff_l; +} + +void +Mudela_voice::add_item (Mudela_item* mudela_item_l) +{ + mudela_item_l_list_.bottom().add (mudela_item_l); +} + +Moment +Mudela_voice::begin_mom() +{ + return mudela_item_l_list_.size() ? + mudela_item_l_list_.top()->at_mom() : Moment (0); +} + +Moment +Mudela_voice::end_mom() +{ + return mudela_item_l_list_.size() ? + mudela_item_l_list_.bottom()->at_mom() : Moment (0); +} + +static int const FAIRLY_LONG_VOICE_i = 6; + +void +Mudela_voice::output (Mudela_stream& mudela_stream_r) +{ + if (!mudela_item_l_list_.size()) + return; + + if (mudela_item_l_list_.size() > FAIRLY_LONG_VOICE_i) + mudela_stream_r << "\n"; + + int current_bar_i = 0; + Moment bar_mom = mudela_staff_l_->mudela_meter_p_->bar_mom(); + + for (PCursor i (mudela_item_l_list_); i.ok(); i++) { + Moment at_mom = i->mudela_column_l_->at_mom(); + int bar_i = (int) (at_mom / bar_mom) + 1; + if (bar_i > current_bar_i) { + if (current_bar_i) { + if (at_mom == Moment (bar_i - 1) * bar_mom) + mudela_stream_r << "|"; + mudela_stream_r << "\n% "; + mudela_stream_r << String_convert::i2dec_str (bar_i, 0, ' '); + mudela_stream_r << "\n"; + } + LOGOUT(NORMAL_ver) << '[' << bar_i << ']' << flush; + current_bar_i = bar_i; + } + + mudela_stream_r << i->str(); + } + + if (mudela_item_l_list_.size() > FAIRLY_LONG_VOICE_i) + mudela_stream_r << "\n"; +} + diff --git a/mi2mu/my-midi-lexer.cc b/mi2mu/my-midi-lexer.cc index c1ec9627a4..63dfb06d8f 100644 --- a/mi2mu/my-midi-lexer.cc +++ b/mi2mu/my-midi-lexer.cc @@ -3,7 +3,11 @@ // // copyright 1997 Jan Nieuwenhuizen -#include "mi2mu.hh" +#include "string-convert.hh" +#include "mi2mu-global.hh" +#include "my-midi-lexer.hh" +#include "source.hh" +#include "source-file.hh" int yylex() @@ -13,10 +17,12 @@ yylex() My_midi_lexer* midi_lexer_l_g = 0; -My_midi_lexer::My_midi_lexer( String &filename_str, Sources * sources ) +My_midi_lexer::My_midi_lexer (String &filename_str, Sources * sources) { - source_file_l_ =sources->get_file_l(filename_str); - switch_streams( source_file_l_->istream_l() ,0 ); + source_file_l_ = sources->get_file_l(filename_str); + if (!source_file_l_) + ::error ("can't find: `" + filename_str + "'"); + switch_streams (source_file_l_->istream_l(), 0); errorlevel_i_ = 0; char_count_ = 0; running_status_i_ = 0; @@ -28,23 +34,23 @@ My_midi_lexer::~My_midi_lexer() } void -My_midi_lexer::error( char const* sz_l ) +My_midi_lexer::error (char const* sz_l) { - if (1|| !source_file_l_ ) { - cerr << "error at EOF" << sz_l << '\n'; + if (1|| !source_file_l_) { + cerr << "error at EOF: `" << sz_l << "'\n"; } else { // FIXME #if 0 char const* ch_C = here_ch_C(); - if ( ch_C ) { + if (ch_C) { ch_C--; - while ( ( *ch_C == ' ' ) || ( *ch_C == '\t' ) || ( *ch_C == '\n' ) ) + while ( (*ch_C == ' ') || (*ch_C == '\t') || (*ch_C == '\n')) ch_C--; ch_C++; } errorlevel_i_ |= 1; - error( sz_l); + error (sz_l); #endif } } @@ -56,19 +62,19 @@ My_midi_lexer::here_ch_C() } int -My_midi_lexer::varint2_i( String str ) +My_midi_lexer::varint2_i (String str) { int var_i = 0; - for ( int i = 0; i < str.length_i(); i++ ) { + for (int i = 0; i < str.length_i(); i++) { Byte byte = str[ i ]; var_i <<= 7; var_i += byte & 0x7f; - if ( ! ( byte & 0x80 ) ) + if (! (byte & 0x80)) return var_i; } - cout << "\nvarint2_i:" << String_convert::bin2hex_str( str ) << endl; - assert( 0 ); // illegal varint + cout << "\nvarint2_i:" << String_convert::bin2hex_str (str) << endl; + assert (0); // illegal varint return 0; } diff --git a/mi2mu/my-midi-parser.cc b/mi2mu/my-midi-parser.cc index 7c86998486..d0ecf943ac 100644 --- a/mi2mu/my-midi-parser.cc +++ b/mi2mu/my-midi-parser.cc @@ -3,183 +3,226 @@ // // copyright 1997 Jan Nieuwenhuizen -#include "mi2mu.hh" +#include "string-convert.hh" +#include "duration-convert.hh" +#include "mi2mu-global.hh" +#include "my-midi-lexer.hh" +#include "my-midi-parser.hh" +#include "mudela-column.hh" +#include "mudela-item.hh" +#include "mudela-score.hh" +#include "mudela-staff.hh" void -yyerror(char const* sz_l ) +yyerror(char const* sz_l) { - midi_parser_l_g->error( sz_l ); + midi_parser_l_g->error (sz_l); } My_midi_parser* midi_parser_l_g = 0; -My_midi_parser::My_midi_parser( String filename_str, Sources *sources_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 - defined_ch_C_ = 0; - fatal_error_i_ = 0; - midi_key_p_ = 0; - midi_score_p_ = 0; - midi_tempo_p_ = 0; - midi_time_p_ = 0; - track_i_ = 0; - bar_i_ = 1; - reset(); + bar_i_ = 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; + + reset(); } My_midi_parser::~My_midi_parser() { - midi_lexer_l_g = 0; // ugh + midi_lexer_l_g = 0; // ugh - delete midi_lexer_p_; - delete midi_key_p_; - delete midi_tempo_p_; - delete midi_time_p_; - delete midi_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() { - delete midi_key_p_; - midi_key_p_ = new Midi_key( 0, 0 ); - // useconds per 4: 250000 === 60 4 per minute - delete midi_tempo_p_; - midi_tempo_p_ = new Midi_tempo( 1000000 ); - delete midi_time_p_; - midi_time_p_ = new Midi_time( 4, 2, 24, 8 ); - now_i64_ = 0; - bar_i_ = 1; +// open_mudela_note_l_list_.clear(); + 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); - copyright_str_ = ""; - track_name_str_ = ""; - instrument_str_ = ""; + bar_i_ = 1; + mudela_column_l_ = mudela_score_p_->mudela_column_l (0); - for ( int i = 0; i < CHANNELS_i; i++ ) - for ( int j = 0; j < PITCHES_i; j++ ) -// running_i64_i64_a_[ i ][ j ] = -1; - running_i64_i64_a_[ i ][ j ] = 0; + // ugh + copyright_str_ = ""; + track_name_str_ = ""; + instrument_str_ = ""; } void -My_midi_parser::add_score( Midi_score* midi_score_p ) +My_midi_parser::add_score (Mudela_score* mudela_score_p) { - assert( !midi_score_p_ ); - midi_score_p_ = midi_score_p; - track_i_ = 0; - bar_i_ = 1; + assert (mudela_score_p_); + +#if 0 // ugh, already constructed + 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; } void -My_midi_parser::error( char const* sz_l ) +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_ ) - exit( fatal_error_i_ ); + if (fatal_error_i_) + exit (fatal_error_i_); } void -My_midi_parser::forward( int i ) +My_midi_parser::forward (int i) { - if ( Duration_convert::no_quantify_b_s ) { - now_i64_ += i; - return; - } - while ( i > Duration::division_1_i_s ) { - now_i64_ += Duration::division_1_i_s; - i -= Duration::division_1_i_s; - } - Duration dur = Duration_convert::ticks2standardised_dur( i ); - now_i64_ += Duration_convert::dur2ticks_i( dur ); + if (!i) + return; + + Duration dur; + dur.type_i_ = (0); + dur.set_ticks (i); + Moment mom = at_mom() + Duration_convert::dur2_mom (dur); + + mudela_column_l_ = mudela_score_p_->mudela_column_l (mom); + + if (i) { + int bars_i = (int) (mom / mudela_meter_p_->bar_mom()); + if (bars_i > bar_i_) + LOGOUT(NORMAL_ver) << '[' << bar_i_ << ']' << flush; + bar_i_ = bars_i; + } } Moment -My_midi_parser::mom() +My_midi_parser::at_mom() { - return Moment( now_i64_, Duration::division_1_i_s ); + assert (mudela_column_l_); +// return mudela_column_l_ ? mudela_column_l_->at_mom() : 0; + return mudela_column_l_->at_mom(); } void -My_midi_parser::note_begin( int channel_i, int pitch_i, int dyn_i ) -{ - // one pitch a channel at time! - // heu, what about { < c2 > < c4 d4 > } -// assert( running_i64_i64_a_[ channel_i ][ pitch_i ] == -1 ); - running_i64_i64_a_[ channel_i ][ pitch_i ] = now_i64_; -} - -Midi_event* -My_midi_parser::note_end_midi_event_p( int channel_i, int pitch_i, int dyn_i ) -{ - I64 start_i64 = running_i64_i64_a_[ channel_i ][ pitch_i ]; - -// running_i64_i64_a_[ channel_i ][ pitch_i ] = -1; -// assert( start_i64 != -1 ); // did we start? - - Duration dur; - dur.type_i_ = 0; - if ( Duration_convert::no_quantify_b_s ) - dur = Duration_convert::ticks2_dur( (I64)now_i64_ - start_i64 ); - else { - dur = Duration_convert::ticks2standardised_dur( (I64)now_i64_ - start_i64 ); - // checking myself iso using tor saves some time - if ( level_ver >= VERBOSE_ver ) { - Moment mom( (I64)now_i64_ - start_i64, Duration::division_1_i_s ); - if ( dur.length() != mom ) - warning( String( "duration not exact: " ) + String( (Real)mom ) ); - } +My_midi_parser::note_begin (int channel_i, int pitch_i, int dyn_i) +{ + // junk dynamics + (void)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); +} + +void +My_midi_parser::note_end (int channel_i, int pitch_i, int aftertouch_i) +{ + // junk dynamics + (void)aftertouch_i; + + // find + for (PCursor 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; } - return new Midi_note( midi_key_p_->notename_str( pitch_i ), dur ); + } + warning (String ("junking note-end event: ") + + " channel = " + String_convert::i2dec_str (channel_i, 0, ' ') + + ", pitch = " + String_convert::i2dec_str (pitch_i, 0, ' ')); } -int -My_midi_parser::output_mudela( String filename_str ) +void +My_midi_parser::note_end_all() { - assert( midi_score_p_ ); - tor( NORMAL_ver ) << "\nProcessing..." << endl; - midi_score_p_->process(); - return midi_score_p_->output_mudela( filename_str ); + // find + for (PCursor i (open_mudela_note_l_list_); i.ok(); i++) { + i->end_column_l_ = mudela_column_l_; + i.remove_p(); + // ugh + if (!i.ok()) + break; + } } int My_midi_parser::parse() { - tor( NORMAL_ver ) << "\nParsing..." << flush; - return ::yyparse(); + LOGOUT(NORMAL_ver) << "\nParsing..." << flush; + int i = ::yyparse(); + if (!i) + note_end_all(); + return i; } void -My_midi_parser::set_division_4( int division_4_i ) +My_midi_parser::set_division_4 (int division_4_i) { - division_1_i_ = division_4_i * 4; - Duration::division_1_i_s = division_1_i_; - if ( division_4_i < 0 ) - warning( "seconds iso metrical time" ); + 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 ) +My_midi_parser::set_key (int accidentals_i, int minor_i) { - delete midi_key_p_; - midi_key_p_ = new Midi_key( accidentals_i, minor_i ); + delete mudela_key_p_; + mudela_key_p_ = new Mudela_key (accidentals_i, minor_i); } void -My_midi_parser::set_tempo( int useconds_per_4_i ) +My_midi_parser::set_meter (int num_i, int den_i, int clocks_i, int count_32_i) { - delete midi_tempo_p_; - midi_tempo_p_ = new Midi_tempo( useconds_per_4_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_time( int num_i, int den_i, int clocks_i, int count_32_i ) +My_midi_parser::set_tempo (int useconds_per_4_i) { - delete midi_time_p_; - midi_time_p_ = new Midi_time( num_i, den_i, clocks_i, count_32_i ); + delete mudela_tempo_p_; + mudela_tempo_p_ = new Mudela_tempo (useconds_per_4_i); } diff --git a/mi2mu/template.cc b/mi2mu/template.cc index e0b9a92513..7de70076c3 100644 --- a/mi2mu/template.cc +++ b/mi2mu/template.cc @@ -8,28 +8,19 @@ #include "list.tcc" #include "cursor.tcc" -L_instantiate(void *); - class istream; class ostream; -#include "mi2mu.hh" +#include "mudela-item.hh" +#include "mudela-column.hh" +#include "mudela-staff.hh" +#include "mudela-voice.hh" #include "plist.hh" #include "plist.tcc" -#ifdef MEVENT_LIST -IPL_instantiate(Midi_event); -#endif - -IPL_instantiate(Midi_track); - -#ifdef MVOICE_LIST -PL_instantiate(Midi_voice); -#endif - -IPL_instantiate(Midi_voice); - -#ifdef TCOL_LIST -IPL_instantiate(Track_column); -#endif +template IPL_INSTANTIATE(Mudela_item); +template IPL_INSTANTIATE(Mudela_staff); +template PL_INSTANTIATE(Mudela_voice); +template IPL_INSTANTIATE(Mudela_voice); +template IPL_INSTANTIATE(Mudela_column); diff --git a/mi2mu/version.cc b/mi2mu/version.cc index 03b78e14eb..1c630664d8 100644 --- a/mi2mu/version.cc +++ b/mi2mu/version.cc @@ -1,4 +1,5 @@ -#include "mi2mu.hh" +#include "proto.hh" +#include "string.hh" const char * mi2mu_version_sz(); @@ -6,8 +7,8 @@ const char * mi2mu_version_sz(); String mi2mu_version_str() { - return String( mi2mu_version_sz()) - + "/" + flower_version_sz() - + " of " + __DATE__ + " " + __TIME__; + return String (mi2mu_version_sz()) + + "/" + flower_version_sz() + + " of " + __DATE__ + " " + __TIME__; }