From b2bba8f2ecf6bd5e8b755c45b8f271d09ddaa79f Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Fri, 7 Jan 2005 12:27:05 +0000 Subject: [PATCH] *** empty log message *** --- lily/global-context-scheme.cc | 94 ++++++++++++++++++++++++++++++++++ lily/global-context.cc | 2 +- lily/paper-outputter-scheme.cc | 72 ++++++++++++++++++++++++++ lily/paper-outputter.cc | 60 ---------------------- lily/paper-system-scheme.cc | 71 +++++++++++++++++++++++++ lily/paper-system.cc | 61 ---------------------- 6 files changed, 238 insertions(+), 122 deletions(-) create mode 100644 lily/global-context-scheme.cc create mode 100644 lily/paper-outputter-scheme.cc create mode 100644 lily/paper-system-scheme.cc diff --git a/lily/global-context-scheme.cc b/lily/global-context-scheme.cc new file mode 100644 index 0000000000..c0f919f2e7 --- /dev/null +++ b/lily/global-context-scheme.cc @@ -0,0 +1,94 @@ +/* + global-context-scheme.cc -- implement Global_context bindings + + source file of the GNU LilyPond music typesetter + + (c) 2005 Han-Wen Nienhuys + +*/ + +#include "warn.hh" +#include "music-output.hh" +#include "output-def.hh" +#include "music-iterator.hh" +#include "music.hh" +#include "cpu-timer.hh" +#include "global-context.hh" +#include "object-key.hh" +#include "main.hh" + +LY_DEFINE (ly_format_output, "ly:format-output", + 2, 0, 0, (SCM context, SCM outname), + "Given a Score context in its final state," + "process it and return the (rendered) result.") +{ + Global_context *g = dynamic_cast (unsmob_context (context)); + SCM_ASSERT_TYPE (g, context, SCM_ARG1, __FUNCTION__, "Global context"); + SCM_ASSERT_TYPE (scm_is_string (outname), outname, SCM_ARG2, __FUNCTION__, "output file name"); + + Music_output *output = g->get_output (); + progress_indication ("\n"); + /* ugh, midi still wants outname */ + return output->process (ly_scm2string (outname)); +} + + +LY_DEFINE (ly_run_translator, "ly:run-translator", + 2, 1, 0, (SCM mus, SCM output_def, SCM key), + "Process @var{mus} according to @var{output_def}. \n" + "An interpretation context is set up,\n" + "and @var{mus} is interpreted with it. \n" + "The context is returned in its final state.\n" + + "\n\nOptionally, this routine takes an Object-key to\n" + "to uniquely identify the Score block containing it.\n") +{ + Output_def *odef = unsmob_output_def (output_def); + Music *music = unsmob_music (mus); + + if (!music + || !music->get_length ().to_bool ()) + { + warning (_ ("Need music in a score")); + return SCM_BOOL_F; + } + + SCM_ASSERT_TYPE (music, mus, SCM_ARG1, + __FUNCTION__, "Music"); + SCM_ASSERT_TYPE (odef, output_def, SCM_ARG2, __FUNCTION__, + "Output definition"); + + Cpu_timer timer; + + Global_context *trans = new Global_context (odef, music->get_length (), unsmob_key (key) ); + if (!trans) + { + programming_error ("no toplevel translator"); + return SCM_BOOL_F; + } + + progress_indication (_ ("Interpreting music... ")); + + SCM protected_iter = Music_iterator::get_static_get_iterator (music); + Music_iterator * iter = unsmob_iterator (protected_iter); + iter->init_translator (music, trans); + + iter->construct_children (); + + if (!iter->ok ()) + { + warning (_ ("Need music in a score")); + /* todo: should throw exception. */ + return SCM_BOOL_F; + } + + trans->run_iterator_on_me (iter); + iter->quit (); + scm_remember_upto_here_1 (protected_iter); + trans->finish (); + + if (verbose_global_b) + progress_indication (_f ("elapsed time: %.2f seconds", timer.read ())); + + return scm_gc_unprotect_object (trans->self_scm ()); +} diff --git a/lily/global-context.cc b/lily/global-context.cc index ee26880d4d..3096610966 100644 --- a/lily/global-context.cc +++ b/lily/global-context.cc @@ -1,5 +1,5 @@ /* - global-translator.cc -- implement global_context + global-context.cc -- implement Global_context source file of the GNU LilyPond music typesetter diff --git a/lily/paper-outputter-scheme.cc b/lily/paper-outputter-scheme.cc new file mode 100644 index 0000000000..2dd552889f --- /dev/null +++ b/lily/paper-outputter-scheme.cc @@ -0,0 +1,72 @@ +/* + paper-outputter-scheme.cc -- implement Paper_outputter bindings + + source file of the GNU LilyPond music typesetter + + (c) 2005 Han-Wen Nienhuys + +*/ + +#include "paper-outputter.hh" +#include "warn.hh" +#include "stencil.hh" + +LY_DEFINE (ly_make_paper_outputter, "ly:make-paper-outputter", + 2, 0, 0, (SCM outname, SCM format), + "Create an outputter that evaluates within " + "@code{output-}@var{format}, writing to file @var{outname}.") +{ + SCM_ASSERT_TYPE(scm_is_string (outname), outname, SCM_ARG1, __FUNCTION__, + "String"); + SCM_ASSERT_TYPE(scm_is_string (format), format, SCM_ARG2, __FUNCTION__, + "String"); + + String outname_str = ly_scm2string (outname); + String f = ly_scm2string (format); + + progress_indication (_f ("Layout output to `%s'...", + outname_str == "-" + ? String ("") + : outname_str)); + progress_indication ("\n"); + Paper_outputter *po = new Paper_outputter (outname_str, f); + + scm_gc_unprotect_object (po->self_scm ()); + return po->self_scm (); +} + +/* FIXME: why is output_* wrapper called dump? */ +LY_DEFINE (ly_outputter_dump_stencil, "ly:outputter-dump-stencil", + 2, 0, 0, (SCM outputter, SCM stencil), + "Dump stencil @var{expr} onto @var{outputter}.") +{ + Paper_outputter *po = unsmob_outputter (outputter); + Stencil *st = unsmob_stencil (stencil); + SCM_ASSERT_TYPE (po, outputter, SCM_ARG1, __FUNCTION__, "Paper_outputter"); + SCM_ASSERT_TYPE (st, stencil, SCM_ARG1, __FUNCTION__, "Paper_outputter"); + po->output_stencil (*st); + return SCM_UNSPECIFIED; +} + +LY_DEFINE (ly_outputter_dump_string, "ly:outputter-dump-string", + 2, 0, 0, (SCM outputter, SCM str), + "Dump @var{str} onto @var{outputter}.") +{ + Paper_outputter *po = unsmob_outputter (outputter); + SCM_ASSERT_TYPE (po, outputter, SCM_ARG1, __FUNCTION__, "Paper_outputter"); + SCM_ASSERT_TYPE (scm_is_string (str), str, SCM_ARG1, __FUNCTION__, "Paper_outputter"); + + return po->dump_string (str); +} + + +LY_DEFINE (ly_outputter_close, "ly:outputter-close", + 1, 0, 0, (SCM outputter), + "Close port of @var{outputter}.") +{ + Paper_outputter *po = unsmob_outputter (outputter); + SCM_ASSERT_TYPE (po, outputter, SCM_ARG1, __FUNCTION__, "Paper_outputter"); + + po->close (); + return SCM_UNSPECIFIED; +} diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc index 74b2a5b2d0..9651f5c806 100644 --- a/lily/paper-outputter.cc +++ b/lily/paper-outputter.cc @@ -107,66 +107,6 @@ Paper_outputter::output_stencil (Stencil stil) (void*) this, Offset (0,0)); } -LY_DEFINE (ly_make_paper_outputter, "ly:make-paper-outputter", - 2, 0, 0, (SCM outname, SCM format), - "Create an outputter that evaluates within " - "@code{output-}@var{format}, writing to file @var{outname}.") -{ - SCM_ASSERT_TYPE(scm_is_string (outname), outname, SCM_ARG1, __FUNCTION__, - "String"); - SCM_ASSERT_TYPE(scm_is_string (format), format, SCM_ARG2, __FUNCTION__, - "String"); - - String outname_str = ly_scm2string (outname); - String f = ly_scm2string (format); - - progress_indication (_f ("Layout output to `%s'...", - outname_str == "-" - ? String ("") - : outname_str)); - progress_indication ("\n"); - Paper_outputter *po = new Paper_outputter (outname_str, f); - - scm_gc_unprotect_object (po->self_scm ()); - return po->self_scm (); -} - -/* FIXME: why is output_* wrapper called dump? */ -LY_DEFINE (ly_outputter_dump_stencil, "ly:outputter-dump-stencil", - 2, 0, 0, (SCM outputter, SCM stencil), - "Dump stencil @var{expr} onto @var{outputter}.") -{ - Paper_outputter *po = unsmob_outputter (outputter); - Stencil *st = unsmob_stencil (stencil); - SCM_ASSERT_TYPE (po, outputter, SCM_ARG1, __FUNCTION__, "Paper_outputter"); - SCM_ASSERT_TYPE (st, stencil, SCM_ARG1, __FUNCTION__, "Paper_outputter"); - po->output_stencil (*st); - return SCM_UNSPECIFIED; -} - -LY_DEFINE (ly_outputter_dump_string, "ly:outputter-dump-string", - 2, 0, 0, (SCM outputter, SCM str), - "Dump @var{str} onto @var{outputter}.") -{ - Paper_outputter *po = unsmob_outputter (outputter); - SCM_ASSERT_TYPE (po, outputter, SCM_ARG1, __FUNCTION__, "Paper_outputter"); - SCM_ASSERT_TYPE (scm_is_string (str), str, SCM_ARG1, __FUNCTION__, "Paper_outputter"); - - return po->dump_string (str); -} - - -LY_DEFINE (ly_outputter_close, "ly:outputter-close", - 1, 0, 0, (SCM outputter), - "Close port of @var{outputter}.") -{ - Paper_outputter *po = unsmob_outputter (outputter); - SCM_ASSERT_TYPE (po, outputter, SCM_ARG1, __FUNCTION__, "Paper_outputter"); - - po->close (); - return SCM_UNSPECIFIED; -} - void Paper_outputter::close () { diff --git a/lily/paper-system-scheme.cc b/lily/paper-system-scheme.cc new file mode 100644 index 0000000000..46f984d2f8 --- /dev/null +++ b/lily/paper-system-scheme.cc @@ -0,0 +1,71 @@ +/* + paper-system-scheme.cc -- implement Paper_system bindings + + source file of the GNU LilyPond music typesetter + + (c) 2005 Han-Wen Nienhuys + +*/ + +#include "paper-system.hh" + +LY_DEFINE (ly_paper_system_height, "ly:paper-system-extent", + 2, 0, 0, (SCM system, SCM axis), + "Return the extent of @var{system}.") +{ + Paper_system *ps = unsmob_paper_system (system); + SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system"); + SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis"); + Axis ax = (Axis)scm_to_int (axis); + return ly_interval2scm (ps->to_stencil().extent (ax)); +} + + + +LY_DEFINE (ly_paper_system_title_p, "ly:paper-system-title?", + 1, 0, 0, (SCM system), + "Is @var{system} a title system?") +{ + Paper_system *ps = unsmob_paper_system (system); + SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system"); + return SCM_BOOL (ps->is_title ()); +} + +LY_DEFINE (ly_paper_system_number, "ly:paper-system-number", + 1, 0, 0, (SCM system), + "Return the number of @var{system}.") +{ + Paper_system *ps = unsmob_paper_system (system); + SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system"); + return scm_int2num (ps->number_); +} + +LY_DEFINE (ly_paper_system_break_before_penalty, "ly:paper-system-break-before-penalty", + 1, 0, 0, (SCM system), + "Return the score for page break after @var{system}.") +{ + Paper_system *ps = unsmob_paper_system (system); + SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system"); + return scm_int2num (int (ps->break_before_penalty ())); +} + +LY_DEFINE (ly_paper_system_stencil, "ly:paper-system-stencil", + 1, 0, 0, (SCM system), + "Return the height of @var{system}.") +{ + Paper_system *ps = unsmob_paper_system (system); + SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system"); + return ps->to_stencil ().smobbed_copy (); +} + + + +LY_DEFINE (ly_paper_system_staff_extent, "ly:paper-system-staff-extents", + 1, 0, 0, (SCM system), + "Return the top and bottom staff refpoint.") +{ + Paper_system *ps = unsmob_paper_system (system); + SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system"); + return ly_interval2scm (ps->staff_refpoints_); +} + diff --git a/lily/paper-system.cc b/lily/paper-system.cc index 49fe5cb0b7..d20b80cf9e 100644 --- a/lily/paper-system.cc +++ b/lily/paper-system.cc @@ -72,64 +72,3 @@ Paper_system::to_stencil () const { return stencil_; } - -LY_DEFINE (ly_paper_system_height, "ly:paper-system-extent", - 2, 0, 0, (SCM system, SCM axis), - "Return the extent of @var{system}.") -{ - Paper_system *ps = unsmob_paper_system (system); - SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system"); - SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis"); - Axis ax = (Axis)scm_to_int (axis); - return ly_interval2scm (ps->to_stencil().extent (ax)); -} - - - -LY_DEFINE (ly_paper_system_title_p, "ly:paper-system-title?", - 1, 0, 0, (SCM system), - "Is @var{system} a title system?") -{ - Paper_system *ps = unsmob_paper_system (system); - SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system"); - return SCM_BOOL (ps->is_title ()); -} - -LY_DEFINE (ly_paper_system_number, "ly:paper-system-number", - 1, 0, 0, (SCM system), - "Return the number of @var{system}.") -{ - Paper_system *ps = unsmob_paper_system (system); - SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system"); - return scm_int2num (ps->number_); -} - -LY_DEFINE (ly_paper_system_break_before_penalty, "ly:paper-system-break-before-penalty", - 1, 0, 0, (SCM system), - "Return the score for page break after @var{system}.") -{ - Paper_system *ps = unsmob_paper_system (system); - SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system"); - return scm_int2num (int (ps->break_before_penalty ())); -} - -LY_DEFINE (ly_paper_system_stencil, "ly:paper-system-stencil", - 1, 0, 0, (SCM system), - "Return the height of @var{system}.") -{ - Paper_system *ps = unsmob_paper_system (system); - SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system"); - return ps->to_stencil ().smobbed_copy (); -} - - - -LY_DEFINE (ly_paper_system_staff_extent, "ly:paper-system-staff-extents", - 1, 0, 0, (SCM system), - "Return the top and bottom staff refpoint.") -{ - Paper_system *ps = unsmob_paper_system (system); - SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system"); - return ly_interval2scm (ps->staff_refpoints_); -} - -- 2.39.2