]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.0.34
authorfred <fred>
Sun, 24 Mar 2002 19:32:51 +0000 (19:32 +0000)
committerfred <fred>
Sun, 24 Mar 2002 19:32:51 +0000 (19:32 +0000)
27 files changed:
Generate.make
Makefile
hdr/Makefile
hdr/inputfile.hh [new file with mode: 0644]
hdr/lexer.hh
hdr/midi-event.hh [new file with mode: 0644]
hdr/midi-main.hh [new file with mode: 0644]
hdr/midi-score.hh [new file with mode: 0644]
hdr/midi-track.hh [new file with mode: 0644]
hdr/my-midi-lexer.hh [new file with mode: 0644]
hdr/my-midi-parser.hh [new file with mode: 0644]
hdr/source.hh
src/Makefile
src/inputfile.cc [new file with mode: 0644]
src/lexerinit.cc
src/midi-event.cc [new file with mode: 0644]
src/midi-lexer.l [new file with mode: 0644]
src/midi-main.cc [new file with mode: 0644]
src/midi-parser.y [new file with mode: 0644]
src/midi-score.cc [new file with mode: 0644]
src/midi-template.cc [new file with mode: 0644]
src/midi-track.cc [new file with mode: 0644]
src/my-midi-lexer.cc [new file with mode: 0644]
src/my-midi-parser.cc [new file with mode: 0644]
src/mylexer.cc
src/sourcefile.cc
src/warn.cc

index 701c6d79b04493d1f0168e3914df82d4fac4c7a5..0b1e6c490d20a11ef254fb584bef536cd57a321a 100644 (file)
@@ -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 $< > $@
 
