]> git.donarmstrong.com Git - lilypond.git/commitdiff
* scm/midi.scm (paper-book-write-midis): new function. Write all
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 11 Jul 2005 13:30:57 +0000 (13:30 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 11 Jul 2005 13:30:57 +0000 (13:30 +0000)
performances in numbered MIDI files.

* lily/performance-scheme.cc (LY_DEFINE): new file.
(LY_DEFINE): new function ly:performance-write.

14 files changed:
ChangeLog
lily/book-scheme.cc
lily/book.cc
lily/include/book.hh
lily/include/paper-book.hh
lily/paper-book-scheme.cc
lily/paper-book.cc
lily/performance-scheme.cc [new file with mode: 0644]
lily/performance.cc
lily/score-scheme.cc
lily/score.cc
scm/framework-ps.scm
scm/lily-library.scm
scm/midi.scm

index 8ccf916294ba072255848a7d0b32d35696e11408..982c3c2aac962f5731f03279a0c23abc63078601 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2005-07-11  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
+       * scm/midi.scm (paper-book-write-midis): new function. Write all
+       performances in numbered MIDI files.
+
+       * lily/performance-scheme.cc (LY_DEFINE): new file.
+       (LY_DEFINE): new function ly:performance-write.
+
        * lily/lily-parser-scheme.cc (LY_DEFINE): ly:parser-output-name:
        new function.
        (LY_DEFINE): change name ly:parser-define -> ly:parser-define!
index f430377fce47f2ffd3c291ff9bec6d573b2818b0..03e10af05d73c3d39caafe3105090a36210cc5cb 100644 (file)
@@ -39,8 +39,11 @@ LY_DEFINE (ly_parser_print_book, "ly:book-process",
           4, 0, 0, (SCM book_smob,
                     SCM default_paper,
                     SCM default_layout,
-                    SCM basename),
-          "Print book.")
+                    SCM output),
+          "Print book. @var{output} is passed to the backend unchanged. "
+          "Eg. it may be "
+          "a string (for file based outputs) or a socket (for network based "
+          "output).")
 {
   Book *book = unsmob_book (book_smob);
 
@@ -49,16 +52,12 @@ LY_DEFINE (ly_parser_print_book, "ly:book-process",
                   default_layout, SCM_ARG2, __FUNCTION__, "\\paper block");
   SCM_ASSERT_TYPE (unsmob_output_def (default_layout),
                   default_layout, SCM_ARG3, __FUNCTION__, "\\layout block");
-  SCM_ASSERT_TYPE (scm_is_string (basename), basename, SCM_ARG4, __FUNCTION__, "string");
 
-  String base = ly_scm2string (basename);
-  Paper_book *pb = book->process (base,
-                                 unsmob_output_def (default_paper),
-                                 unsmob_output_def (default_layout)
-                                 );
+  Paper_book *pb = book->process (unsmob_output_def (default_paper),
+                                 unsmob_output_def (default_layout));
   if (pb)
     {
-      pb->output (base);
+      pb->output (output);
       scm_gc_unprotect_object (pb->self_scm ());
     }
 
index 59c9c206afb1b91478641f17f2463b2a02a9ece9..0994c84a0e0589b8bb6799816c8f92791bb4e5dc 100644 (file)
@@ -74,11 +74,11 @@ Book::add_score (SCM s)
   scores_ = scm_cons (s, scores_);
 }
 
-/* This function does not dump the output; outname is required eg. for
-   dumping header fields.  */
+/* Concatenate all score outputs into a Paper_book
+   
+ */
 Paper_book *
