From: fred Date: Sun, 24 Mar 2002 19:32:51 +0000 (+0000) Subject: lilypond-0.0.34 X-Git-Tag: release/1.5.59~5327 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=9130db0b1007693a2e8eb70f73f3ca33c8954c5d;p=lilypond.git lilypond-0.0.34 --- diff --git a/Generate.make b/Generate.make index 701c6d79b0..0b1e6c490d 100644 --- a/Generate.make +++ b/Generate.make @@ -1,9 +1,12 @@ +# Generate.make ? +# -> Rules.make: containing all compile/flex/bison/... rules (jcn) parsheadorig=$(CCDIR)/parser.tab.h parsheadnew=$(HEADERDIR)/parser.hh # # take some trouble to avoid overwriting the old y.tab.h +# why? (jcn) $(CCDIR)/parser.cc: $(CCDIR)/parser.y $(BISON) -d $< (if diff $(parsheadorig) $(parsheadnew)>/dev/null; then \ @@ -18,9 +21,11 @@ $(parsheadnew): $(CCDIR)/parser.cc $(HEADERDIR)/version.hh: Variables.make make_version make_version $(MAJVER) $(MINVER) $(PATCHLEVEL) "$(CXX) $(CXXVER)" > $@ -$(CCDIR)/lexer.cc: $(CCDIR)/lexer.l - $(FLEX) -t $< > $@ - - +$(CCDIR)/%.cc: $(CCDIR)/%.y + $(BISON) -d $< + mv $(CCDIR)/$(shell basename $@ .cc ).tab.h $(HEADERDIR)/$(shell basename $@ .cc).hh + mv $(CCDIR)/$(shell basename $@ .cc ).tab.c $@ +$(CCDIR)/%.cc: $(CCDIR)/%.l + $(FLEX) -t $< > $@ diff --git a/Makefile b/Makefile index 830b08c360..3e4a16e511 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,6 @@ +# Makefile +# top level makefile of LilyPond + include Variables.make .SUFFIXES: @@ -8,11 +11,13 @@ $(exe): $(obs) $(STRIPDEBUG) $(STABLEOBS) $(LINKER) -o $@ $^ $(LOADLIBES) +$(m2m): $(m2mobs) + $(LINKER) -o $@ $^ $(LOADLIBES) .PHONY: clean docxx clean: - rm -f $(exe) $(DOCDIR)/* core $(obs) $(ALLDEPS) + rm -f $(allexe) $(DOCDIR)/* core $(allobs) $(ALLDEPS) for SUBDIR in $(SUBDIRS); \ do \ $(MAKE) SUBDIR=$$SUBDIR -C $$SUBDIR clean;\ @@ -21,7 +26,7 @@ clean: distclean: clean rm -f version.hh $(gencc) .GENERATE *~ $(ALLDEPS) -all: kompijl doc +all: $(exe) $(m2m) doc # value of $(OSTYPE) on windhoos; "make $OSTYPE" if u use bash :-) win32: diff --git a/hdr/Makefile b/hdr/Makefile index f23ddcf6ca..384c9bc39e 100644 --- a/hdr/Makefile +++ b/hdr/Makefile @@ -1,6 +1,6 @@ default: $(MAKE) -C .. -DISTFILES=Makefile $(hdr) +DISTFILES=Makefile $(allhdr) dist: ln $(DISTFILES) $(DDIR)/$(SUBDIR) @@ -10,3 +10,4 @@ TAGS: $(hdr) clean: rm -f parser.hh + rm -f midi-parser.hh diff --git a/hdr/inputfile.hh b/hdr/inputfile.hh new file mode 100644 index 0000000000..5e55050299 --- /dev/null +++ b/hdr/inputfile.hh @@ -0,0 +1,28 @@ +/* + inputfile.hh -- declare Input_file + + source file of the LilyPond music typesetter + + (c) 1997 Han-Wen Nienhuys +*/ + +#ifndef INPUT_FILE_HH +#define INPUT_FILE_HH +#include +#include "proto.hh" +#include "fproto.hh" +#include "varray.hh" +#include "string.hh" + +struct Input_file { + istream* is; + char const* defined_ch_c_l_; + Source_file* sourcefile_l_; + int line; + String name; + + Input_file(String); + ~Input_file(); +}; + +#endif // INPUT_FILE_HH diff --git a/hdr/lexer.hh b/hdr/lexer.hh index ce760fe22d..7f06158c3a 100644 --- a/hdr/lexer.hh +++ b/hdr/lexer.hh @@ -1,3 +1,11 @@ +/* + lexer.hh -- declare My_flex_lexer + + source file of the LilyPond music typesetter + + (c) 1997 Han-Wen Nienhuys +*/ + #ifndef LEXER_HH #define LEXER_HH #include @@ -12,18 +20,6 @@ bool busy_parsing(); void kill_lexer(); void set_lexer(); -struct Input_file { - istream* is; - char const* defined_ch_c_l_; - Source_file* sourcefile_l_; - int line; - String name; - - Input_file(String); - ~Input_file(); -}; - - /// lexer with provisions for include files. struct My_flex_lexer : yyFlexLexer { diff --git a/hdr/midi-event.hh b/hdr/midi-event.hh new file mode 100644 index 0000000000..c9ab0336ea --- /dev/null +++ b/hdr/midi-event.hh @@ -0,0 +1,19 @@ +// +// midi-event.hh -- declare midi_event +// +// copyright 1997 Jan Nieuwenhuizen + +#ifndef MIDI_EVENT_HH +#define MIDI_EVENT_HH + +/// (midi_event) +class Midi_event { +public: + Midi_event(); + ~Midi_event(); + +private: +}; + +#endif // MIDI_EVENT_HH + diff --git a/hdr/midi-main.hh b/hdr/midi-main.hh new file mode 100644 index 0000000000..2812bb82b4 --- /dev/null +++ b/hdr/midi-main.hh @@ -0,0 +1,10 @@ +// +// midi-main.hh -- global (sic) m2m stuff +// +// copyright 1997 Jan Nieuwenhuizen + +#include "string.hh" +extern Source* source_l_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 ); diff --git a/hdr/midi-score.hh b/hdr/midi-score.hh new file mode 100644 index 0000000000..2f88168a11 --- /dev/null +++ b/hdr/midi-score.hh @@ -0,0 +1,24 @@ +// +// midi-score.hh -- declare midi_score +// +// copyright 1997 Jan Nieuwenhuizen + +#ifndef MIDI_SCORE_HH +#define MIDI_SCORE_HH + +/// (midi_score) +class Midi_score { +public: + Midi_score( int format_i, int tracks_i, int tempo_i ); + ~Midi_score(); + + void add_track( Midi_track* midi_track_p ); + +private: + int format_i_; + int tracks_i_; + int tempo_i_; +}; + +#endif // MIDI_SCORE_HH + diff --git a/hdr/midi-track.hh b/hdr/midi-track.hh new file mode 100644 index 0000000000..ce258c6eae --- /dev/null +++ b/hdr/midi-track.hh @@ -0,0 +1,21 @@ +// +// midi-track.hh -- declare midi_track +// +// copyright 1997 Jan Nieuwenhuizen + +#ifndef MIDI_TRACK_HH +#define MIDI_TRACK_HH + +/// (midi_track) +class Midi_track { +public: + Midi_track(); + ~Midi_track(); + + void add_event( Midi_event* midi_event_p ); + +private: +}; + +#endif // MIDI_TRACK_HH + diff --git a/hdr/my-midi-lexer.hh b/hdr/my-midi-lexer.hh new file mode 100644 index 0000000000..5245d1be84 --- /dev/null +++ b/hdr/my-midi-lexer.hh @@ -0,0 +1,43 @@ +// +// my-midi-lexer.hh -- declare My_midi_lexer +// +// copyright 1997 Jan Nieuwenhuizen + +#ifndef MY_MIDI_LEXER_HH +#define MY_MIDI_LEXER_HH + +#include +#include "proto.hh" +// #include "fproto.hh" +#include "varray.hh" +#include "string.hh" + +int yylex(); +void yyerror(const char *s); +// bool busy_parsing(); +// void kill_lexer(); +// void set_lexer(); + +/// (midi_lexer) +class My_midi_lexer : yyFlexLexer { +public: + My_midi_lexer( String filename_str ); + ~My_midi_lexer(); + + int close_i(); + void error( char const* sz_l ); + char const* here_ch_c_l(); + static int varint2int_i( String str ); + int yylex(); + +private: + Input_file* input_file_p_; + +public: // ugh + int errorlevel_i_; +}; + +extern My_midi_lexer* midi_lexer_l_g; + +#endif // MY_MIDI_LEXER_HH + diff --git a/hdr/my-midi-parser.hh b/hdr/my-midi-parser.hh new file mode 100644 index 0000000000..68b238a795 --- /dev/null +++ b/hdr/my-midi-parser.hh @@ -0,0 +1,35 @@ +// +// my-midi-parser.hh -- declare My_midi_parser +// +// copyright 1997 Jan Nieuwenhuizen + +#ifndef MY_MIDI_PARSER_HH +#define MY_MIDI_PARSER_HH + +#include "proto.hh" +#include "varray.hh" +#include "string.hh" +// #include "plist.hh" + +int yyparse(); + +/// (midi_parser) +class My_midi_parser { +public: + My_midi_parser( String filename_str ); + ~My_midi_parser(); + void add_score( Midi_score* midi_score_p ); + void error( char const* sz_l ); + int parse(); + +private: + Array midi_score_p_array_; + char const* defined_ch_c_l_; + int fatal_error_i_; + My_midi_lexer* midi_lexer_p_; +}; + +extern My_midi_parser* midi_parser_l_g; + +#endif // MY_MIDI_PARSER_HH + diff --git a/hdr/source.hh b/hdr/source.hh index 3bdbef721e..6c79b75a99 100644 --- a/hdr/source.hh +++ b/hdr/source.hh @@ -19,4 +19,8 @@ private: IPointerList sourcefile_p_iplist_; }; + +// ugh +extern Source* source_l_g; + #endif // SOURCE_HH // diff --git a/src/Makefile b/src/Makefile index 8c88c5dbc7..e78d5785f7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -4,12 +4,12 @@ default: win32: $(MAKE) -C .. Windows_NT -DISTFILES=Makefile $(mycc) $(othersrc) +DISTFILES=Makefile $(allcc) $(othersrc) dist: ln $(DISTFILES) $(DDIR)/$(SUBDIR) -TAGS: $(mycc) - etags -CT $(mycc) +TAGS: $(allcc) + etags -CT $(allcc) clean: rm -f $(gencc) diff --git a/src/inputfile.cc b/src/inputfile.cc new file mode 100644 index 0000000000..7faefd2c9b --- /dev/null +++ b/src/inputfile.cc @@ -0,0 +1,41 @@ +/* + inputfile.cc -- implement Input_file + + source file of the LilyPond music typesetter + + (c) 1997 Han-Wen Nienhuys Jan Nieuwenhuizen +*/ + +#include +#include +#include "proto.hh" +#include "plist.hh" +#include "inputfile.hh" +#include "debug.hh" +#include "sourcefile.hh" +#include "source.hh" + +Input_file::Input_file(String s) +{ + name = s; + line = 1; + String pf(s); + if ( pf == "" ) { + is = &cin; + defined_ch_c_l_ = 0; + sourcefile_l_ = 0; + } + else { + Source_file* sourcefile_p = new Source_file( pf ); + source_l_g->add( sourcefile_p ); + sourcefile_l_ = sourcefile_p; + is = sourcefile_l_->istream_l(); + defined_ch_c_l_ = sourcefile_l_->ch_c_l(); + } + cout << "[" << pf << flush; +} + +Input_file::~Input_file() +{ + cout << "]" << flush; +} diff --git a/src/lexerinit.cc b/src/lexerinit.cc index 43a1c2c5a6..02dd000e63 100644 --- a/src/lexerinit.cc +++ b/src/lexerinit.cc @@ -1,3 +1,11 @@ +/* + lexerinit.cc -- implement some stuff + + source file of the LilyPond music typesetter + + (c) 1997 Han-Wen Nienhuys +*/ + #include #include #include "proto.hh" @@ -20,28 +28,3 @@ busy_parsing() { return lexer; } - -Input_file::Input_file(String s) -{ - name = s; - line = 1; - String pf(s); - if (pf=="") { - is = &cin; - defined_ch_c_l_ = 0; - sourcefile_l_ = 0; - } - else { - Source_file* sourcefile_p = new Source_file( pf ); - source_global_l->add( sourcefile_p ); - sourcefile_l_ = sourcefile_p; - is = sourcefile_l_->istream_l(); - defined_ch_c_l_ = sourcefile_l_->ch_c_l(); - } - cout << "["< + +#include "proto.hh" +#include "midi-event.hh" + +Midi_event::Midi_event() +{ +} + +Midi_event::~Midi_event() +{ +} + diff --git a/src/midi-lexer.l b/src/midi-lexer.l new file mode 100644 index 0000000000..d95696dbb5 --- /dev/null +++ b/src/midi-lexer.l @@ -0,0 +1,261 @@ +%{ +// midi-lexer.l + +#include + +#include "string.hh" +#include "proto.hh" +#include "my-midi-lexer.hh" +#include "midi-parser.hh" + +#ifndef MIDI_LEX_DEBUG +#define puts( x ) +#endif + +%} + +%option c++ +%option noyywrap +%option nodefault +%option yylineno +%option debug +%option yyclass="My_midi_lexer" +%option stack + +%x data +%x event +%x int8 +%x int16 +%x int32 +%x meta_event +%x track + +INT8 [\x00-\xff] +INT16 {INT8}{INT8} +INT32 {INT16}{INT16} +INT7_8UNSET [\x00-\x7f] +INT7_8SET [\x80-\xff] +VARINT {INT7_8SET}{0,3}{INT7_8UNSET} + +HEADER MThd +TRACK MTrk + +RUNNING_STATUS [\x30-\x4f] +NOTE_OFF [\x80-\x8f] +NOTE_ON [\x90-\x9f] +PROGRAM_CHANGE [\xc0-\xcf] + +SYSEX_EVENT1 [\xf0] +SYSEX_EVENT2 [\xf7] + +META_EVENT [\xff] + +SEQUENCE [\x00][\x02] +TEXT [\x01] +COPYRIGHT [\x02] +TRACK_NAME [\x03] +INSTRUMENT_NAME [\x04] +LYRIC [\x05] +MARKER [\x06] +CUE_POINT [\x07] + +END_OF_TRACK [\x2f][\x00] +TEMPO [\x51][\x03] +SMPTE_OFFSET [\x54][\x05] +TIME [\x58][\x04] +KEY [\x59][\x02] +SSME [\0x7f][\x03] + +%% + +{HEADER}/{INT32} { // using /{INT32}; longer match than {INT32} + puts( "lex: header" ); + yy_push_state( int16 ); + yy_push_state( int16 ); + yy_push_state( int16 ); + yy_push_state( int32 ); + return HEADER; +} + +{TRACK}/{INT32} { // using /{INT32}; longer match than {INT32} + puts( "lex: track" ); + yy_push_state( track ); + yy_push_state( int32 ); + return TRACK; +} + +{INT32} { + puts( "lex: int32" ); + assert( YYLeng() == 4 ); + String str( (Byte const*)YYText(), YYLeng() ); + yylval.i = StringConversion::bin2int_i( str ); + yy_pop_state(); + return INT32; +} +{INT16} { + puts( "lex: int16" ); + assert( YYLeng() == 2 ); + String str( (Byte const*)YYText(), YYLeng() ); + yylval.i = StringConversion::bin2int_i( str ); + yy_pop_state(); + return INT16; +} +{INT8} { + puts( "lex: int8" ); + assert( YYLeng() == 1 ); +// yylval.byte = *(Byte*)YYText(); + yylval.i = *(Byte*)YYText(); + yy_pop_state(); + return INT8; +} + +{VARINT} { + puts( "lex: track: varint" ); + String str( (Byte const*)YYText(), YYLeng() ); + yylval.i = My_midi_lexer::varint2int_i( str ); + yy_push_state( event ); + return VARINT; +} + +{RUNNING_STATUS} { + yylval.byte = *(Byte*)YYText(); + yy_pop_state(); + yy_push_state( int8 ); + return RUNNING_STATUS; +} +{NOTE_OFF} { + puts( "lex: note off" ); + yylval.byte = *(Byte*)YYText(); + yy_pop_state(); + yy_push_state( int8 ); + yy_push_state( int8 ); + return NOTE_OFF; +} +{NOTE_ON} { + puts( "lex: note on" ); + yylval.byte = *(Byte*)YYText(); + yy_pop_state(); + yy_push_state( int8 ); + yy_push_state( int8 ); + return NOTE_ON; +} +{PROGRAM_CHANGE} { + yylval.byte = *(Byte*)YYText(); + yy_pop_state(); + yy_push_state( int8 ); + return PROGRAM_CHANGE; +} +{META_EVENT} { + yy_push_state( meta_event ); + return META_EVENT; +} + +{SEQUENCE} { // ssss sequence number + yy_push_state( int16 ); + return SEQUENCE; +} +{TEXT} { // len data + yy_push_state( data ); + return TEXT; +} +{COPYRIGHT} { + yy_push_state( data ); + return COPYRIGHT; +} +{TRACK_NAME} { + yy_push_state( data ); + return TRACK_NAME; +} +{INSTRUMENT_NAME} { + yy_push_state( data ); + return INSTRUMENT_NAME; +} +{LYRIC} { + yy_push_state( data ); + return LYRIC; +} +{MARKER} { + yy_push_state( data ); + return MARKER; +} +{CUE_POINT} { + yy_push_state( data ); + return CUE_POINT; +} +{TEMPO} { // tttttt usec + puts( "lex: tempo" ); + yy_pop_state(); + yy_pop_state(); + yy_push_state( int8 ); + yy_push_state( int8 ); + yy_push_state( int8 ); + return TEMPO; +} +{SMPTE_OFFSET} { // hr mn se fr ff + yy_pop_state(); + yy_pop_state(); + yy_push_state( int8 ); + yy_push_state( int8 ); + yy_push_state( int8 ); + yy_push_state( int8 ); + yy_push_state( int8 ); + return SMPTE_OFFSET; +} +{TIME} { // nn dd cc bb + puts( "lex: time" ); + yy_pop_state(); + yy_pop_state(); + yy_push_state( int8 ); + yy_push_state( int8 ); + yy_push_state( int8 ); + yy_push_state( int8 ); + return TIME; +} +{KEY} { // sf mi + puts( "lex: key" ); + yy_pop_state(); + yy_pop_state(); + yy_push_state( int8 ); + yy_push_state( int8 ); + return KEY; +} +{SSME} { // len data + yy_pop_state(); + yy_pop_state(); + yy_push_state( data ); + return SSME; +} +{END_OF_TRACK} { + puts( "lex: end of track" ); + yy_pop_state(); + yy_pop_state(); + yy_pop_state(); + return END_OF_TRACK; +} +{INT8} { + yylval.byte = *(Byte*)YYText(); + return INT8; +} + +{VARINT} { + String str( (Byte const*)YYText(), YYLeng() ); + int i = My_midi_lexer::varint2int_i( str ); + String* str_p = new String; + while ( i-- ) + *str_p += (char)yyinput(); + yylval.str_p = str_p; + yy_pop_state(); + yy_pop_state(); + return DATA; +} + + +<> { +// mtor << "<>"; + + if ( !close_i() ) + yyterminate(); // can't move this, since it actually rets a YY_NULL +} + +%% + diff --git a/src/midi-main.cc b/src/midi-main.cc new file mode 100644 index 0000000000..3735517f13 --- /dev/null +++ b/src/midi-main.cc @@ -0,0 +1,74 @@ +// +// midi-main.cc -- implement silly main() entry point +// should have Root class. +// +// copyright 1997 Jan Nieuwenhuizen + +#include +#include "proto.hh" +#include "plist.hh" +#include "string.hh" +#include "source.hh" +#include "sourcefile.hh" +#include "midi-main.hh" +#include "midi-event.hh" +#include "midi-track.hh" +#include "my-midi-lexer.hh" +#include "my-midi-parser.hh" + +Source source; +Source* source_l_g = &source; + +//ugh +char const* defined_ch_c_l = 0; + +String +find_file( String str ) +{ + return str; +} + +// ugh, copied from warn.cc, cannot use +void +message( String message_str, char const* context_ch_c_l ) +{ + String str = "lilypond: "; + Source_file* sourcefile_l = source_l_g->sourcefile_l( context_ch_c_l ); + if ( sourcefile_l ) { + str += sourcefile_l->file_line_no_str(context_ch_c_l) + String(": "); + } + str += message_str; + if ( sourcefile_l ) { + str += ":\n"; + str += sourcefile_l->error_str( context_ch_c_l ); + } +// if ( busy_parsing() ) +// cerr << endl; + cerr << str << endl; +} + +void +warning( String message_str, char const* context_ch_c_l ) +{ + message( "warning: " + message_str, context_ch_c_l ); +} + +void +error( String message_str, char const* context_ch_c_l ) +{ + message( message_str, context_ch_c_l ); + // since when exits error again? + // i-d say: error: errorlevel |= 1; -> no output upon error + // warning: recovery -> output (possibly wrong) + if ( midi_lexer_l_g ) + midi_lexer_l_g->errorlevel_i_ |= 1; +} + +int +main( int argc_i, char* argv_sz_a[] ) +{ + if ( !argc_i ) + return 2; + My_midi_parser midi_parser( argv_sz_a[ 1 ] ); + return midi_parser.parse(); +} diff --git a/src/midi-parser.y b/src/midi-parser.y new file mode 100644 index 0000000000..519266f1fb --- /dev/null +++ b/src/midi-parser.y @@ -0,0 +1,173 @@ +%{ + +#include + +#include "my-midi-lexer.hh" +#include "my-midi-parser.hh" +#include "midi-event.hh" +#include "midi-track.hh" +#include "midi-score.hh" + +#ifndef NDEBUG +#define YYDEBUG 1 +#endif + +%} + +%union { + Byte byte; + char c; + int i; + String* str_p; + Request* request_p; + Midi_event* midi_event_p; // Voice_element* ? + Midi_score* midi_score_p; // Input_score* ? + Midi_track* midi_track_p; // Input_music* ? +} + +%token HEADER TRACK +%token SYSEX_EVENT1 SYSEX_EVENT2 +%token META_EVENT +%token SEQUENCE TEXT COPYRIGHT TRACK_NAME INSTRUMENT_NAME LYRIC MARKER CUE_POINT +%token END_OF_TRACK TEMPO SMPTE_OFFSET TIME KEY SSME + +%token INT8 INT16 INT32 INT7_8UNSET INT7_8SET VARINT +%token RUNNING_STATUS NOTE_OFF NOTE_ON PROGRAM_CHANGE +%token DATA + +%type header midi_score +%type track +%type event +%type the_event meta_event text_event midi_event sysex_event +%type running_status note_off note_on program_change + +%% + +midi: /* empty */ + | midi midi_score { + midi_parser_l_g->add_score( $2 ); + } + ; + +midi_score: + header { + } + | midi_score track { + $$->add_track( $2 ); + } + ; + +header: + HEADER INT32 INT16 INT16 INT16 { + $$ = new Midi_score( $3, $4, $5 ); + } + ; + +track: + TRACK INT32 { + $$ = new Midi_track; + } + | track event { + $$->add_event( $2 ); + } + ; + +event: + VARINT the_event { + } + ; + +the_event: + meta_event { + } + | midi_event { + } + | sysex_event { + } + ; + +meta_event: + META_EVENT the_meta_event { + }; + +the_meta_event: + SEQUENCE INT16 { + } + | text_event DATA { + } + | END_OF_TRACK { + } + | TEMPO INT8 INT8 INT8 { + } + | SMPTE_OFFSET INT8 INT8 INT8 INT8 INT8 { + } + | TIME INT8 INT8 INT8 INT8 { + } + | KEY INT8 INT8 { + } + | SSME DATA { + } + ; + +text_event: + TEXT { + } + | COPYRIGHT { + } + | TRACK_NAME { + } + | INSTRUMENT_NAME { + } + | LYRIC { + } + | MARKER { + } + | CUE_POINT { + } + ; + +midi_event: + running_status { + } + | note_off { + } + | note_on { + } + | program_change { + } + ; + +running_status: + RUNNING_STATUS { + } + ; + +note_off: + NOTE_OFF INT8 INT8 { + } + ; + +note_on: + NOTE_ON INT8 INT8 { + int pitch_i = $2; + // assuming key of C + String notename_str = ( pitch_i % 12 )[ "ccddeffggaab" ]; + static int accidental_i_a[ 12 ] = { 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0 }; + int accidental_i = accidental_i_a[ pitch_i % 12 ]; + if ( accidental_i == 1 ) + notename_str += "is"; + cout << "note(" << pitch_i << "): " << notename_str << endl; + } + ; + +program_change: + PROGRAM_CHANGE { + } + ; + +sysex_event: + SYSEX_EVENT1 { + } + | SYSEX_EVENT2 { + } + ; diff --git a/src/midi-score.cc b/src/midi-score.cc new file mode 100644 index 0000000000..02a79a542d --- /dev/null +++ b/src/midi-score.cc @@ -0,0 +1,24 @@ +// +// midi-score.cc -- implement Midi_score +// +// copyright 1997 Jan Nieuwenhuizen + +#include "proto.hh" +#include "midi-track.hh" +#include "midi-score.hh" + +Midi_score::Midi_score( int format_i, int tracks_i, int tempo_i ) +{ + format_i_ = format_i; + tracks_i_ = tracks_i; + tempo_i_ = tempo_i; +} + +Midi_score::~Midi_score() +{ +} + +void +Midi_score::add_track( Midi_track* midi_track_p ) +{ +} diff --git a/src/midi-template.cc b/src/midi-template.cc new file mode 100644 index 0000000000..02315c320b --- /dev/null +++ b/src/midi-template.cc @@ -0,0 +1,19 @@ +// +// midi-template.cc -- implementemplate +// +// copyright 1997 Jan Nieuwenhuizen + +#include "list.tcc" +#include "cursor.tcc" + +L_instantiate(void *); + +class istream; +class ostream; +#include "proto.hh" +#include "plist.tcc" +#include "pcursor.tcc" +#include "string.hh" +#include "sourcefile.hh" + +IPL_instantiate(Source_file); diff --git a/src/midi-track.cc b/src/midi-track.cc new file mode 100644 index 0000000000..99390c3346 --- /dev/null +++ b/src/midi-track.cc @@ -0,0 +1,21 @@ +// +// midi-track.cc -- implement Midi_track +// +// copyright 1997 Jan Nieuwenhuizen + +#include "proto.hh" +#include "midi-event.hh" +#include "midi-track.hh" + +Midi_track::Midi_track() +{ +} + +Midi_track::~Midi_track() +{ +} + +void +Midi_track::add_event( Midi_event* midi_event_p ) +{ +} diff --git a/src/my-midi-lexer.cc b/src/my-midi-lexer.cc new file mode 100644 index 0000000000..70c860bcf5 --- /dev/null +++ b/src/my-midi-lexer.cc @@ -0,0 +1,78 @@ +// +// my-midi-lexer.cc -- implement My_midi_lexer +// +// copyright 1997 Jan Nieuwenhuizen + +#include "debug.hh" +#include "inputfile.hh" +#include "sourcefile.hh" +#include "my-midi-lexer.hh" + +int +yylex() +{ + return midi_lexer_l_g->yylex(); +} + +My_midi_lexer* midi_lexer_l_g; + +My_midi_lexer::My_midi_lexer( String filename_str ) +{ + input_file_p_ = new Input_file( filename_str ); + switch_streams( input_file_p_->is ); + midi_lexer_l_g = this; + errorlevel_i_ = 0; +} + +My_midi_lexer::~My_midi_lexer() +{ + delete input_file_p_; + midi_lexer_l_g = 0; +} + +void +My_midi_lexer::error( char const* sz_l ) +{ + if ( !input_file_p_ ) { +// *mlog << "error at EOF" << sz_l << '\n'; + cerr << "error at EOF" << sz_l << '\n'; + } else { + char const* ch_c_l = here_ch_c_l(); + if ( ch_c_l ) { + ch_c_l--; + while ( ( *ch_c_l == ' ' ) || ( *ch_c_l == '\t' ) || ( *ch_c_l == '\n' ) ) + ch_c_l--; + ch_c_l++; + } + errorlevel_i_ |= 1; +// ::error( sz_l, ch_c_l ); + ::error( sz_l, ch_c_l ); + } +} + +char const* +My_midi_lexer::here_ch_c_l() +{ + return input_file_p_->sourcefile_l_->ch_c_l() + yyin->tellg(); +} + +#if 0 // ?? huh +int +My_midi_lexer::yylex() +{ + return 0; +} +#endif + +int +My_midi_lexer::varint2int_i( String str ) +{ + return 0; +} + +int +My_midi_lexer::close_i() +{ + return 0; +} + diff --git a/src/my-midi-parser.cc b/src/my-midi-parser.cc new file mode 100644 index 0000000000..51dda6bd15 --- /dev/null +++ b/src/my-midi-parser.cc @@ -0,0 +1,52 @@ +// +// my-midi-parser.cc -- implement My_midi_parser +// +// copyright 1997 Jan Nieuwenhuizen + +#include "my-midi-lexer.hh" +#include "my-midi-parser.hh" + +void +yyerror(char const* sz_l ) +{ + midi_parser_l_g->error( sz_l ); +} + + +My_midi_parser* midi_parser_l_g; + +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; +} + +My_midi_parser::~My_midi_parser() +{ + delete midi_lexer_p_; + midi_parser_l_g = 0; +} + +void +My_midi_parser::error( char const* sz_l ) +{ + midi_lexer_l_g->error( sz_l ); + + if ( fatal_error_i_ ) + exit( fatal_error_i_ ); +} + +int +My_midi_parser::parse() +{ + return ::yyparse(); +} + +void +My_midi_parser::add_score( Midi_score* midi_score_p ) +{ + midi_score_p_array_.push( midi_score_p ); +} + diff --git a/src/mylexer.cc b/src/mylexer.cc index ea86b3094b..a02c323ea3 100644 --- a/src/mylexer.cc +++ b/src/mylexer.cc @@ -3,6 +3,7 @@ #include "identparent.hh" #include "associter.hh" #include "lexer.hh" +#include "inputfile.hh" #include "parser.hh" #include "keyword.hh" #include "assoc.hh" diff --git a/src/sourcefile.cc b/src/sourcefile.cc index f10d419b5a..0775719160 100644 --- a/src/sourcefile.cc +++ b/src/sourcefile.cc @@ -152,6 +152,7 @@ Source_file::map() data_caddr_ = (caddr_t)mmap( (void*)0, size_off_, PROT_READ, MAP_SHARED, fildes_i_, 0 ); if ( (int)data_caddr_ == -1 ) + // ugh: defined_ch_c_l... warning( String( "can't map: " ) + name_str_ + String( ": " ) + strerror( errno ), defined_ch_c_l ); //lexer->here_ch_c_l() ); } diff --git a/src/warn.cc b/src/warn.cc index 63490de581..b57c6d2bdc 100644 --- a/src/warn.cc +++ b/src/warn.cc @@ -48,7 +48,7 @@ void message( String message_str, char const* context_ch_c_l ) { String str = "lilypond: "; - Source_file* sourcefile_l = source_global_l->sourcefile_l( context_ch_c_l ); + Source_file* sourcefile_l = source_l_g->sourcefile_l( context_ch_c_l ); if ( sourcefile_l ) { str += sourcefile_l->file_line_no_str(context_ch_c_l) + String(": "); }