index 830b08c36043d0de30be49d0f432c6a75b91cfcc..3e4a16e51101447a28b094db5a7961b8ecdcc291 100644 (file)
--- 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: 
index f23ddcf6caa7f9633d6d525e3bd404a2579369cd..384c9bc39e60fd99b4ad4a2e2ba5d286f000bdb9 100644 (file)
@@ -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 (file)
index 0000000..5e55050
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+  inputfile.hh -- declare Input_file
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#ifndef INPUT_FILE_HH
+#define INPUT_FILE_HH
+#include <FlexLexer.h>
+#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
index ce760fe22dd4bb894151b9a41c4094778cb24412..7f06158c3a5c31652fcfd3e3aeacbb44d03928ef 100644 (file)
@@ -1,3 +1,11 @@
+/*
+  lexer.hh -- declare My_flex_lexer
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
 #ifndef LEXER_HH
 #define LEXER_HH
 #include <FlexLexer.h>
@@ -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 (file)
index 0000000..c9ab033
--- /dev/null
@@ -0,0 +1,19 @@
+//
+// midi-event.hh -- declare midi_event
+//
+// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#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 (file)
index 0000000..2812bb8
--- /dev/null
@@ -0,0 +1,10 @@
+//
+// midi-main.hh -- global (sic) m2m stuff 
+//
+// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#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 (file)
index 0000000..2f88168
--- /dev/null
@@ -0,0 +1,24 @@
+//
+// midi-score.hh -- declare midi_score
+//
+// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#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 (file)
index 0000000..ce258c6
--- /dev/null
@@ -0,0 +1,21 @@
+//
+// midi-track.hh -- declare midi_track
+//
+// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#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 (file)
index 0000000..5245d1b
--- /dev/null
@@ -0,0 +1,43 @@
+//
+// my-midi-lexer.hh -- declare My_midi_lexer
+//
+// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#ifndef MY_MIDI_LEXER_HH
+#define MY_MIDI_LEXER_HH
+
+#include <FlexLexer.h>
+#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 (file)
index 0000000..68b238a
--- /dev/null
@@ -0,0 +1,35 @@
+//
+// my-midi-parser.hh -- declare My_midi_parser
+//
+// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#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*> 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
+
index 3bdbef721e249e1f3289ac97cfcc9556c02be27d..6c79b75a996de0df81fbe99ab3acfa4636cd6d31 100644 (file)
@@ -19,4 +19,8 @@ private:
     IPointerList<Source_file*> sourcefile_p_iplist_;
 };
 
+
+// ugh
+extern Source* source_l_g;
+
 #endif // SOURCE_HH //
index 8c88c5dbc787adbf7a31f5fdd78a465369a68fcc..e78d5785f7b57b876be2b49930fe5c90b073c9aa 100644 (file)
@@ -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 (file)
index 0000000..7faefd2
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+  inputfile.cc -- implement Input_file
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl> Jan Nieuwenhuizen <jan@digicash.com>
+*/
+
+#include <iostream.h>
+#include <strstream.h>
+#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;  
+}
index 43a1c2c5a6f4a73685e3ad7cc4f4798643f569d9..02dd000e638bc7edbe7e6eb9c6704fed992fee4f 100644 (file)
@@ -1,3 +1,11 @@
+/*
+  lexerinit.cc -- implement some stuff
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
 #include <iostream.h>
 #include <strstream.h>
 #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 << "["<<pf<<flush;
-}
-
-Input_file::~Input_file()
-{
-  cout << "]" << flush;  
-}
diff --git a/src/midi-event.cc b/src/midi-event.cc
new file mode 100644 (file)
index 0000000..2e295a5
--- /dev/null
@@ -0,0 +1,16 @@
+//
+// midi-event.cc -- implement Midi_event
+//
+// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#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 (file)
index 0000000..d95696d
--- /dev/null
@@ -0,0 +1,261 @@
+%{
+// midi-lexer.l
+
+#include <stdio.h>
+
+#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>{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>{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>{INT8}   {
+       puts( "lex: int8" );
+       assert( YYLeng() == 1 );
+//     yylval.byte = *(Byte*)YYText();
+       yylval.i = *(Byte*)YYText();
+       yy_pop_state(); 
+       return INT8;
+}
+
+<track>{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;
+}
+
+<event>{RUNNING_STATUS}        {
+       yylval.byte = *(Byte*)YYText();
+       yy_pop_state(); 
+       yy_push_state( int8 );
+       return RUNNING_STATUS;
+}
+<event>{NOTE_OFF}      {
+       puts( "lex: note off" );
+       yylval.byte = *(Byte*)YYText();
+       yy_pop_state(); 
+       yy_push_state( int8 );
+       yy_push_state( int8 );
+       return NOTE_OFF;
+}
+<event>{NOTE_ON}       {
+       puts( "lex: note on" );
+       yylval.byte = *(Byte*)YYText();
+       yy_pop_state(); 
+       yy_push_state( int8 );
+       yy_push_state( int8 );
+       return NOTE_ON;
+}
+<event>{PROGRAM_CHANGE}        {
+       yylval.byte = *(Byte*)YYText();
+       yy_pop_state(); 
+       yy_push_state( int8 );
+       return PROGRAM_CHANGE;
+}
+<event>{META_EVENT}    {
+       yy_push_state( meta_event );
+       return META_EVENT;
+}
+
+<meta_event>{SEQUENCE} {       // ssss sequence number
+       yy_push_state( int16 );
+       return SEQUENCE;
+}
+<meta_event>{TEXT}     {               // len data
+       yy_push_state( data );
+       return TEXT;
+}
+<meta_event>{COPYRIGHT}        {
+       yy_push_state( data );
+       return COPYRIGHT;
+}
+<meta_event>{TRACK_NAME}       {
+       yy_push_state( data );
+       return TRACK_NAME;
+}
+<meta_event>{INSTRUMENT_NAME}  {
+       yy_push_state( data );
+       return INSTRUMENT_NAME;
+}
+<meta_event>{LYRIC}    {
+       yy_push_state( data );
+       return LYRIC;
+}
+<meta_event>{MARKER}   {
+       yy_push_state( data );
+       return MARKER;
+}
+<meta_event>{CUE_POINT}        {
+       yy_push_state( data );
+       return CUE_POINT;
+}
+<meta_event>{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;
+}
+<meta_event>{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;
+}
+<meta_event>{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;
+}
+<meta_event>{KEY}      {       // sf mi
+       puts( "lex: key" );
+       yy_pop_state();
+       yy_pop_state();
+       yy_push_state( int8 );
+       yy_push_state( int8 );
+       return KEY;
+}
+<meta_event>{SSME}     {       // len data
+       yy_pop_state();
+       yy_pop_state();
+       yy_push_state( data );
+       return SSME;
+}
+<meta_event>{END_OF_TRACK} {
+       puts( "lex: end of track" );
+       yy_pop_state();
+       yy_pop_state();
+       yy_pop_state();
+       return END_OF_TRACK;
+}
+<meta_event>{INT8} {
+       yylval.byte = *(Byte*)YYText();
+       return INT8;
+}
+
+<data>{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;
+}
+
+
+<<EOF>> {
+//     mtor << "<<EOF>>";
+
+       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 (file)
index 0000000..3735517
--- /dev/null
@@ -0,0 +1,74 @@
+//
+// midi-main.cc -- implement silly main() entry point
+// should have Root class.
+//
+// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#include <iostream.h>
+#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 (file)
index 0000000..519266f
--- /dev/null
@@ -0,0 +1,173 @@
+%{
+
+#include <iostream.h>
+
+#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<i> INT8 INT16 INT32 INT7_8UNSET INT7_8SET VARINT
+%token<i> RUNNING_STATUS NOTE_OFF NOTE_ON PROGRAM_CHANGE
+%token<str_p> DATA
+
+%type <midi_score_p> header midi_score
+%type <midi_track_p> track
+%type <midi_event_p> event
+%type <midi_event_p> the_event meta_event text_event midi_event sysex_event
+%type <midi_event_p> 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 (file)
index 0000000..02a79a5
--- /dev/null
@@ -0,0 +1,24 @@
+//
+// midi-score.cc -- implement Midi_score
+//
+// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#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 (file)
index 0000000..02315c3
--- /dev/null
@@ -0,0 +1,19 @@
+//
+// midi-template.cc -- implementemplate
+//
+// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#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 (file)
index 0000000..99390c3
--- /dev/null
@@ -0,0 +1,21 @@
+//
+// midi-track.cc -- implement Midi_track
+//
+// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#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 (file)
index 0000000..70c860b
--- /dev/null
@@ -0,0 +1,78 @@
+//
+// my-midi-lexer.cc -- implement My_midi_lexer
+//
+// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#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 (file)
index 0000000..51dda6b
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// my-midi-parser.cc -- implement My_midi_parser
+//
+// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#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 );
+}
+
index ea86b3094b4d4d1a6b1b3901917eb6ba6076a247..a02c323ea35bb7288ecd06c61d6b90e337000278 100644 (file)
@@ -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"
index f10d419b5afefe243cc8d28d74361421e3d65943..0775719160a45d969a5d32b4f0fe7e11fef43844 100644 (file)
@@ -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() );
 }
 
index 63490de581077299168faf69b39d54a2bccf2f11..b57c6d2bdceda2f9dec0d93d088c485504bc2be2 100644 (file)
@@ -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(": ");
     }