From: fred Date: Sun, 24 Mar 2002 19:33:48 +0000 (+0000) Subject: lilypond-0.0.37 X-Git-Tag: release/1.5.59~5273 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=0ce4715460b3858d7b4f576e4cf2dcee2a1aced0;p=lilypond.git lilypond-0.0.37 --- diff --git a/Documentation/faq.pod b/Documentation/faq.pod index d54266f053..79e511498e 100644 --- a/Documentation/faq.pod +++ b/Documentation/faq.pod @@ -56,11 +56,14 @@ A: By using g++ LilyPond is portable to all platforms which support g++ (there are quite a few). Not having to support other compilers saves us a *lot* of trouble. LilyPond & FlowerLib uses: -=over 5 +=over 6 =item * builtin bool +=item * +64 bit integral type long long + =item * typeof diff --git a/Sources.make b/Sources.make index 0146217149..a4e776d8f4 100644 --- a/Sources.make +++ b/Sources.make @@ -1,7 +1,9 @@ # Sources.make # sourcefiles to be shipped. Also used for dependencies -hdr=bar.hh barreg.hh beam.hh boxes.hh break.hh clefreg.hh clefitem.hh\ +hdr=bar.hh barreg.hh beam.hh\ + binary-source-file.hh\ + boxes.hh break.hh clefreg.hh clefitem.hh\ colhpos.hh commandrequest.hh \ complexwalker.hh complexstaff.hh\ const.hh debug.hh dimen.hh directionalspanner.hh\ @@ -86,20 +88,30 @@ stablecc=request.cc bar.cc boxes.cc break.cc \ # m2m headers # mym2mhh=\ - binary-source-file.hh\ + duration.hh\ + lily-stream.hh\ midi-event.hh\ midi-main.hh\ midi-score.hh\ midi-track.hh\ my-midi-lexer.hh\ my-midi-parser.hh\ + track-column.hh\ + +# + +# m2m shared headers +# +mym2msharedhh=\ + binary-source-file.hh\ # - + # m2m source # mym2mcc=\ - binary-source-file.cc\ + duration.cc\ + lily-stream.cc\ midi-event.cc\ midi-main.cc\ midi-score.cc\ @@ -107,15 +119,17 @@ mym2mcc=\ midi-track.cc\ my-midi-lexer.cc\ my-midi-parser.cc\ + track-column.cc\ # # m2m shared source # mym2msharedcc=\ + binary-source-file.cc\ inputfile.cc\ sourcefile.cc\ source.cc\ - # + diff --git a/Variables.make b/Variables.make index 886b6eb256..6a9b2cf738 100644 --- a/Variables.make +++ b/Variables.make @@ -3,7 +3,7 @@ # version info MAJVER=0 MINVER=0 -PATCHLEVEL=36 +PATCHLEVEL=37 diff --git a/configure b/configure index 1c611713a5..fec8a5617d 100755 --- a/configure +++ b/configure @@ -12,7 +12,7 @@ function setversion() { MAKE=${MAKE:-make} PREFIX=${PREFIX:-.} -NEEDFLOWERVER=1.1.2 +NEEDFLOWERVER=1.1.4 echo using PREFIX=$PREFIX echo I need Flower version $NEEDFLOWERVER diff --git a/deps/dummy.dep b/deps/dummy.dep index 8b13789179..e69de29bb2 100644 --- a/deps/dummy.dep +++ b/deps/dummy.dep @@ -1 +0,0 @@ - diff --git a/hdr/lily-stream.hh b/hdr/lily-stream.hh new file mode 100644 index 0000000000..55ae71b6e3 --- /dev/null +++ b/hdr/lily-stream.hh @@ -0,0 +1,27 @@ +// +// lily-stream.hh -- part of LilyPond +// +// copyright 1997 Jan Nieuwenhuizen + +// should i be named Mudela_stream? + +#ifndef LILY_STREAM_HH +#define LILY_STREAM_HH + +/// Lily output +struct Lily_stream { + ostream* os_p_; + String filename_str_; + + Lily_stream( String filename_str ); + ~Lily_stream(); + + Lily_stream& operator <<( String str ); + Lily_stream& operator <<( Midi_event& midi_event_r ); + + void header(); + void open(); +}; + +#endif // LILY_STREAM_HH + diff --git a/hdr/midi-main.hh b/hdr/midi-main.hh index 4eb86c27d2..b58e077d43 100644 --- a/hdr/midi-main.hh +++ b/hdr/midi-main.hh @@ -19,6 +19,9 @@ extern Verbose level_ver; #endif extern Source* source_l_g; +extern bool no_triplets_bo_g; void message( String message_str, char const* context_ch_c_l ); void warning( String message_str, char const* context_ch_c_l ); void error( String message_str, char const* context_ch_c_l ); + +String version_str(); diff --git a/hdr/midi-score.hh b/hdr/midi-score.hh index 2f88168a11..68707633ef 100644 --- a/hdr/midi-score.hh +++ b/hdr/midi-score.hh @@ -14,7 +14,10 @@ public: void add_track( Midi_track* midi_track_p ); + int output_mudela( String filename_str ); + private: + IPointerList midi_track_p_list_; int format_i_; int tracks_i_; int tempo_i_; diff --git a/hdr/midi-track.hh b/hdr/midi-track.hh index ce258c6eae..d1458ed0ca 100644 --- a/hdr/midi-track.hh +++ b/hdr/midi-track.hh @@ -9,12 +9,17 @@ /// (midi_track) class Midi_track { public: - Midi_track(); + Midi_track( int track_i ); ~Midi_track(); - void add_event( Midi_event* midi_event_p ); + void add_event( Moment mom, Midi_event* midi_event_p ); + String name_str(); + void output_mudela( Lily_stream& lily_stream_r ); + Track_column* tcol_l( Moment mom ); private: + IPointerList tcol_p_list_; + String name_str_; }; #endif // MIDI_TRACK_HH diff --git a/hdr/midiitem.hh b/hdr/midiitem.hh index 486637c367..f4b14aa5ef 100644 --- a/hdr/midiitem.hh +++ b/hdr/midiitem.hh @@ -10,7 +10,7 @@ struct Midi_item { /* *************** */ - static String int2varlength_str( int i ); + static String i2varint_str( int i ); virtual void output_midi( Midi_stream& midi_stream_r ); virtual String str() = 0; }; diff --git a/hdr/my-midi-lexer.hh b/hdr/my-midi-lexer.hh index 5245d1be84..032bf6752b 100644 --- a/hdr/my-midi-lexer.hh +++ b/hdr/my-midi-lexer.hh @@ -27,7 +27,7 @@ public: int close_i(); void error( char const* sz_l ); char const* here_ch_c_l(); - static int varint2int_i( String str ); + static int varint2_i( String str ); int yylex(); private: diff --git a/hdr/my-midi-parser.hh b/hdr/my-midi-parser.hh index fd7e088654..d199bc1c4e 100644 --- a/hdr/my-midi-parser.hh +++ b/hdr/my-midi-parser.hh @@ -6,9 +6,8 @@ #ifndef MY_MIDI_PARSER_HH #define MY_MIDI_PARSER_HH -#include "proto.hh" -#include "varray.hh" -#include "string.hh" +// #include "proto.hh" +// #include "string.hh" int yyparse(); @@ -20,25 +19,26 @@ public: void add_score( Midi_score* midi_score_p ); void error( char const* sz_l ); int parse(); - void forward( Real f ); + 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( String filename_str ); - void set_division( int clocks_per_4_i ); + int output_mudela( String filename_str ); + void reset(); + void set_division_4( int division_4_i ); void set_key( int accidentals_i, int minor_i ); void set_tempo( int useconds_i ); void set_time( int num_i, int den_i, int clocks_i, int count_32_i ); private: - Real now_f_; - Real step_f_; + Int64 now_i64_; // 31 bits yields tipically about 1000 bars static int const CHANNELS_i = 16; static int const PITCHES_i = 128; - Real running_f_f_a_[ CHANNELS_i ][ PITCHES_i ]; + Int64 running_i64_i64_a_[ CHANNELS_i ][ PITCHES_i ]; - Array midi_score_p_array_; - int clocks_per_whole_i_; + Midi_score* midi_score_p_; + int division_1_i_; Midi_key* midi_key_p_; Midi_tempo* midi_tempo_p_; Midi_time* midi_time_p_; diff --git a/hdr/proto.hh b/hdr/proto.hh index 0f2a007c79..0ca6d726dd 100644 --- a/hdr/proto.hh +++ b/hdr/proto.hh @@ -10,6 +10,9 @@ #include "fproto.hh" #include "real.hh" +/// (i64) +typedef long long Int64; + struct Absdynamic_req; struct Accidental; struct Atom; @@ -33,6 +36,8 @@ struct Complex_staff; struct Complex_walker; struct Cresc_req; struct Decresc_req; +struct Duration; +struct Duration_iterator; struct Durational_req; struct Dynamic; struct Group_change_req; @@ -50,6 +55,7 @@ struct Key_change_req; struct Key_item; struct Keyword; struct Keyword_table; +struct Lily_stream; struct Line_of_score; struct Line_of_staff; struct Linestaff; @@ -98,6 +104,7 @@ struct Offset; struct Output; struct PCol; struct Plet_req; +struct Plet; struct PScore; struct PStaff; struct Paperdef; @@ -151,6 +158,7 @@ struct Text_register; struct Text_req; struct Timing_req; struct Time_description; +struct Track_column; struct Voice; struct Voice_element; struct Voice_group_registers; diff --git a/hdr/script.hh b/hdr/script.hh index 9c48c75e24..7c089e3a54 100644 --- a/hdr/script.hh +++ b/hdr/script.hh @@ -32,7 +32,7 @@ struct Script : Item { private: void set_symdir(); void set_default_dir(); - void set_default_pos(); + void set_default_index(); Symbol symbol()const; }; diff --git a/hdr/stem.hh b/hdr/stem.hh index ccc02a6b59..2aafd66074 100644 --- a/hdr/stem.hh +++ b/hdr/stem.hh @@ -63,7 +63,7 @@ struct Stem : Item { void add(Notehead*n); const char * name() const; - Real hpos()const; + Real hindex()const; void do_print() const; void set_stemend(Real); int get_default_dir(); diff --git a/hdr/textitem.hh b/hdr/textitem.hh index c7df9069d9..4e0e454941 100644 --- a/hdr/textitem.hh +++ b/hdr/textitem.hh @@ -18,7 +18,7 @@ struct Text_item : Item { /* ***************/ const char * name() const; - virtual void set_default_pos(); + virtual void set_default_index(); Molecule* brew_molecule_p() const; void do_pre_processing(); diff --git a/hdr/track-column.hh b/hdr/track-column.hh new file mode 100644 index 0000000000..1d86755a9f --- /dev/null +++ b/hdr/track-column.hh @@ -0,0 +1,24 @@ +// +// track-column.hh -- declare Track_column +// +// copyright 1997 Jan Nieuwenhuizen + +#ifndef TRACK_COLUMN_HH +#define TRACK_COLUMN_HH + +/// (tcol) +class Track_column { +public: + Track_column( Moment mom ); + ~Track_column(); + + void add_event( Midi_event* midi_event_p ); + Moment mom(); + +//private: + IPointerList midi_event_p_list_; + Moment mom_; +}; + +#endif // TRACK_COLUMN_HH + diff --git a/input/Makefile b/input/Makefile index 92dfaf11c5..47e58f972d 100644 --- a/input/Makefile +++ b/input/Makefile @@ -7,7 +7,8 @@ DISTFILES=Makefile kortjakje.ly maartje.ly\ martien.ly mlalt.ly mlvio1.ly mlvio2.ly mlcello.ly\ coriolan-alto.ly rhythm.ly \ standchen.tex scsii-menuetto.tex scsii-menuetto.ly\ - martien.tex + martien.tex\ + pre1.midi.ly fugue1.midi.ly dist: diff --git a/input/fugue1.midi.ly b/input/fugue1.midi.ly new file mode 100644 index 0000000000..b2c091fc8b --- /dev/null +++ b/input/fugue1.midi.ly @@ -0,0 +1,100 @@ +% Creator: This is m2m 0.0.36-2/FlowerLib 1.1.3-1 of Feb 27 1997 02:41:23 +% Automatically generated, at Thu Feb 27 08:38:27 1997 +% from input file: + +track0 = music { $ + % \Time: 4/8, 96: 8 % \Tempo: 967742: 61 4 per minute + % \Tempo: 1000000: 60 4 per minute + % \Tempo: 1052632: 56 4 per minute + % \Tempo: 1132075: 53 4 per minute + % \Tempo: 1200000: 50 4 per minute + % \Tempo: 1463415: 40 4 per minute + % \Tempo: 1578947: 38 4 per minute + +$} % track0 + +track1 = music { $ + g8 a8 b8 c8. d32 c32 b8 e8 a8 d8. e16 d16 c16 + b16 g16 a16 b16 c16 b16 c16 d16 e16 d16 e16 + fis16 g8 b8 c8 a8 d16 c16 b16 a16 g8. g16 f16 + e16 f16 g16 a16 g16 a16 b16 c2 b4 c8 d8 e8 f8. + g32 f32 e8 a8 d8 g8. a16 g16 f16 e8 a8. b16 a16 + g16 f2 e8. fis16 g2 fis4 g16 f16 e16 d16 c16 + d16 c16 b16 a16 c16 b16 a16 c16 a16 gis8 e8 + d8 c16 b16 a16 gis16 a16 b16 c16 fis16 gis16 + a16 b8 a16 b16 c8 f8 e8 d4 c16 b16 c64 b64 c64 + b64 c64 b64 c64 b64 c64 b32. a32. a4 g8 a8 b8 + c8. d32 c32 b8 c8 d8 e8 f8. g32 f32 e8 a8 d8 g8. + a16 g16 f16 e8 a8 d8 ais8 a8 g16 f16 g16 f16 + g16 e16 f16 g16 g64 a64 g32 f32 g32 a16 cis16 + d16 g16 f64 e64 f64 e64 f64 e16. d32. d8. g8 + a8 b8 c8. d32 c32 b8 e8 a8 d8. e16 d16 c16 b16 + c16 d16 e16 f16 g16 a16 g16 f16 e16 d16 c16 + c64 b64 c64 b8. c8 d8 g8 c4 b8 c4 b8 ais8 a8 d4 + c8 d8 e8 f8.. a32. g32. f32. e32. f32. e32. + d32. c2 g32 a32 b16 c16 d16 e16 f8. c32 d32 + e32 f16 g16 a8. b16 c2 +$} % track1 + +track2 = music { $ + c8 d8 e8 f8. g32 f32 e8 a8 d8 g8. a16 g16 f16 + e16 f16 e16 d16 c16 d16 c16 b16 a8 fis8 g4. + f16 e16 f8 d8 g8 f8 e8 d8 g4 f16 e16 f8.. f16 + e8 d4 c8 f8 g16 f16 e16 f8 d8 g4.. g8 a8 b8 c8. + d32 c32 b8 e8 a8 d8. e16 d16 c16 b16.. d8 e8 + fis8 g8. a32 g32 f8 b8 e8 a8. b16 a16 gis16 + fis8 f8 e8 d8. e16 fis16 gis16 a16 gis16 a16 + b16 gis16 fis16 gis16 a16 b8 c8 d8 e8 f8. g32 + f32 e8 a8 d8 g8. a16 g16 f16 e16. e16. fis16. + g4 fis8 gis8 a4 g8 a8 b8 c8. d32 c32 b16. e8 + a8 d8. e16 d16 c16 b8 g8 cis8 d8 e8 cis8 d8 e8 + a8 e8 fis8 g8 a8. b32 a32 g8 c8 fis8 b8. c16 + b16 a16 g16 fis16 e16 d16 e4 d4. a16 g16 f16 + e16 g16 f16 g4. a16 a16 ais8 c4 d8 g8 g4. f4 + e8 d4 e16. a4 g4 f8 g8 a8 ais8. c32 ais32 a8 + d8 g8 c8. d16 c16 ais16 a16 ais16 a16 g16 f16 + g16 f16 e16 g16 a4 f16 d8 e2 +$} % track2 + +track3 = music { $ + g8 a8 b8 c8. d32 c32 b8 e8 a8 d8. e16 d16 c16 + b8 c4 ais8 a8 d8 g8 c8 a16 b16 c16 d4 g4 g8 a8 + b8 c8. d32 c32 b8 e8 a8 d8. e16 d16 c16 b8 e4. + d4 b16 c16 a16 e16 d16 c16 b16 c16 a16 b16 c16 + d16 c16 b16 a16 g4 e8 fis8 gis8 a8. b32 a32 + g8 c8 fis8 b8. c16 b16 a16 gis16.. a4 gis8 + a4 g8 a8 b8 c8. d32 c32 b8 e8 a8 d4 g8 d4 c8 a8 + e4 d8 a8 b8 cis8 d8. e32 d32 c8 f8 b8 e8. f16 + e16 d16 cis8 a8 b8 cis8 d8. e32 d32 c8 fis8 + b8 e8. fis16 e16 d16 c4.. d16 c16 b16 a16 g16 + a16 fis16 g16.. b16.. c16.. d8 e8. f32 e32 + d8 g8 c8 f8. g16 f16 e16 d4 e8 d4 g8 g4. c8 d8 + e8 f8. g32 f32 e8 a8 d8 g8. a16 g16 f16 e16 d16 + e16 f16 g16 a16 ais16 g16 a16 e16 f16 g16 a16 + b16 c16 a16 c1 +$} % track3 + +track4 = music { $ + c8 d8 e8 f8. g32 f32 e8 a8 d8 g8. a16 g16 f16 + e16 f16 e16 d16 c16 d16 c16 b16 a8 d8 a8 fis8 + g16 a16 ais16 g16 cis8 d8 a4 e4 a16 b16 c16 + d16 c16 b16 a16 g16 c8 g8 a8 b8 c8. d32 c32 b8 + e8 a8 d8. e16 d16 c16 b8 e4 d8 c8 f4 e4 d4 e8 f8 + e16 d16 e4 a4 g8 a8 b8 c8. d32 c32 b8 e8 a8 d8. + e16 d16 c16 b8 ais8 a8 g8 a8 fis8 g8 e8 d4 e8 + f8 g8. a32 g32 f8 ais8 e8 a8. b16. a16 g16 f16 + e16 f16 d16 g8 a8 d4.. e16 d16 c16 b16 a16 g16 + fis16 e8 e8 fis8 g4 a16 g16 fis8 d8 g1 a4 b8 + c8 f16 a16 g16 f16 e16 d16 c16 b16 c16 d16 e16 + f16 g8 g8 b2 c8 +$} % track4 + +score { + staff { melodic music { track0 } } + staff { melodic music { track1 } } + staff { melodic music { track2 } } + staff { melodic music { track3 } } + staff { melodic music { track4 } } + commands { meter { 4*4 } } + midi { tempo 4:60 } +} diff --git a/input/pre1.midi.ly b/input/pre1.midi.ly new file mode 100644 index 0000000000..ca6beafb22 --- /dev/null +++ b/input/pre1.midi.ly @@ -0,0 +1,80 @@ +% Creator: This is m2m 0.0.36-2/FlowerLib 1.1.3-1 of Feb 27 1997 02:41:23 +% Automatically generated, at Thu Feb 27 02:54:33 1997 +% from input file: + +track0 = music { $ + % \Time: 4/8, 96: 8 % \Tempo: 857143: 69 4 per minute + % \Tempo: 882353: 67 4 per minute + % \Tempo: 909091: 65 4 per minute + % \Tempo: 937500: 64 4 per minute + % \Tempo: 967742: 61 4 per minute + % \Tempo: 1000000: 60 4 per minute + % \Tempo: 1200000: 50 4 per minute + % \Tempo: 1224490: 48 4 per minute + % \Tempo: 833333: 72 4 per minute + +$} % track0 + +track1 = music { $ + g16 c16 e16 g16 c16 e16 g16 c16 e16 g16 c16 + e16 a16 d16 f16 a16 d16 f16 a16 d16 f16 a16 + d16 f16 g16 d16 f16 g16 d16 f16 g16 d16 f16 + g16 d16 f16 g16 c16 e16 g16 c16 e16 g16 c16 + e16 g16 c16 e16 a16 e16 a16 a16 e16 a16 a16 + e16 a16 a16 e16 a16 fis16 a16 d16 fis16 a16 + d16 fis16 a16 d16 fis16 a16 d16 g16 d16 g16 + g16 d16 g16 g16 d16 g16 g16 d16 g16 e16 g16 + c16 e16 g16 c16 e16 g16 c16 e16 g16 c16 e16 + g16 c16 e16 g16 c16 e16 g16 c16 e16 g16 c16 + d16 fis16 c16 d16 fis16 c16 d16 fis16 c16 + d16 fis16 c16 d16 g16 b16 d16 g16 b16 d16 g16 + b16 d16 g16 b16 e16 g16 cis16 e16 g16 cis16 + e16 g16 cis16 e16 g16 cis16 d16 a16 d16 d16 + a16 d16 d16 a16 d16 d16 a16 d16 d16 f16 b16 + d16 f16 b16 d16 f16 b16 d16 f16 b16 c16 g16 + c16 c16 g16 c16 c16 g16 c16 c16 g16 c16 a16 + c16 f16 a16 c16 f16 a16 c16 f16 a16 c16 f16 + a16 c16 f16 a16 c16 f16 a16 c16 f16 a16 c16 + f16 g16 b16 f16 g16 b16 f16 g16 b16 f16 g16 + b16 f16 g16 c16 e16 g16 c16 e16 g16 c16 e16 + g16 c16 e16 ais16 c16 e16 ais16 c16 e16 ais16 + c16 e16 ais16 c16 e16 a16 c16 e16 a16 c16 e16 + a16 c16 e16 a16 c16 e16 a16 c16 dis16 a16 c16 + dis16 a16 c16 dis16 a16 c16 dis16 b16 c16 + d16 b16 c16 d16 b16 c16 d16 b16 c16 d16 g16 + b16 d16 g16 b16 d16 g16 b16 d16 g16 b16 d16 + g16 c16 e16 g16 c16 e16 g16 c16 e16 g16 c16 + e16 g16 c16 f16 g16 c16 f16 g16 c16 f16 g16 + c16 f16 g16 b16 f16 g16 b16 f16 g16 b16 f16 + g16 b16 f16 a16 c16 fis16 a16 c16 fis16 a16 + c16 fis16 a16 c16 fis16 g16 c16 g16 g16 c16 + g16 g16 c16 g16 g16 c16 g16 g16 c16 f16 g16 + c16 f16 g16 c16 f16 g16 c16 f16 g16 b16 f16 + g16 b16 f16 g16 b16 f16 g16 b16 f16 g16 ais16 + e16 g16 ais16 e16 g16 ais16 e16 g16 ais16 + e16 f16 a16 c16 f16 c16 a16 c16 a16 f16 a16 + f16 d16 f16 d16 g16 b16 d16 f16 d16 b16 d16 + b16 g16 b16 d16 f16 e64 f64 e32 d16 c1 +$} % track1 + +track2 = music { $ + c2 e4. c2 e4. c2 d4. c2 d4. b2 d4. b2 d4. c2 e4. + c2 e4. c2 e4. c2 e4. c2 d4. c2 d4. b2 d4. b2 d4. + b2 c4. b2 c4. a2 c4. a2 c4. d2 a4. d2 a4. g2 b4. + g2 b4. g2 ais4. g2 ais4. f2 a4. f2 a4. f2 gis4. + f2 gis4. e2 g4. e2 g4. e2 f4. e2 f4. d2 f4. d2 + f4. g2 d4. g2 d4. c2 e4. c2 e4. c2 g4. c2 g4. + f2 f4. f2 f4. fis2 c2 fis2 c4. gis2 f4. gis2 + f4. g2 f4. g2 f4. g2 e2 g2 e4. g2 d4. g2 d2 g2 + d4. g2 d4. g2 dis4. g2 dis4. g2 e4. g2 e4. g2 + d4. g2 d4. g2 d4. g2 d4. c2 c4. c2 c4. c1 c1 b1 + c1 c1 +$} % track2 + +score { + staff { melodic music { track0 } } + staff { melodic music { track1 } } + staff { melodic music { track2 } } + commands { meter { 4*4 } } + midi { tempo 4:60 } +} diff --git a/src/beam.cc b/src/beam.cc index 1b0fa2baa3..f554d424bc 100644 --- a/src/beam.cc +++ b/src/beam.cc @@ -28,7 +28,7 @@ struct Stem_info { Stem_info::Stem_info(const Stem*s) { - x = s->hpos(); + x = s->hindex(); int dir = s->dir; idealy = max(dir*s->top, dir*s->bot); miny = max(dir*s->minnote, dir*s-> maxnote); @@ -119,9 +119,9 @@ void Beam::set_stemlens() { iter_top(stems,s); - Real x0 = s->hpos(); + Real x0 = s->hindex(); for (; s.ok() ; s++) { - Real x = s->hpos()-x0; + Real x = s->hindex()-x0; s->set_stemend(left_pos + slope * x); } } @@ -192,8 +192,8 @@ Interval Beam::width() const { Beam * me = (Beam*) this; // ugh - return Interval( (*me->stems.top()) ->hpos(), - (*me->stems.bottom()) ->hpos() ); + return Interval( (*me->stems.top()) ->hindex(), + (*me->stems.bottom()) ->hindex() ); } /* @@ -202,8 +202,8 @@ Beam::width() const Molecule Beam::stem_beams(Stem *here, Stem *next, Stem *prev)const { - assert( !next || next->hpos() > here->hpos() ); - assert( !prev || prev->hpos() < here->hpos() ); + assert( !next || next->hindex() > here->hindex() ); + assert( !prev || prev->hindex() < here->hindex() ); Real dy=paper()->internote()*2; Real stemdx = paper()->rule_thickness(); Real sl = slope*paper()->internote(); @@ -216,7 +216,7 @@ Beam::stem_beams(Stem *here, Stem *next, Stem *prev)const if (prev) { int lhalfs= lhalfs = here->beams_left - prev->beams_right ; int lwholebeams= here->beams_left beams_right ; - Real w = (here->hpos() - prev->hpos())/4; + Real w = (here->hindex() - prev->hindex())/4; Symbol dummy; Atom a(dummy); if (lhalfs) // generates warnings if not @@ -233,7 +233,7 @@ Beam::stem_beams(Stem *here, Stem *next, Stem *prev)const int rhalfs = here->beams_right - next->beams_left; int rwholebeams = here->beams_right beams_left; - Real w = next->hpos() - here->hpos(); + Real w = next->hindex() - here->hindex(); Atom a = paper()->lookup_p_->beam(sl, w + stemdx); int j = 0; @@ -264,7 +264,7 @@ Beam::brew_molecule_p() const return out; { Real inter=paper()->internote(); out = new Molecule; - Real x0 = stems.top()->hpos(); + Real x0 = stems.top()->hindex(); for (iter_top(stems,i); i.ok(); i++) { PCursor p(i-1); @@ -273,7 +273,7 @@ Beam::brew_molecule_p() const return out; Stem * next = n.ok() ? n.ptr() : 0; Molecule sb = stem_beams(i, next, prev); - Real x = i->hpos()-x0; + Real x = i->hindex()-x0; sb.translate(Offset(x, (x * slope + left_pos)* inter)); out->add(sb); } diff --git a/src/binary-source-file.cc b/src/binary-source-file.cc index 8335a13a5e..8545f221e9 100644 --- a/src/binary-source-file.cc +++ b/src/binary-source-file.cc @@ -32,13 +32,13 @@ Binary_source_file::error_str( char const* pos_ch_c_l ) char const* end_ch_c_l = pos_ch_c_l + 7 0 && (isspace(s[i]) || isalpha(s[i])) ){ i--; } String unit(s + i+1); - return convert_dimen(dim.fvalue(), unit); + return convert_dimen(dim.value_f(), unit); } diff --git a/src/duration.cc b/src/duration.cc new file mode 100644 index 0000000000..6a251235ea --- /dev/null +++ b/src/duration.cc @@ -0,0 +1,249 @@ +// +// duration.cc -- implement Duration, Plet, Duration_convert, Duration_iterator +// +// copyright 1997 Jan Nieuwenhuizen + +// split into 4? + +#include "proto.hh" // ugh, these all for midi-main.hh +#include "plist.hh" +#include "string.hh" +#include "sourcefile.hh" +#include "source.hh" +#include "midi-main.hh" // *tors + +#include "string.hh" +#include "moment.hh" +#include "duration.hh" + +Duration::Duration( int type_i, int dots_i = 0, Plet* plet_l ) +{ + type_i_ = type_i; + dots_i_ = dots_i; + plet_p_ = 0; + set_plet( plet_l ); +} + +Duration::Duration( Duration const& dur_c_r ) +{ + type_i_ = 0; + dots_i_ = 0; + plet_p_ = 0; + *this = dur_c_r; +} + +Duration::~Duration() +{ + delete plet_p_; +} + +Duration const& +Duration::operator =( Duration const& dur_c_r ) +{ + if ( &dur_c_r == this ) + return *this; + + type_i_ = dur_c_r.type_i_; + dots_i_ = dur_c_r.dots_i_; + set_plet( dur_c_r.plet_p_ ); + + return *this; +} + +void +Duration::set_plet( Plet* plet_l ) +{ + delete plet_p_; + plet_p_ = 0; + if ( plet_l ) + plet_p_ = new Plet( *plet_l ); +} + +Plet::Plet( int iso_i, int type_i ) +{ + iso_i_ = iso_i; + type_i_ = type_i; +} + +Plet::Plet( Plet const& plet_c_r ) +{ + iso_i_ = plet_c_r.iso_i_; + type_i_ = plet_c_r.type_i_; +} + +String +Duration_convert::dur2_str( Duration dur ) +{ + String str( dur.type_i_ ); + str += String( '.', dur.dots_i_ ); + if ( dur.plet_p_ ) + str += String( "*" ) + String( dur.plet_p_->iso_i_ ) + + String( "/" ) + String( dur.plet_p_->type_i_ ); + return str; +} + +int +Duration_convert::dur2_i( Duration dur, int division_1_i ) +{ + return dur2_mom( dur ) * Moment( division_1_i ); +} + +Moment +Duration_convert::dur2_mom( Duration dur ) +{ + if ( !dur.type_i_ ) + return 0; + + Moment mom = Moment( 1 , dur.type_i_ ); + + Moment delta = mom; + while ( dur.dots_i_-- ) { + delta /= 2.0; + mom += delta; + } + + return mom * plet_factor_mom( dur ); +} + +Duration +Duration_convert::mom2_dur( Moment mom ) +{ + /* this is cute, + but filling an array using Duration_iterator + might speed things up, a little + */ + Duration_iterator iter_dur; + assert( iter_dur ); + while ( iter_dur ) { + Duration lower_dur = iter_dur++; + Duration upper_dur( 0 ); + if ( iter_dur ) + upper_dur = iter_dur(); + Moment lower_mom = dur2_mom( lower_dur ); + Moment upper_mom = dur2_mom( upper_dur ); + if ( mom == lower_mom ) + return lower_dur; + if ( mom == upper_mom ) // don-t miss last (sic) + return upper_dur; + if ( ( mom >= lower_mom ) && ( mom <= upper_mom ) ) { + warning( String( "duration not exact: " ) + String( (Real)mom ) , 0 ); + if ( abs( mom - lower_mom ) < abs( mom - upper_mom ) ) + return lower_dur; + else + return upper_dur; + } + lower_dur = upper_dur; + } + return Duration( 0 ); +} + +Moment +Duration_convert::plet_factor_mom( Duration dur ) +{ + if ( !dur.plet_p_ ) + return 1; + return Moment( dur.plet_p_->iso_i_, dur.plet_p_->type_i_ ); +} + +Real +Duration_convert::sync_f( Duration dur, Moment mom ) +{ + return mom / dur2_mom( dur ); +} + +Moment +Duration_convert::i2_mom( int time_i, int division_1_i ) +{ + if ( !time_i ) + return Moment( 0 ); + + if ( division_1_i > 0 ) + return Moment( time_i, division_1_i ); + else + return Moment( -division_1_i, time_i ); +} + +Duration_iterator::Duration_iterator() +{ + cursor_dur_.type_i_ = 128; + cursor_dur_.set_plet( 0 ); +} + +Duration +Duration_iterator::operator ++(int) +{ + return forward_dur(); +} + +Duration +Duration_iterator::operator ()() +{ + return dur(); +} + +Duration_iterator::operator bool() +{ + return ok(); +} + +Duration +Duration_iterator::dur() +{ + return cursor_dur_; +} + +Duration +Duration_iterator::forward_dur() +{ + // should do smart table? guessing: + // duration wholes + // 16 0.0625 + // 32.. 0.0703 + // 8:2/3 0.0833 + // 16. 0.0938 + // 8 0.1250 + // 16.. 0.1406 + // 4:2/3 0.1667 + // 8. 0.1875 + + assert( ok() ); + + Duration dur = cursor_dur_; + + if ( !cursor_dur_.dots_i_ && !cursor_dur_.plet_p_ ) { + cursor_dur_.type_i_ *= 2; + cursor_dur_.dots_i_ = 2; + } + else if ( cursor_dur_.dots_i_ == 2 ) { + assert( !cursor_dur_.plet_p_ ); + cursor_dur_.dots_i_ = 0; + cursor_dur_.type_i_ /= 4; + cursor_dur_.set_plet( &Plet( 2, 3 ) ); + } + else if ( cursor_dur_.plet_p_ + && ( cursor_dur_.plet_p_->iso_i_ == 2 ) + && ( cursor_dur_.plet_p_->type_i_ == 3 ) ) { + assert( !cursor_dur_.dots_i_ ); + cursor_dur_.set_plet( 0 ); + cursor_dur_.type_i_ *= 2; + cursor_dur_.dots_i_ = 1; + } + else if ( cursor_dur_.dots_i_ == 1 ) { + assert( !cursor_dur_.plet_p_ ); + cursor_dur_.dots_i_ = 0; + cursor_dur_.type_i_ /= 2; + } + + // ugh + if ( no_triplets_bo_g && cursor_dur_.plet_p_ && ok() ) + forward_dur(); + + return dur; +} + +bool +Duration_iterator::ok() +{ + return ( cursor_dur_.type_i_ + && !( ( cursor_dur_.type_i_ == 1 ) && ( cursor_dur_.dots_i_ > 2 ) ) ); +} diff --git a/src/inputfile.cc b/src/inputfile.cc index 2245c8dbe0..9e1a496834 100644 --- a/src/inputfile.cc +++ b/src/inputfile.cc @@ -29,7 +29,7 @@ Input_file::Input_file(String s) else { Source_file* sourcefile_p = 0; // ugh, very dirty, need to go away - if ( ( pf.right( 3 ).lower() == "mid" ) || ( pf.right( 4 ).lower() == "midi" ) ) + if ( ( pf.right_str( 3 ).lower_str() == "mid" ) || ( pf.right_str( 4 ).lower_str() == "midi" ) ) sourcefile_p = new Binary_source_file( pf ); else sourcefile_p = new Source_file( pf ); diff --git a/src/lexer.l b/src/lexer.l index 1e4e8488a5..6f72f7f2cc 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -106,7 +106,7 @@ COMMENT [%#].*\n return DOTS; } {INT} { - yylval.i = String(YYText()).value(); + yylval.i = String_convert::dec2_i( String( YYText() ) ); return INT; } {COMMENT} { @@ -119,7 +119,7 @@ COMMENT [%#].*\n } \"[^"]*\" { String s (YYText()+1); - s = s.left(s.len()-1); + s = s.left_str(s.length_i()-1); yylval.string = new String(s); return STRING; } @@ -144,7 +144,7 @@ COMMENT [%#].*\n return DOTS; } {INT} { - yylval.i = String(YYText()).value(); + yylval.i = String_convert::dec2_i( String( YYText() ) ); return INT; } {NOTECOMMAND} { @@ -172,19 +172,19 @@ COMMENT [%#].*\n } \"[^"]*\" { String s (YYText()+1); - s = s.left(s.len()-1); + s = s.left_str(s.length_i()-1); yylval.string = new String(s); return STRING; } {LYRICS} { String s (YYText()); int i = 0; - while ((i=s.pos("_")) != 0) // change word binding "_" to " " - *(s.ch_l() + i - 1) = ' '; - if ((i=s.pos("\\,")) !=0) // change "\," to TeX's "\c " + while ((i=s.index_i("_")) != -1) // change word binding "_" to " " + *(s.ch_l() + i) = ' '; + if ((i=s.index_i("\\,")) != -1) // change "\," to TeX's "\c " { - *(s.ch_l() + i) = 'c'; - s = s.left(i+1) + " " + s.right(s.len()-i-1); + *(s.ch_l() + i + 1) = 'c'; + s = s.left_str(i+2) + " " + s.right_str(s.length_i()-i-2); } yylval.string = new String(s); return STRING; @@ -221,8 +221,8 @@ include { [ \t]* { /* eat the whitespace */ } \"[^"]*\"+ { /* got the include file name */ String s (YYText()+1); - s = s.left(s.len()-1); - defined_ch_c_l = here_ch_c_l() - String( YYText() ).len() - 1; + s = s.left_str(s.length_i()-1); + defined_ch_c_l = here_ch_c_l() - String( YYText() ).length_i() - 1; new_input(s); yy_pop_state(); } diff --git a/src/lily-stream.cc b/src/lily-stream.cc new file mode 100644 index 0000000000..2a4d4a4417 --- /dev/null +++ b/src/lily-stream.cc @@ -0,0 +1,72 @@ +// +// lily-stream.cc +// +// source file of the LilyPond music typesetter +// +// (c) 1997 Jan Nieuwenhuizen + +// should i be named Mudela_stream? + +#include +#include + +#include "proto.hh" +#include "plist.hh" +#include "string.hh" + +#include "moment.hh" +#include "sourcefile.hh" +#include "source.hh" +#include "midi-main.hh" // *tors + +#include "duration.hh" +#include "midi-event.hh" +#include "lily-stream.hh" + +Lily_stream::Lily_stream( String filename_str ) +{ + filename_str_ = filename_str; + os_p_ = 0; + open(); + header(); +} + +Lily_stream::~Lily_stream() +{ + delete os_p_; +} + +Lily_stream& +Lily_stream::operator <<( String str ) +{ + *os_p_ << str; + return *this; +} + +Lily_stream& +Lily_stream::operator <<( Midi_event& midi_event_r ) +{ + midi_event_r.output_mudela( *this ); + return *this; +} + +void +Lily_stream::header() +{ + *os_p_ << "% Creator: " << 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-> + *os_p_ << "\n\n"; +} + +void +Lily_stream::open() +{ + os_p_ = new ofstream( filename_str_ ); + if ( !*os_p_ ) + error ( "can't open `" + filename_str_ + "\'", 0 ); +} + diff --git a/src/lyricitem.cc b/src/lyricitem.cc index 30f49e5bf4..b35c866761 100644 --- a/src/lyricitem.cc +++ b/src/lyricitem.cc @@ -23,6 +23,6 @@ Lyric_item::do_pre_processing() // override Text_item // test context-error - if ( tdef_l_->text_str_.pos( "Gates" ) )// :-) + if ( tdef_l_->text_str_.index_i( "Gates" ) )// :-) warning( "foul word", tdef_l_->defined_ch_c_l_ ); } diff --git a/src/main.cc b/src/main.cc index 55a5129055..450545ab25 100644 --- a/src/main.cc +++ b/src/main.cc @@ -18,7 +18,7 @@ extern void parse_file(String,String); void -destill_inname( String &inName); +destill_inname( String &name_str_r); long_option_init theopts[] = { 1, "output", 'o', 0, "warranty", 'w', @@ -147,20 +147,20 @@ find_file(String f) /// make input file name: add default extension. "" is stdin. void -destill_inname( String &inName) +destill_inname( String &name_str_r) { - if ( inName.len() ) + if ( name_str_r.length_i() ) { - if( inName[ 0 ] != '-' ) + if( name_str_r[ 0 ] != '-' ) { String a,b,c,d; - split_path(inName,a,b,c,d); + split_path(name_str_r,a,b,c,d); // add extension if not present. if (d == "") d = ".ly"; - inName = a+b+c+d; + name_str_r = a+b+c+d; } - } else inName = ""; + } else name_str_r = ""; } diff --git a/src/midi-lexer.l b/src/midi-lexer.l index dfbafd5fbf..49f74ead0e 100644 --- a/src/midi-lexer.l +++ b/src/midi-lexer.l @@ -89,14 +89,14 @@ SSME [\0x7f][\x03] } {INT8} { error( String( "top level: illegal byte: " ) - + StringConversion::bin2hex_str( String( *YYText() ) ) ); + + String_convert::bin2hex_str( String( *YYText() ) ) ); exit( 1 ); } {INT32} { dtor << "lex: int32" << endl; assert( YYLeng() == 4 ); String str( (Byte const*)YYText(), YYLeng() ); - yylval.i = StringConversion::bin2int_i( str ); + yylval.i = String_convert::bin2_i( str ); yy_pop_state(); return INT32; } @@ -104,7 +104,7 @@ SSME [\0x7f][\x03] dtor << "lex: int16" << endl; assert( YYLeng() == 2 ); String str( (Byte const*)YYText(), YYLeng() ); - yylval.i = StringConversion::bin2int_i( str ); + yylval.i = String_convert::bin2_i( str ); yy_pop_state(); return INT16; } @@ -119,16 +119,16 @@ SSME [\0x7f][\x03] {VARINT} { String str( (Byte const*)YYText(), YYLeng() ); - yylval.i = My_midi_lexer::varint2int_i( str ); + yylval.i = My_midi_lexer::varint2_i( str ); dtor << String( "lex: track: varint(" ) + String( yylval.i ) + "): " - + StringConversion::bin2hex_str( str ) << endl; + + String_convert::bin2hex_str( str ) << endl; yy_push_state( event ); return VARINT; } {INT8} { error( String( "track: illegal byte: " ) - + StringConversion::bin2hex_str( String( *YYText() ) ) ); + + String_convert::bin2hex_str( String( *YYText() ) ) ); exit( 1 ); } {RUNNING_STATUS} { @@ -240,7 +240,7 @@ SSME [\0x7f][\x03] } {INT8} { error( String( "event: illegal byte: " ) - + StringConversion::bin2hex_str( String( *YYText() ) ) ); + + String_convert::bin2hex_str( String( *YYText() ) ) ); exit( 1 ); } {SEQUENCE} { // ssss sequence number @@ -353,7 +353,7 @@ SSME [\0x7f][\x03] } {INT8} { warning( String( "meta_event: unimplemented event: " ) - + StringConversion::bin2hex_str( String( *YYText() ) ), + + String_convert::bin2hex_str( String( *YYText() ) ), *this->here_ch_c_l() ); yy_pop_state(); yy_pop_state(); @@ -365,7 +365,7 @@ SSME [\0x7f][\x03] {VARINT} { dtor << "lex: data" << endl; String str( (Byte const*)YYText(), YYLeng() ); - int i = My_midi_lexer::varint2int_i( str ); + int i = My_midi_lexer::varint2_i( str ); String* str_p = new String; while ( i-- ) *str_p += (char)yyinput(); @@ -375,7 +375,7 @@ SSME [\0x7f][\x03] } {INT8} { error( String( "data: illegal byte: " ) - + StringConversion::bin2hex_str( String( *YYText() ) ) ); + + String_convert::bin2hex_str( String( *YYText() ) ) ); exit( 1 ); } diff --git a/src/midi-main.cc b/src/midi-main.cc index 5b6ecb3e2d..5dfdf64662 100644 --- a/src/midi-main.cc +++ b/src/midi-main.cc @@ -5,6 +5,7 @@ // copyright 1997 Jan Nieuwenhuizen #include +#include #include "proto.hh" #include "plist.hh" #include "version.hh" @@ -15,6 +16,7 @@ #include "sourcefile.hh" #include "midi-main.hh" #include "moment.hh" +#include "duration.hh" #include "midi-event.hh" #include "midi-track.hh" #include "my-midi-lexer.hh" @@ -25,6 +27,9 @@ Source* source_l_g = &source; Verbose level_ver = NORMAL_ver; +// ugh +bool no_triplets_bo_g = false; + //ugh char const* defined_ch_c_l = 0; @@ -76,9 +81,10 @@ help() { btor << "--debug, -d be really verbose\n" - "--help, -h This help\n" - "--include, -I add to file search path.\n" - "--output, -o set default output\n" + "--help, -h this help\n" + "--include=DIR, -I DIR add DIR to search path\n" + "--no-triplets, -n assume no triplets\n" + "--output=FILE, -o FILE set FILE as default output\n" "--quiet, -q be quiet\n" "--verbose, -v be verbose\n" "--warranty, -w show warranty & copyright\n" @@ -88,8 +94,7 @@ help() void identify() { - mtor << "This is m2m " << VERSIONSTR << "/FlowerLib " << FVERSIONSTR - << " of " << __DATE__ << " " << __TIME__ << endl; + mtor << version_str() << endl; } void @@ -119,6 +124,15 @@ notice() "USA.\n"; } +// should simply have Root class... +String +version_str() +{ + return String ( "This is m2m " ) + VERSIONSTR + + "/FlowerLib " + FVERSIONSTR + + " of " + __DATE__ + " " + __TIME__; +} + int main( int argc_i, char* argv_sz_a[] ) { @@ -126,6 +140,7 @@ main( int argc_i, char* argv_sz_a[] ) 0, "debug", 'd', 0, "help", 'h', // 1, "include", 'I', + 0, "no-triplets", 'n', 1, "output", 'o', 0, "quiet", 'q', 0, "verbose", 'v', @@ -148,6 +163,9 @@ main( int argc_i, char* argv_sz_a[] ) // case 'I': // path->push( getopt_long.optarg ); // break; + case 'n': + no_triplets_bo_g = true; + break; case 'o': output_str = getopt_long.optarg; break; @@ -172,7 +190,14 @@ main( int argc_i, char* argv_sz_a[] ) int error_i = midi_parser.parse(); if ( error_i ) return error_i; - error_i = midi_parser.output( output_str ); + if ( !output_str.length_i() ) { + output_str = String( arg_sz ) + ".ly"; + // i-m sure there-s already some routine for this + int name_i; // too bad we can-t declare local to if + if ( ( name_i = output_str.index_last_i( '/' ) ) != -1 ) + output_str = output_str.mid_str( name_i + 1, INT_MAX ); + } + error_i = midi_parser.output_mudela( output_str ); if ( error_i ) return error_i; } diff --git a/src/midi-parser.y b/src/midi-parser.y index 56680f4b77..466b5c58d5 100644 --- a/src/midi-parser.y +++ b/src/midi-parser.y @@ -12,6 +12,7 @@ #include "my-midi-lexer.hh" #include "my-midi-parser.hh" #include "moment.hh" +#include "duration.hh" #include "midi-event.hh" #include "midi-track.hh" #include "midi-score.hh" @@ -20,6 +21,9 @@ #define YYDEBUG 1 #endif +//ugh +static track_i = 0; + %} %union { @@ -61,6 +65,7 @@ midi: /* empty */ | midi midi_score { midi_parser_l_g->add_score( $2 ); + track_i = 0; } ; @@ -69,34 +74,31 @@ midi_score: } | midi_score track { $$->add_track( $2 ); + midi_parser_l_g->reset(); } ; header: HEADER INT32 INT16 INT16 INT16 { $$ = new Midi_score( $3, $4, $5 ); - midi_parser_l_g->set_division( $5 ); + midi_parser_l_g->set_division_4( $5 ); } ; track: TRACK INT32 { - $$ = new Midi_track; + $$ = new Midi_track( track_i++ ); } | track event { - $$->add_event( $2 ); + $$->add_event( midi_parser_l_g->mom(), $2 ); } ; event: varint the_event { - if ( $2 && $2->mudela_str().length_i() ) { - if ( ( $2->mudela_str()[ 0 ] >= 'a' ) - && $2->mudela_str()[ 0 ] <= 'g' ) - qtor << $2->mudela_str() << " "; - else - vtor << $2->mudela_str() << " "; - } + $$ = $2; + if ( $2 && $2->mudela_str().length_i() ) + dtor << $2->mudela_str() << " " << flush; } ; @@ -130,7 +132,7 @@ the_meta_event: } | text_event DATA { $$ = 0; - vtor << *$2 << endl; + dtor << *$2 << endl; delete $2; } | END_OF_TRACK { @@ -138,7 +140,7 @@ the_meta_event: } | TEMPO INT8 INT8 INT8 { $$ = new Midi_tempo( ( $2 << 16 ) + ( $3 << 8 ) + $4 ); - vtor << $$->mudela_str() << endl; // ?? waai not at event: + dtor << $$->mudela_str() << endl; // ?? waai not at event: midi_parser_l_g->set_tempo( ( $2 << 16 ) + ( $3 << 8 ) + $4 ); } | SMPTE_OFFSET INT8 INT8 INT8 INT8 INT8 { @@ -146,7 +148,7 @@ the_meta_event: } | TIME INT8 INT8 INT8 INT8 { $$ = new Midi_time( $2, $3, $4, $5 ); - vtor << $$->mudela_str() << endl; // ?? waai not at event: + dtor << $$->mudela_str() << endl; // ?? waai not at event: midi_parser_l_g->set_time( $2, $3, $4, $5 ); } | KEY INT8 INT8 { @@ -161,25 +163,25 @@ the_meta_event: text_event: TEXT { - vtor << endl << "Text: "; + dtor << "\n% Text: "; } | COPYRIGHT { - vtor << endl << "Copyright: "; + dtor << "\n% Copyright: "; } | TRACK_NAME { - vtor << endl << "Track name: "; + dtor << "\n% Track name: "; } | INSTRUMENT_NAME { - vtor << endl << "Instrument name: "; + dtor << "\n% Instrument name: "; } | LYRIC { - vtor << endl << "Lyric: "; + dtor << "\n% Lyric: "; } | MARKER { - vtor << endl << "Marker: "; + dtor << "\n% Marker: "; } | CUE_POINT { - vtor << endl << "Cue point: "; + dtor << "\n% Cue point: "; } ; diff --git a/src/midi-score.cc b/src/midi-score.cc index 02a79a542d..f24f9093d1 100644 --- a/src/midi-score.cc +++ b/src/midi-score.cc @@ -4,6 +4,16 @@ // copyright 1997 Jan Nieuwenhuizen #include "proto.hh" +#include "plist.hh" +#include "string.hh" +#include "moment.hh" +#include "duration.hh" +#include "sourcefile.hh" +#include "source.hh" +#include "midi-main.hh" // *tors +#include "midi-event.hh" +#include "lily-stream.hh" +#include "track-column.hh" #include "midi-track.hh" #include "midi-score.hh" @@ -21,4 +31,33 @@ Midi_score::~Midi_score() void Midi_score::add_track( Midi_track* midi_track_p ) { + midi_track_p_list_.bottom().add( midi_track_p ); } + +int +Midi_score::output_mudela( String filename_str ) +{ + mtor << "Lily output to " << filename_str << " ..." << endl; + + Lily_stream lily_stream( filename_str ); + for ( PCursor midi_track_l_pcur( midi_track_p_list_.top() ); midi_track_l_pcur.ok(); midi_track_l_pcur++ ) { + midi_track_l_pcur->output_mudela( lily_stream ); + lily_stream << "\n"; + } + + lily_stream << "score {\n"; + + for ( PCursor midi_track_l_pcur( midi_track_p_list_.top() ); midi_track_l_pcur.ok(); midi_track_l_pcur++ ) { + lily_stream << "\tstaff { melodic music { "; + lily_stream << midi_track_l_pcur->name_str(); + lily_stream << " } }\n"; + } + + lily_stream << "\tcommands { meter { 4*4 } }\n"; + lily_stream << "\tmidi { tempo 4:60 }\n"; + + lily_stream << "}\n"; + + return 0; +} + diff --git a/src/midi-template.cc b/src/midi-template.cc index 02315c320b..c4caa838b4 100644 --- a/src/midi-template.cc +++ b/src/midi-template.cc @@ -16,4 +16,14 @@ class ostream; #include "string.hh" #include "sourcefile.hh" +#include "moment.hh" +#include "duration.hh" +#include "midi-event.hh" +#include "lily-stream.hh" +#include "track-column.hh" +#include "midi-track.hh" + +IPL_instantiate(Midi_event); +IPL_instantiate(Midi_track); IPL_instantiate(Source_file); +IPL_instantiate(Track_column); diff --git a/src/midi-track.cc b/src/midi-track.cc index 77abf04e1c..99bd9dee8c 100644 --- a/src/midi-track.cc +++ b/src/midi-track.cc @@ -4,13 +4,23 @@ // copyright 1997 Jan Nieuwenhuizen #include "proto.hh" +#include "plist.hh" #include "string.hh" +#include "sourcefile.hh" +#include "source.hh" +#include "midi-main.hh" // *tors + #include "moment.hh" +#include "duration.hh" #include "midi-event.hh" +#include "lily-stream.hh" +#include "track-column.hh" #include "midi-track.hh" -Midi_track::Midi_track() +Midi_track::Midi_track( int track_i ) { + name_str_ = String( "track" ) + String( track_i ); + tcol_p_list_.bottom().add( new Track_column( Moment( 0 ) ) ); } Midi_track::~Midi_track() @@ -18,6 +28,57 @@ Midi_track::~Midi_track() } void -Midi_track::add_event( Midi_event* midi_event_p ) +Midi_track::add_event( Moment mom, Midi_event* midi_event_p ) +{ + if ( ! midi_event_p ) + return; + tcol_l( mom - midi_event_p->mom() )->add_event( midi_event_p ); +} + +// too much red tape ? +String +Midi_track::name_str() +{ + return name_str_; +} + +void +Midi_track::output_mudela( Lily_stream& lily_stream_r ) { + lily_stream_r << name_str_ << " = music { $\n"; + lily_stream_r << "\t"; + int column_i = 8; + + for ( PCursor tcol_l_pcur( tcol_p_list_.top() ); tcol_l_pcur.ok(); tcol_l_pcur++ ) { + if ( tcol_l_pcur->midi_event_p_list_.size() > 1 ) + warning( "oeps, chord: can-t do that yet", 0 ); + if ( !tcol_l_pcur->midi_event_p_list_.size() ) + continue; + lily_stream_r << **tcol_l_pcur->midi_event_p_list_.top(); + column_i += tcol_l_pcur->midi_event_p_list_.top()->mudela_str().length_i(); + if ( column_i > 40 ) { + lily_stream_r << "\n\t"; + column_i = 8; + } + } + lily_stream_r << "\n$} % " << name_str_ << "\n"; } + +Track_column* +Midi_track::tcol_l( Moment mom ) +{ + for ( PCursor tcol_l_pcur( tcol_p_list_.top() ); tcol_l_pcur.ok(); tcol_l_pcur++ ) { + if ( tcol_l_pcur->mom() == mom ) + return *tcol_l_pcur; + if ( tcol_l_pcur->mom() > mom ) { + Track_column* tcol_p = new Track_column( mom ); + tcol_l_pcur.insert( tcol_p ); + return tcol_p; + } + } + + Track_column* tcol_p = new Track_column( mom ); + tcol_p_list_.bottom().add( tcol_p ); + return tcol_p; +} + diff --git a/src/midiitem.cc b/src/midiitem.cc index 0ce9ead5e0..c57f9ff5de 100644 --- a/src/midiitem.cc +++ b/src/midiitem.cc @@ -38,8 +38,8 @@ String Midi_chunk::str() { String str = header_str_; - String length_str = StringConversion::int2hex_str( data_str_.length_i() + footer_str_.length_i(), 8, '0' ); - length_str = StringConversion::hex2bin_str( length_str ); + String length_str = String_convert::i2hex_str( data_str_.length_i() + footer_str_.length_i(), 8, '0' ); + length_str = String_convert::hex2bin_str( length_str ); str += length_str; str += data_str_; str += footer_str_; @@ -61,20 +61,20 @@ Midi_header::Midi_header( int format_i, int tracks_i, int clocks_per_4_i ) { String str; - String format_str = StringConversion::int2hex_str( format_i, 4, '0' ); - str += StringConversion::hex2bin_str( format_str ); + String format_str = String_convert::i2hex_str( format_i, 4, '0' ); + str += String_convert::hex2bin_str( format_str ); - String tracks_str = StringConversion::int2hex_str( tracks_i, 4, '0' ); - str += StringConversion::hex2bin_str( tracks_str ); + String tracks_str = String_convert::i2hex_str( tracks_i, 4, '0' ); + str += String_convert::hex2bin_str( tracks_str ); - String tempo_str = StringConversion::int2hex_str( clocks_per_4_i, 4, '0' ); - str += StringConversion::hex2bin_str( tempo_str ); + String tempo_str = String_convert::i2hex_str( clocks_per_4_i, 4, '0' ); + str += String_convert::hex2bin_str( tempo_str ); set( "MThd", str, "" ); } String -Midi_item::int2varlength_str( int i ) +Midi_item::i2varint_str( int i ) { int buffer_i = i & 0x7f; while ( (i >>= 7) > 0 ) { @@ -136,8 +136,8 @@ Midi_tempo::str() { int useconds_per_4_i = 60 * (int)1e6 / tempo_i_; String str = "ff5103"; - str += StringConversion::int2hex_str( useconds_per_4_i, 6, '0' ); - return StringConversion::hex2bin_str( str ); + str += String_convert::i2hex_str( useconds_per_4_i, 6, '0' ); + return String_convert::hex2bin_str( str ); } Midi_track::Midi_track( int number_i ) @@ -169,10 +169,10 @@ Midi_track::Midi_track( int number_i ) String data_str; // only for format 0 (currently using format 1)? - data_str += StringConversion::hex2bin_str( data_ch_c_l ); + data_str += String_convert::hex2bin_str( data_ch_c_l ); char const* footer_ch_c_l = "00" "ff2f" "00"; - String footer_str = StringConversion::hex2bin_str( footer_ch_c_l ); + String footer_str = String_convert::hex2bin_str( footer_ch_c_l ); set( "MTrk", data_str, footer_str ); } @@ -181,13 +181,14 @@ void Midi_track::add( int delta_time_i, String event_str ) { assert(delta_time_i >= 0); - Midi_chunk::add( int2varlength_str( delta_time_i ) + event_str ); + Midi_chunk::add( i2varint_str( delta_time_i ) + event_str ); } void Midi_track::add( Moment delta_time_moment, Midi_item* mitem_l ) { // use convention of 384 clocks per 4 + // use Duration_convert int delta_time_i = delta_time_moment * Moment( 384 ) / Moment( 1, 4 ); add( delta_time_i, mitem_l->str() ); } diff --git a/src/midistream.cc b/src/midistream.cc index 84b105d27d..f561e0b946 100644 --- a/src/midistream.cc +++ b/src/midistream.cc @@ -18,6 +18,7 @@ Midi_stream::Midi_stream( String filename_str, int tracks_i, int clocks_per_4_i filename_str_ = filename_str; tracks_i_ = tracks_i; clocks_per_4_i_ = clocks_per_4_i; + os_p_ = 0; open(); header(); } @@ -32,7 +33,7 @@ Midi_stream::operator <<( String str ) { // still debugging... if ( check_debug ) - str = StringConversion::bin2hex_str( str ); + str = String_convert::bin2hex_str( str ); // string now 1.0.26-2 handles binary streaming *os_p_ << str; return *this; @@ -51,7 +52,7 @@ Midi_stream& Midi_stream::operator <<( int i ) { // output binary string ourselves - *this << Midi_item::int2varlength_str( i ); + *this << Midi_item::i2varint_str( i ); return *this; } @@ -71,7 +72,7 @@ Midi_stream::header() // 00 60 96 per quarter-note // char const ch_c_l = "0000" "0006" "0001" "0001" "0060"; -// str += StringConversion::hex2bin_str( ch_c_l ); +// str += String_convert::hex2bin_str( ch_c_l ); // *os_p_ << str; // *this << Midi_header( 1, 1, tempo_i_ ); diff --git a/src/my-midi-lexer.cc b/src/my-midi-lexer.cc index a070992f53..c261e5c503 100644 --- a/src/my-midi-lexer.cc +++ b/src/my-midi-lexer.cc @@ -57,7 +57,7 @@ My_midi_lexer::here_ch_c_l() } int -My_midi_lexer::varint2int_i( String str ) +My_midi_lexer::varint2_i( String str ) { int var_i = 0; @@ -68,7 +68,7 @@ My_midi_lexer::varint2int_i( String str ) if ( ! ( byte & 0x80 ) ) return var_i; } - cout << "\nvarint2int:" << StringConversion::bin2hex_str( str ) << endl; + cout << "\nvarint2_i:" << String_convert::bin2hex_str( str ) << endl; assert( 0 ); // illegal varint return 0; } diff --git a/src/my-midi-parser.cc b/src/my-midi-parser.cc index cd12082239..62f4d499c8 100644 --- a/src/my-midi-parser.cc +++ b/src/my-midi-parser.cc @@ -13,7 +13,12 @@ #include "my-midi-lexer.hh" #include "my-midi-parser.hh" +#include "duration.hh" #include "midi-event.hh" +#include "lily-stream.hh" +#include "track-column.hh" +#include "midi-track.hh" +#include "midi-score.hh" #include "my-midi-lexer.hh" #include "my-midi-parser.hh" @@ -30,21 +35,32 @@ My_midi_parser::My_midi_parser( String filename_str ) { midi_lexer_p_ = new My_midi_lexer( filename_str ); midi_parser_l_g = this; + defined_ch_c_l_ = 0; + fatal_error_i_ = 0; + midi_key_p_ = 0; + midi_score_p_ = 0; + midi_tempo_p_ = 0; + midi_time_p_ = 0; + reset(); +} +void +My_midi_parser::reset() +{ + delete midi_key_p_; midi_key_p_ = new Midi_key( 0, 0 ); -// midi_tempo_p_ = new Midi_tempo( 384 ); // wiellie dunno! - // 07A120 == 500000 - midi_tempo_p_ = new Midi_tempo( 0x07a120 ); // wiellie dunno! - midi_time_p_ = new Midi_time( 4, 4, 0x24, 8 ); + // useconds per 4: 250000 === 60 4 per minute + delete midi_tempo_p_; + midi_tempo_p_ = new Midi_tempo( 250000 ); + delete midi_time_p_; + midi_time_p_ = new Midi_time( 4, 4, 384, 8 ); - defined_ch_c_l_ = 0; - fatal_error_i_ = 0; - now_f_ = 0; - step_f_ = 0; + now_i64_ = 0; for ( int i = 0; i < CHANNELS_i; i++ ) for ( int j = 0; j < PITCHES_i; j++ ) - running_f_f_a_[ i ][ j ] = 0; +// running_i64_i64_a_[ i ][ j ] = -1; + running_i64_i64_a_[ i ][ j ] = 0; } My_midi_parser::~My_midi_parser() @@ -54,13 +70,14 @@ My_midi_parser::~My_midi_parser() delete midi_key_p_; delete midi_tempo_p_; delete midi_time_p_; + delete midi_score_p_; } void My_midi_parser::add_score( Midi_score* midi_score_p ) { - midi_score_p_array_.push( midi_score_p ); - cout << endl; + assert( !midi_score_p_ ); + midi_score_p_ = midi_score_p; } void @@ -73,36 +90,41 @@ My_midi_parser::error( char const* sz_l ) } void -My_midi_parser::forward( Real f ) +My_midi_parser::forward( int i ) +{ + now_i64_ += i; +} + +Moment +My_midi_parser::mom() { - // ugh - if ( f ) - step_f_ = f; - now_f_ += step_f_; + return Duration_convert::i2_mom( now_i64_, division_1_i_ ); } void My_midi_parser::note_begin( int channel_i, int pitch_i, int dyn_i ) { // one pitch a channel at time! - // heu, what if start at t = 0? -// assert( !running_f_f_a_[ channel_i ][ pitch_i ] ); - running_f_f_a_[ channel_i ][ pitch_i ] = now_f_; + // 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 ) { - Real start_f = running_f_f_a_[ channel_i ] [ pitch_i ]; - // did we start? -> heu, don-t know: what if start at t = 0? -// assert( start_f ); - return new Midi_note( midi_key_p_, midi_time_p_, clocks_per_whole_i_, pitch_i, now_f_ - start_f ); + Int64 start_i64 = running_i64_i64_a_[ channel_i ][ pitch_i ]; +// running_i64_i64_a_[ channel_i ][ pitch_i ] = -1; + // did we start? +// assert( start_i64 != -1 ); + return new Midi_note( midi_key_p_, midi_time_p_, division_1_i_, pitch_i, now_i64_ - start_i64 ); } int -My_midi_parser::output( String filename_str ) +My_midi_parser::output_mudela( String filename_str ) { - return 0; + assert( midi_score_p_ ); + return midi_score_p_->output_mudela( filename_str ); } int @@ -112,10 +134,10 @@ My_midi_parser::parse() } void -My_midi_parser::set_division( int clocks_per_4_i ) +My_midi_parser::set_division_4( int division_4_i ) { - clocks_per_whole_i_ = clocks_per_4_i * 4; - if ( clocks_per_4_i < 0 ) + division_1_i_ = division_4_i * 4; + if ( division_4_i < 0 ) warning( "seconds iso metrical time" , 0 ); } diff --git a/src/mylexer.cc b/src/mylexer.cc index a02c323ea3..10c395759c 100644 --- a/src/mylexer.cc +++ b/src/mylexer.cc @@ -60,7 +60,7 @@ static Keyword_ent the_key_tab[]={ int My_flex_lexer::ret_notename(int *p, String text, int octave_mod) { - text.lower(); + text = text.lower_str(); char const* ch_c_l = here_ch_c_l(); if ( ch_c_l ) { ch_c_l--; diff --git a/src/note.cc b/src/note.cc index 95a7d8313d..0f7eb8e85f 100644 --- a/src/note.cc +++ b/src/note.cc @@ -25,7 +25,7 @@ bool last_duration_mode = false; void set_duration_mode(String s) { - s.upper(); + s = s.upper_str(); last_duration_mode = (s== "LAST"); } diff --git a/src/request.cc b/src/request.cc index bce34a8575..991be88550 100644 --- a/src/request.cc +++ b/src/request.cc @@ -101,12 +101,12 @@ Melodic_req::height() const /* should be settable from input to allow "viola"-mode */ -static Byte pitch_by_a[ 7 ] = { 0, 2, 4, 5, 7, 9, 11 }; +static Byte pitch_byte_a[ 7 ] = { 0, 2, 4, 5, 7, 9, 11 }; int Melodic_req::pitch() const { - return pitch_by_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12; + return pitch_byte_a[ notename_i_ % 7 ] + accidental_i_ + octave_i_ * 12; } Plet_req::Plet_req() diff --git a/src/script.cc b/src/script.cc index db87b6baf1..a98a8a9926 100644 --- a/src/script.cc +++ b/src/script.cc @@ -57,7 +57,7 @@ Script::support_height() const return r; } void -Script::set_default_pos() +Script::set_default_index() { Real inter_f= paper()->internote(); Interval dy = symbol().dim.y; @@ -115,7 +115,7 @@ Script::do_pre_processing() void Script::do_post_processing() { - set_default_pos(); + set_default_index(); } Molecule* diff --git a/src/sourcefile.cc b/src/sourcefile.cc index eac2b1f84a..5caa8545fa 100644 --- a/src/sourcefile.cc +++ b/src/sourcefile.cc @@ -104,10 +104,10 @@ Source_file::error_str( char const* pos_ch_c_l ) else error_col_i++; - String str = line_str.left( pos_ch_c_l - begin_ch_c_l ) + String str = line_str.left_str( pos_ch_c_l - begin_ch_c_l ) + String( '\n' ) + String( ' ', error_col_i ) - + line_str.mid( pos_ch_c_l - begin_ch_c_l + 1, INT_MAX ); // String::mid should take 0 arg.. + + line_str.mid_str( pos_ch_c_l - begin_ch_c_l + 1, INT_MAX ); // String::mid should take 0 arg.. return str; } diff --git a/src/stem.cc b/src/stem.cc index 22123356c6..e9a4f943bf 100644 --- a/src/stem.cc +++ b/src/stem.cc @@ -186,7 +186,7 @@ Stem::brew_molecule_p()const return out; } Real -Stem::hpos()const +Stem::hindex()const { return pcol_l_->hpos + stem_xoffset; // hmm. + offset_.x; } diff --git a/src/tex.cc b/src/tex.cc index 1a5c4a08c5..d7f1162d29 100644 --- a/src/tex.cc +++ b/src/tex.cc @@ -14,10 +14,10 @@ vstrut(Real h) static void substitute_arg(String& r, String arg) { - int p = r.pos('%'); + int p = r.index_i('%'); if (!p ) return ; else p--; - r = r.left(p) + arg + r.right(r.len() - p -1); + r = r.left_str(p) + arg + r.right_str(r.length_i() - p -1); } @@ -27,7 +27,7 @@ substitute_args(String source, Array args) String retval (source); for (int i = 0 ; i < args.size(); i++) substitute_arg(retval, args[i]); - while (retval.pos('%')) + while (retval.index_i('%')) substitute_arg(retval, ""); return retval; } diff --git a/src/textitem.cc b/src/textitem.cc index 110e95e3bf..56fb8e054b 100644 --- a/src/textitem.cc +++ b/src/textitem.cc @@ -17,7 +17,7 @@ Text_item::Text_item(Text_req* treq_l, int staffsize_i) } void -Text_item::set_default_pos() +Text_item::set_default_index() { pos_i_ = (dir_i_ > 0) ? staffsize_i_ + 2: -4; } @@ -25,7 +25,7 @@ Text_item::set_default_pos() void Text_item::do_pre_processing() { - set_default_pos(); + set_default_index(); } diff --git a/src/track-column.cc b/src/track-column.cc new file mode 100644 index 0000000000..22a828376f --- /dev/null +++ b/src/track-column.cc @@ -0,0 +1,35 @@ +// +// track-column.cc -- implement Track_column +// +// copyright 1997 Jan Nieuwenhuizen + +#include "proto.hh" +#include "plist.hh" +#include "string.hh" +#include "moment.hh" +#include "duration.hh" +#include "midi-event.hh" +#include "lily-stream.hh" +#include "track-column.hh" +#include "midi-track.hh" + +Track_column::Track_column( Moment mom ) +{ + mom_ = mom; +} + +Track_column::~Track_column() +{ +} + +void +Track_column::add_event( Midi_event* midi_event_p ) +{ + midi_event_p_list_.bottom().add( midi_event_p ); +} + +Moment +Track_column::mom() +{ + return mom_; +}