]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.0.39
authorfred <fred>
Tue, 4 Mar 1997 21:16:15 +0000 (21:16 +0000)
committerfred <fred>
Tue, 4 Mar 1997 21:16:15 +0000 (21:16 +0000)
lily/include/main.hh [new file with mode: 0644]
lily/main.cc [new file with mode: 0644]
lily/midi-stream.cc [new file with mode: 0644]
lily/tex-stream.cc [new file with mode: 0644]

diff --git a/lily/include/main.hh b/lily/include/main.hh
new file mode 100644 (file)
index 0000000..fe4f9ad
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef MAIN_HH
+#define MAIN_HH
+#include "proto.hh"
+
+void debug_init();
+void set_debug(bool);
+void do_scores();
+void add_score(Input_score * s);
+void set_default_output(String s);
+Input_score* current_iscore_l();
+String find_file(String);
+const char *get_version();
+extern String infile_str_g;
+extern Source* source_l_g;
+extern bool only_midi;
+
+extern String default_out_fn;
+
+#endif
diff --git a/lily/main.cc b/lily/main.cc
new file mode 100644 (file)
index 0000000..1073f94
--- /dev/null
@@ -0,0 +1,168 @@
+#include <iostream.h>
+#include <assert.h>
+#include "proto.hh"
+#include "plist.hh"
+#include "lgetopt.hh"
+#include "misc.hh"
+#include "string.hh"
+#include "main.hh"
+#include "path.hh"
+#include "config.hh"
+#include "source-file.hh"
+#include "source.hh"
+
+Source source;
+Source* source_l_g = &source;
+String infile_str_g;
+bool only_midi = false;
+extern void parse_file(String,String);
+
+
+void
+destill_inname( String &name_str_r);
+Long_option_init theopts[] = {
+    1, "output", 'o',
+    0, "warranty", 'w',
+    0, "help", 'h',
+    0, "debug", 'd',
+    1, "init", 'i',
+    1, "include", 'I',
+    0, "midi", 'M',
+    0,0,0
+};
+
+void
+help()
+{
+    cout <<
+       "--help, -h             This help\n"
+       "--warranty, -w         show warranty & copyright\n"
+       "--output, -o           set default output\n"
+       "--debug, -d            enable debug output\n"
+       "--init, -i             set init file\n"
+        "--include, -I         add to file search path.\n"
+       "--midi, -M             midi output only\n"
+       ;
+    
+}
+
+void 
+notice()
+{
+    cout <<
+       "\n"
+       "LilyPond, a music typesetter.\n"
+       "Copyright (C) 1996,97 by\n"
+       "  Han-Wen Nienhuys <hanwen@stack.nl>\n"
+       "Contributors\n"
+       "  Jan Nieuwenhuizen <jan@digicash.com>\n"
+       "  Mats Bengtsson <matsb@s3.kth.se>\n"
+       "\n"
+       "    This program is free software; you can redistribute it and/or\n"
+       "modify it under the terms of the GNU General Public License version 2\n"
+       "as published by the Free Software Foundation.\n"
+       "\n"
+       "    This program is distributed in the hope that it will be useful,\n"
+       "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+       "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n"
+       "General Public License for more details.\n"
+       "\n"
+       "    You should have received a copy (refer to the file COPYING) of the\n"
+       "GNU General Public License along with this program; if not, write to\n"
+       "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
+       "USA.\n";
+}
+
+static File_path * path =0;
+struct Main_init {
+    Main_init() {
+       path = new File_path(LIBDIR);
+       path->push(String(LIBDIR)+"init/");
+       debug_init();
+    }
+    ~Main_init() {
+       delete path;
+    }
+} main_init;
+
+int
+main (int argc, char **argv)
+{    
+    Getopt_long oparser(argc, argv,theopts);
+    cout << get_version();
+    String init_str("symbol.ini");
+    
+    while (Long_option_init * opt = oparser()) {
+       switch ( opt->shortname){
+       case 'o':
+           set_default_output(oparser.optarg);
+           break;
+       case 'w':
+           notice();
+           exit(0);
+           break;
+       case 'I':
+           path->push(oparser.optarg);
+           break;
+       case 'i':
+           init_str = oparser.optarg;
+           break;
+       case 'h':
+           help();
+           exit(0);
+           break;
+       case 'd':
+           set_debug(true);
+           break;
+       case 'M':
+           only_midi = true;
+           break;
+       default:
+           assert(false);
+           break;
+       }
+    }
+
+    int p=0;
+    char *arg ;
+    while ( (arg= oparser.get_next_arg()) ) {
+       String f(arg);
+       destill_inname(f);
+       infile_str_g = f;
+       parse_file(init_str,f);
+       do_scores();
+       p++;
+    }
+    if (!p) {
+       parse_file(init_str, "");       
+       do_scores();
+    }
+
+    return 0;
+}
+
+String
+find_file(String f)
+{
+    return path->find(f);
+}
+
+/// make input file name: add default extension. "" is stdin.
+void
+destill_inname( String &name_str_r)
+{
+    if ( name_str_r.length_i() )
+        {
+        if( name_str_r[ 0 ] != '-' ) 
+           {
+           String a,b,c,d;
+           split_path(name_str_r,a,b,c,d);
+
+           // add extension if not present.
+           if (d == "") 
+               d = ".ly";
+           name_str_r = a+b+c+d;
+           }
+       } else name_str_r = "";   
+}
+
diff --git a/lily/midi-stream.cc b/lily/midi-stream.cc
new file mode 100644 (file)
index 0000000..88e5eb2
--- /dev/null
@@ -0,0 +1,90 @@
+//
+// midistream.cc
+//
+// source file of the LilyPond music typesetter
+//
+// (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#include <fstream.h>
+#include <time.h>
+#include "string.hh"
+#include "string-convert.hh"
+#include "main.hh"
+#include "misc.hh"
+#include "midi-item.hh"
+#include "midi-stream.hh"
+#include "debug.hh"
+
+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();
+}
+
+Midi_stream::~Midi_stream()
+{
+    delete os_p_;
+}
+
+Midi_stream&
+Midi_stream::operator <<( String str )
+{
+    // still debugging...
+    if ( check_debug )
+       str = String_convert::bin2hex_str( str );
+    // string now 1.0.26-2 handles binary streaming
+    *os_p_ << str;
+    return *this;
+}
+
+Midi_stream&
+Midi_stream::operator <<( Midi_item const& mitem_c_r )
+{
+    mitem_c_r.output_midi( *this );
+    if ( check_debug )
+        *os_p_ << "\n";
+    return *this;
+}
+
+Midi_stream&
+Midi_stream::operator <<( int i )
+{
+    // output binary string ourselves
+    *this << Midi_item::i2varint_str( i );
+    return *this;
+}
+
+void
+Midi_stream::header()
+{
+//    *os_p_ << "% Creator: " << get_version();
+//    *os_p_ << "% Automatically generated, at ";
+//    time_t t(time(0));
+//    *os_p_ << ctime(&t);
+
+//                4D 54 68 64     MThd
+//    String str = "MThd";
+//                00 00 00 06     chunk length
+//                00 01   format 1
+//                00 01   one track
+//                00 60   96 per quarter-note
+
+//    char const ch_c_l = "0000" "0006" "0001" "0001" "0060";
+//    str += String_convert::hex2bin_str( ch_c_l );
+//    *os_p_ << str;
+
+//      *this << Midi_header( 1, 1, tempo_i_ );
+      *this << Midi_header( 1, tracks_i_, clocks_per_4_i_ );
+}
+
+void
+Midi_stream::open()
+{
+    os_p_ = new ofstream( filename_str_ );
+    if ( !*os_p_ )
+       error ("can't open `" + filename_str_ + "\'" );
+}
diff --git a/lily/tex-stream.cc b/lily/tex-stream.cc
new file mode 100644 (file)
index 0000000..06459a2
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+  tex-stream.cc -- implement Tex_stream
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include <fstream.h>
+#include <time.h>
+
+#include "tex.hh"
+#include "main.hh"
+#include "tex-stream.hh"
+#include "debug.hh"
+
+Tex_stream::Tex_stream(String filename) 
+{
+    os = new ofstream(filename);
+    if (!*os)
+       error("can't open `" + filename+"\'");
+    nest_level = 0;
+    outputting_comment=false;
+    header();
+}
+void
+Tex_stream::header()
+{
+    *os << "% Creator: " << get_version();
+    *os << "% Automatically generated, at ";
+    time_t t(time(0));
+    *os << ctime(&t);
+    *os << "% from musical definition: " + infile_str_g + "\n";
+}
+Tex_stream::~Tex_stream()
+{
+    delete os;
+    assert(nest_level == 0);
+}
+
+// print string. don't forget indent.
+Tex_stream &
+Tex_stream::operator<<(String s)
+{
+    
+    for (const char *cp = s; *cp; cp++) {
+       if (outputting_comment) {
+           *os << *cp;
+           if (*cp == '\n') {
+               outputting_comment=false;
+
+           }
+           continue;
+       }
+       switch(*cp) 
+           {
+           case '%':
+               outputting_comment = true;
+               *os << *cp;
+               break;
+           case '{':
+               nest_level++;
+               *os << *cp;             
+               break;
+           case '}':
+               nest_level--;           
+               *os << *cp;
+               
+               if (nest_level < 0) {
+                   delete os;  // we want to see the remains.
+                   assert(nest_level>=0);
+               }
+               /* FALLTHROUGH */
+               
+           case '\n':
+               *os << "%\n";
+               *os << String(' ', nest_level);
+               break;        
+           default:
+               *os << *cp;
+               break;
+           }
+    }
+    return *this;
+}
+
+
+/* *************************************************************** */