-Book::process (String outname,
-              Output_def *default_paper,
+Book::process (Output_def *default_paper,
               Output_def *default_layout)
 {
   for (SCM s = scores_; s != SCM_EOL; s = scm_cdr (s))
@@ -102,7 +102,6 @@ Book::process (String outname,
   paper_book->header_ = header_;
 
   /* Render in order of parsing.  */
-  int midi_count = 0;
   for (SCM s = scm_reverse (scores_); s != SCM_EOL; s = scm_cdr (s))
     {
       if (Score *score = unsmob_score (scm_car (s)))
@@ -116,12 +115,7 @@ Book::process (String outname,
 
              if (Performance *perf = dynamic_cast<Performance *> (output))
                {
-                 String fn = outname;
-                 if (midi_count)
-                   fn += "-" + to_string (midi_count);
-
-                 midi_count ++;
-                 perf->write_output (fn);
+                 paper_book->add_performance (perf->self_scm ());
                }
              else if (Paper_score *pscore = dynamic_cast<Paper_score *> (output)) 
                {
index 44c764703d664e25167cea8589d7dc86d85fe21b..79dcd19b4f14462288594168510f3f3529849091 100644 (file)
@@ -27,8 +27,7 @@ public:
 
   Book ();
   void add_score (SCM);
-  Paper_book *process (String,
-                      Output_def *def_paper,
+  Paper_book *process (Output_def *def_paper,
                       Output_def *def_layout);
   void set_keys ();
 };
index 310a321d99fa3457d96758495365e1410a854e8f..f0d29289180ffa1b61e47cc1b3f5f5788eedffb7 100644 (file)
@@ -25,6 +25,7 @@ class Paper_book
 
   SCM systems_;
   SCM pages_;
+  SCM performances_;
 
   void add_score_title (SCM);
 public:
@@ -34,15 +35,19 @@ public:
   Output_def *paper_;
 
   Paper_book ();
-
+  
   void add_score (SCM);
+  void add_performance (SCM);
+
+  SCM performances () const;
   SCM systems ();
   SCM pages ();
   Stencil book_title ();
   Stencil score_title (SCM);
-  void classic_output (String);
-  void output (String);
+  void classic_output (SCM output_channel);
+  void output (SCM output_channel);
   void post_processing (SCM, SCM);
+  
 };
 
 DECLARE_UNSMOB (Paper_book, paper_book)
index 69b7dc02eedac1595136db5fffbca72c8ee96703..7db18919b5219b2eac1efb2feaacbcc7ddd41fc0 100644 (file)
@@ -31,6 +31,13 @@ LY_DEFINE (ly_paper_book_scopes, "ly:paper-book-scopes",
   return scopes;
 }
 
+LY_DEFINE (ly_paper_book_performances, "ly:paper-book-performances",
+          1, 0, 0, (SCM paper_book),
+          "Return performances in book @var{paper-book}.")
+{
+  return unsmob_paper_book (paper_book)->performances ();
+}
+
 LY_DEFINE (ly_paper_book_systems, "ly:paper-book-systems",
           1, 0, 0, (SCM pb),
           "Return systems in book PB.")
index e1fadabd325b498e12e9859ae42a3b4d7fb0fac2..08e378b41eb911542203fde1766fd970240f081f 100644 (file)
@@ -23,6 +23,7 @@ Paper_book::Paper_book ()
   header_0_ = SCM_EOL;
   pages_ = SCM_BOOL_F;
   scores_ = SCM_EOL;
+  performances_ = SCM_EOL;
   systems_ = SCM_BOOL_F;
 
   paper_ = 0;
@@ -34,10 +35,10 @@ Paper_book::~Paper_book ()
 }
 
 IMPLEMENT_DEFAULT_EQUAL_P (Paper_book);
-IMPLEMENT_SMOBS (Paper_book)
-  IMPLEMENT_TYPE_P (Paper_book, "ly:paper-book?")
+IMPLEMENT_SMOBS (Paper_book);
+IMPLEMENT_TYPE_P (Paper_book, "ly:paper-book?");
 
-  SCM
+SCM
 Paper_book::mark_smob (SCM smob)
 {
   Paper_book *b = (Paper_book *) SCM_CELL_WORD_1 (smob);
@@ -46,6 +47,7 @@ Paper_book::mark_smob (SCM smob)
   scm_gc_mark (b->header_);
   scm_gc_mark (b->header_0_);
   scm_gc_mark (b->pages_);
+  scm_gc_mark (b->performances_);
   scm_gc_mark (b->scores_);
   return b->systems_;
 }
@@ -79,8 +81,16 @@ Paper_book::add_score (SCM s)
   scores_ = scm_cons (s, scores_);
 }
 
+
 void
-Paper_book::output (String outname)
+Paper_book::add_performance (SCM s)
+{
+  performances_ = scm_cons (s, performances_);
+}
+
+
+void
+Paper_book::output (SCM output_channel)
 {
   if (scores_ == SCM_EOL)
     return;
@@ -100,7 +110,7 @@ Paper_book::output (String outname)
       SCM func = scm_c_module_lookup (mod, "output-framework");
 
       func = scm_variable_ref (func);
-      scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
+      scm_apply_0 (func, scm_list_n (output_channel,
                                     self_scm (),
                                     scopes,
                                     dump_fields (),
@@ -111,7 +121,7 @@ Paper_book::output (String outname)
     {
       SCM func = scm_c_module_lookup (mod, "output-preview-framework");
       func = scm_variable_ref (func);
-      scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
+      scm_apply_0 (func, scm_list_n (output_channel,
                                     self_scm (),
                                     scopes,
                                     dump_fields (),
@@ -120,7 +130,7 @@ Paper_book::output (String outname)
 }
 
 void
-Paper_book::classic_output (String outname)
+Paper_book::classic_output (SCM output)
 {
   /* Generate all stencils to trigger font loads.  */
   systems ();
@@ -139,7 +149,7 @@ Paper_book::classic_output (String outname)
   SCM func = scm_c_module_lookup (mod, "output-classic-framework");
 
   func = scm_variable_ref (func);
-  scm_apply_0 (func, scm_list_n (scm_makfrom0str (outname.to_str0 ()),
+  scm_apply_0 (func, scm_list_n (output,
                                 self_scm (),
                                 scopes,
                                 dump_fields (),
@@ -343,3 +353,9 @@ Paper_book::pages ()
   pages_ = scm_apply_0 (proc, scm_list_2 (systems (), self_scm ()));
   return pages_;
 }
+
+SCM
+Paper_book::performances () const
+{
+  return scm_reverse (performances_);
+}
diff --git a/lily/performance-scheme.cc b/lily/performance-scheme.cc
new file mode 100644 (file)
index 0000000..d8dd325
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+  performance-scheme.cc -- implement Performance bindings
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+*/
+
+
+#include "performance.hh"
+
+
+LY_DEFINE (ly_performance_write, "ly:performance-write",
+          2,0,0, (SCM performance, SCM filename),
+          "Write @var{performance} to @var{filename}")
+
+{
+  Performance * perf  = dynamic_cast<Performance*> (unsmob_music_output (performance));
+
+  SCM_ASSERT_TYPE(perf, performance, SCM_ARG1, __FUNCTION__, "Performance");
+  SCM_ASSERT_TYPE(scm_is_string (filename), filename, SCM_ARG2, __FUNCTION__, "file name");
+
+  perf->write_output (ly_scm2string (filename));
+  return SCM_UNSPECIFIED;
+}
+
+
+
index 6735f025a79fa0c07de30f6538d95947bb32413e..6bdec3790c7867abc63afdee27e40a36f142fac8 100644 (file)
@@ -167,3 +167,4 @@ Performance::write_output (String out)
   output (midi_stream);
   progress_indication ("\n");
 }
+
index 9690a6cfea1c4190c2e8c74ca44323d3293a1085..6ef6d216ecea404f422a7e92a66e5838d3b12371 100644 (file)
@@ -91,8 +91,6 @@ LY_DEFINE (ly_score_process, "ly:score-process",
                   default_header, SCM_ARG3, __FUNCTION__, "\\paper block");
   SCM_ASSERT_TYPE (unsmob_output_def (default_layout),
                   default_header, SCM_ARG4, __FUNCTION__, "\\layout block");
-  SCM_ASSERT_TYPE (scm_is_string (basename),
-                  default_header, SCM_ARG5, __FUNCTION__, "basename");
   
   Object_key *key = new Lilypond_general_key (0, score->user_key_, 0);
 
index 032c4be49630c6f0e4503163a5799a1df968cd81..7bae956296742ee8c8f9d8172cee0d2c800ea2f2 100644 (file)
@@ -136,7 +136,7 @@ default_rendering (SCM music, SCM outdef,
       SCM systems = pscore->get_paper_systems ();
       paper_book->add_score (systems);
 
-      paper_book->classic_output (ly_scm2string (outname));
+      paper_book->classic_output (outname);
       scm_gc_unprotect_object (paper_book->self_scm ());
     }
 
index 27f0b65df323114ea84180ba9a5df20266510ad6..4e4145261a1eb061320e984bf9ec31eaf9b5d23c 100644 (file)
         (page-count (length pages))
         (port (ly:outputter-port outputter)))
 
+    (paper-book-write-midis book basename)
+    
     (output-scopes scopes fields basename)
     (display (page-header paper page-count #t) port)
     (write-preamble paper #t port)
index 8ea362a19843422bd0dec05a8227dea4c972c76c..bb6624139575d468569b6097c2af2d78aa1c9a76 100644 (file)
        (set! count 0))
 
     (if (> count 0)
-       (set! (base (format #f "~a-~a" count))))
+       (set! base (format #f "~a-~a" base count)))
 
     (ly:parser-define! parser 'output-count (1+ count))
     
-
     (ly:book-process book paper layout base)
     ))
 
index 4180f1b517d294ce135e994c4d61ff0cd1fcd030..9aad4bd1baa9cf58f633b298dacf87b356f7a56f 100644 (file)
@@ -277,3 +277,23 @@ returns the program of the instrument
 (define-public (alterations-in-key pitch-list)
   "Count number of sharps minus number of flats"
   (/ (apply + (map cdr pitch-list)) 2))
+
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+
+(define-public (paper-book-write-midis paper-book basename)
+  (let
+      loop
+      ((perfs (ly:paper-book-performances paper-book))
+       (count 0))
+      
+    (if (pair?  perfs)
+       (begin
+         (ly:performance-write
+          (car perfs)
+          (if (> count 0)
+              (format #f "~a-~a.midi" basename count)
+              (format #f "~a.midi" basename)))
+         (loop (cdr perfs) (1+ count))))))