performances in numbered MIDI files.
* lily/performance-scheme.cc (LY_DEFINE): new file.
(LY_DEFINE): new function ly:performance-write.
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!
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);
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 ());
}
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))
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)))
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))
{
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 ();
};
SCM systems_;
SCM pages_;
+ SCM performances_;
void add_score_title (SCM);
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)
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.")
header_0_ = SCM_EOL;
pages_ = SCM_BOOL_F;
scores_ = SCM_EOL;
+ performances_ = SCM_EOL;
systems_ = SCM_BOOL_F;
paper_ = 0;
}
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);
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_;
}
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;
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 (),
{
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 (),
}
void
-Paper_book::classic_output (String outname)
+Paper_book::classic_output (SCM output)
{
/* Generate all stencils to trigger font loads. */
systems ();
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 (),
pages_ = scm_apply_0 (proc, scm_list_2 (systems (), self_scm ()));
return pages_;
}
+
+SCM
+Paper_book::performances () const
+{
+ return scm_reverse (performances_);
+}
--- /dev/null
+/*
+ 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;
+}
+
+
+
output (midi_stream);
progress_indication ("\n");
}
+
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);
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 ());
}
(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)
(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)
))
(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))))))