From 349358cce4b4fac42826dcf3786f27e1b0e919ff Mon Sep 17 00:00:00 2001 From: hanwen Date: Sat, 2 Oct 2004 10:12:09 +0000 Subject: [PATCH] * lily/parser.yy (command_element): reverse setting of instrumentTransposition * lily/pitch.cc (pitch_interval): rename. * lily/recording-group-engraver.cc (stop_translation_timestep): remove macrameing of accumulator and set_car/cdr. * lily/music.cc (transpose): fold Event::transpose() in. * lily/event.cc: remove Transpose. * lily/recording-group-engraver.cc: cleanup. * ly/music-functions-init.ly (displayMusic): add function. --- ChangeLog | 21 ++++++++ .../user/programming-interface.itely | 6 +++ lily/context.cc | 2 +- lily/duration.cc | 6 +-- lily/event.cc | 21 -------- lily/grob.cc | 2 +- lily/include/event.hh | 1 - lily/include/pitch.hh | 2 +- lily/key-performer.cc | 2 +- lily/lily-parser.cc | 2 +- lily/moment.cc | 2 +- lily/music.cc | 18 +++++++ lily/note-performer.cc | 2 +- lily/paper-book.cc | 2 +- lily/paper-system.cc | 2 +- lily/parser.yy | 6 ++- lily/pitch.cc | 10 ++-- lily/quote-iterator.cc | 6 ++- lily/recording-group-engraver.cc | 49 +++++-------------- lily/translator-scheme.cc | 2 +- ly/music-functions-init.ly | 3 ++ scm/define-context-properties.scm | 4 +- scm/music-functions.scm | 1 + scm/part-combiner.scm | 10 ++-- 24 files changed, 97 insertions(+), 85 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1136bf0850..6be1337a53 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,26 @@ 2004-10-02 Han-Wen Nienhuys + * scm/define-music-properties.scm (all-music-properties): change + meaning of instrumentTransposition. It is now the pitch played + that sounds as middle C. This means that instrumentTransposition + can be \transposed. + + * lily/parser.yy (command_element): reverse setting of + instrumentTransposition + + * lily/pitch.cc (pitch_interval): rename. + + * lily/recording-group-engraver.cc (stop_translation_timestep): + remove macrameing of accumulator and set_car/cdr. + + * lily/music.cc (transpose): fold Event::transpose() in. + + * lily/event.cc: remove Transpose. + + * lily/recording-group-engraver.cc: cleanup. + + * ly/music-functions-init.ly (displayMusic): add function. + * make/lilypond.fedora.spec.in: rename file. * lily/lily-lexer.cc (mark_smob): don't use ly_cdr() for getting diff --git a/Documentation/user/programming-interface.itely b/Documentation/user/programming-interface.itely index 6a2dae83c2..b5b6686270 100644 --- a/Documentation/user/programming-interface.itely +++ b/Documentation/user/programming-interface.itely @@ -298,6 +298,12 @@ saving keystrokes (@inputfileref{input/test,music-box.ly}) and exporting LilyPond input to other formats (@inputfileref{input/test,to-xml.ly}) +@cindex internal storage +@cindex @code{\displayMusic} +When writing a music function, it is often instructive to inspect how +a music expression is stored internally. This can be done with the +music function @code{\displayMusic} + @seealso @file{scm/music-functions.scm}, @file{scm/music-types.scm}, diff --git a/lily/context.cc b/lily/context.cc index 6b539519e1..fff7d6c749 100644 --- a/lily/context.cc +++ b/lily/context.cc @@ -364,7 +364,7 @@ Context::now_mom () const int Context::print_smob (SCM s, SCM port, scm_print_state *) { - Context *sc = (Context *) ly_cdr (s); + Context *sc = (Context *) SCM_CELL_WORD_1 (s); scm_puts ("#<", port); scm_puts (classname (sc), port); diff --git a/lily/duration.cc b/lily/duration.cc index fc52de4481..bf4e97bf73 100644 --- a/lily/duration.cc +++ b/lily/duration.cc @@ -93,7 +93,7 @@ IMPLEMENT_SIMPLE_SMOBS (Duration); int Duration::print_smob (SCM s, SCM port, scm_print_state *) { - Duration *r = (Duration *) ly_cdr (s); + Duration *r = (Duration *) SCM_CELL_WORD_1 (s); scm_puts ("#to_string ().to_str0 ()), port); @@ -105,8 +105,8 @@ Duration::print_smob (SCM s, SCM port, scm_print_state *) SCM Duration::equal_p (SCM a , SCM b) { - Duration *p = (Duration *) ly_cdr (a); - Duration *q = (Duration *) ly_cdr (b); + Duration *p = (Duration *) SCM_CELL_WORD_1 (a); + Duration *q = (Duration *) SCM_CELL_WORD_1 (b); bool eq = p->dots_ == q->dots_ && p->durlog_ == q->durlog_ diff --git a/lily/event.cc b/lily/event.cc index aad0bd2110..f47e335ace 100644 --- a/lily/event.cc +++ b/lily/event.cc @@ -30,27 +30,6 @@ Event::compress (Moment m) set_property ("duration", d ->compressed (m.main_part_).smobbed_copy ()); } -void -Event::transpose (Pitch delta) -{ - for (SCM s = this->get_property_alist (true); scm_is_pair (s); s = ly_cdr (s)) - { - SCM entry = ly_car (s); - SCM val = ly_cdr (entry); - - if (Pitch * p = unsmob_pitch (val)) - { - Pitch transposed = p->transposed (delta); - scm_set_cdr_x (entry, transposed.smobbed_copy ()); - - if (abs (transposed.get_alteration ()) > DOUBLE_SHARP) - { - warning (_f ("Transposition by %s makes alteration larger than two", - delta.to_string ())); - } - } - } -} Pitch Event::to_relative_octave (Pitch last) diff --git a/lily/grob.cc b/lily/grob.cc index 8e79dc76c6..a39ac0f412 100644 --- a/lily/grob.cc +++ b/lily/grob.cc @@ -617,7 +617,7 @@ Grob::mark_smob (SCM ses) int Grob::print_smob (SCM s, SCM port, scm_print_state *) { - Grob *sc = (Grob *) ly_cdr (s); + Grob *sc = (Grob *) SCM_CELL_WORD_1 (s); scm_puts ("#name ().to_str0 (), port); diff --git a/lily/include/event.hh b/lily/include/event.hh index 25e5210adc..0cf7b8f3b2 100644 --- a/lily/include/event.hh +++ b/lily/include/event.hh @@ -26,7 +26,6 @@ public: Event (); VIRTUAL_COPY_CONSTRUCTOR (Music, Event); virtual void compress (Moment); - virtual void transpose (Pitch); virtual Moment get_length () const; virtual Pitch to_relative_octave (Pitch); }; diff --git a/lily/include/pitch.hh b/lily/include/pitch.hh index db31415fad..bd0f209182 100644 --- a/lily/include/pitch.hh +++ b/lily/include/pitch.hh @@ -86,7 +86,7 @@ INSTANTIATE_COMPARE (Pitch, Pitch::compare); int compare (Array*, Array*); extern SCM pitch_less_proc; -Pitch interval (Pitch const & from , Pitch const & to ); +Pitch pitch_interval (Pitch const & from , Pitch const & to ); #endif /* MUSICAL_PITCH_HH */ diff --git a/lily/key-performer.cc b/lily/key-performer.cc index f27f0d85f4..531e33e820 100644 --- a/lily/key-performer.cc +++ b/lily/key-performer.cc @@ -57,7 +57,7 @@ Key_performer::create_audio_elements () SCM c_pitchlist = ly_transpose_key_alist (pitchlist, - interval (key_do, c_do).smobbed_copy ()); + pitch_interval (key_do, c_do).smobbed_copy ()); /* MIDI keys are too limited for lilypond scales. We check for minor scale and assume major otherwise. */ diff --git a/lily/lily-parser.cc b/lily/lily-parser.cc index 157a765165..aa131151ce 100644 --- a/lily/lily-parser.cc +++ b/lily/lily-parser.cc @@ -74,7 +74,7 @@ int Lily_parser::print_smob (SCM s, SCM port, scm_print_state*) { scm_puts ("#", port); return 1; diff --git a/lily/moment.cc b/lily/moment.cc index a7d0e8ddb9..72e138b4a9 100644 --- a/lily/moment.cc +++ b/lily/moment.cc @@ -46,7 +46,7 @@ Moment::mark_smob (SCM) int Moment::print_smob (SCM s, SCM port, scm_print_state *) { - Moment *r = (Moment *) ly_cdr (s); + Moment *r = (Moment *) SCM_CELL_WORD_1 (s); scm_puts ("#to_string (); diff --git a/lily/music.cc b/lily/music.cc index 9e980ea821..869bbbe3fd 100644 --- a/lily/music.cc +++ b/lily/music.cc @@ -169,6 +169,24 @@ Music::compress (Moment factor) void Music::transpose (Pitch delta) { + for (SCM s = this->get_property_alist (true); scm_is_pair (s); s = ly_cdr (s)) + { + SCM entry = ly_car (s); + SCM val = ly_cdr (entry); + + if (Pitch * p = unsmob_pitch (val)) + { + Pitch transposed = p->transposed (delta); + scm_set_cdr_x (entry, transposed.smobbed_copy ()); + + if (abs (transposed.get_alteration ()) > DOUBLE_SHARP) + { + warning (_f ("Transposition by %s makes alteration larger than two", + delta.to_string ())); + } + } + } + SCM elt = get_property ("element"); if (Music* m = unsmob_music (elt)) diff --git a/lily/note-performer.cc b/lily/note-performer.cc index 4d938dee65..0109b7bb33 100644 --- a/lily/note-performer.cc +++ b/lily/note-performer.cc @@ -50,7 +50,7 @@ Note_performer::create_audio_elements () if (Pitch * pitp = unsmob_pitch (pit)) { - Audio_note* p = new Audio_note (*pitp, n->get_length (), transposing); + Audio_note* p = new Audio_note (*pitp, n->get_length (), - transposing); Audio_element_info info (p, n); announce_element (info); notes_.push (p); diff --git a/lily/paper-book.cc b/lily/paper-book.cc index 6d2d6b328e..b557c83b92 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -53,7 +53,7 @@ Paper_book::mark_smob (SCM smob) int Paper_book::print_smob (SCM smob, SCM port, scm_print_state*) { - Paper_book *b = (Paper_book*) ly_cdr (smob); + Paper_book *b = (Paper_book*) SCM_CELL_WORD_1 (smob); scm_puts ("#<", port); scm_puts (classname (b), port); diff --git a/lily/paper-system.cc b/lily/paper-system.cc index 455bb9a667..b4dd9784e4 100644 --- a/lily/paper-system.cc +++ b/lily/paper-system.cc @@ -43,7 +43,7 @@ Paper_system::mark_smob (SCM smob) int Paper_system::print_smob (SCM smob, SCM port, scm_print_state*) { - Paper_system *p = (Paper_system*) ly_cdr (smob); + Paper_system *p = (Paper_system*) SCM_CELL_WORD_1 (smob); scm_puts ("#<", port); scm_puts (classname (p), port); scm_puts (" ", port); diff --git a/lily/parser.yy b/lily/parser.yy index 64bccc13f6..6d8d755366 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -1104,7 +1104,7 @@ Prefix_composite_music: Pitch from = *unsmob_pitch ($2); Pitch to = *unsmob_pitch ($3); - p->transpose (interval (from, to)); + p->transpose (pitch_interval (from, to)); $$->set_property ("element", p->self_scm ()); scm_gc_unprotect_object (p->self_scm ()); } @@ -1616,8 +1616,10 @@ command_element: $$->set_spot (THIS->here_input ()); } | TRANSPOSITION pitch { + Pitch middle_c; + Pitch sounds_as_c = pitch_interval (*unsmob_pitch ($2), middle_c); $$ = set_property_music (ly_symbol2scm ("instrumentTransposition"), - $2); + sounds_as_c.smobbed_copy()); $$->set_spot (THIS-> here_input ()); $$ = context_spec_music (ly_symbol2scm ("Staff"), SCM_UNDEFINED, $$, SCM_EOL); diff --git a/lily/pitch.cc b/lily/pitch.cc index 5dc46f97e6..6613dbdc49 100644 --- a/lily/pitch.cc +++ b/lily/pitch.cc @@ -149,7 +149,7 @@ Pitch::transpose (Pitch delta) } Pitch -interval (Pitch const & from , Pitch const & to ) +pitch_interval (Pitch const & from , Pitch const & to ) { int sound = to.quartertone_pitch () - from.quartertone_pitch (); Pitch pt (to.get_octave () - from.get_octave (), @@ -257,7 +257,7 @@ IMPLEMENT_SIMPLE_SMOBS (Pitch); int Pitch::print_smob (SCM s, SCM port, scm_print_state *) { - Pitch *r = (Pitch *) ly_cdr (s); + Pitch *r = (Pitch *) SCM_CELL_WORD_1 (s); scm_puts ("#to_string ().to_str0 ()), port); scm_puts (" >", port); @@ -267,8 +267,8 @@ Pitch::print_smob (SCM s, SCM port, scm_print_state *) SCM Pitch::equal_p (SCM a , SCM b) { - Pitch *p = (Pitch *) ly_cdr (a); - Pitch *q = (Pitch *) ly_cdr (b); + Pitch *p = (Pitch *) SCM_CELL_WORD_1 (a); + Pitch *q = (Pitch *) SCM_CELL_WORD_1 (b); bool eq = p->notename_ == q->notename_ && p->octave_ == q->octave_ @@ -394,7 +394,7 @@ LY_DEFINE (ly_pitch_diff, "ly:pitch-diff", SCM_ASSERT_TYPE (p, pitch, SCM_ARG1, __FUNCTION__, "Pitch"); SCM_ASSERT_TYPE (r, root, SCM_ARG2, __FUNCTION__, "Pitch"); - return interval (*r, *p).smobbed_copy (); + return pitch_interval (*r, *p).smobbed_copy (); } int diff --git a/lily/quote-iterator.cc b/lily/quote-iterator.cc index 961ae02f81..2b5fd91b83 100644 --- a/lily/quote-iterator.cc +++ b/lily/quote-iterator.cc @@ -164,6 +164,10 @@ Quote_iterator::process (Moment m) if (scm_is_pair (entry)) { Pitch * quote_pitch = unsmob_pitch (ly_cdar (entry)); + + /* + The pitch that sounds like central C + */ Pitch * me_pitch = unsmob_pitch (get_outlet ()->get_property ("instrumentTransposition")); for (SCM s = ly_cdr (entry); scm_is_pair (s); s = ly_cdr (s)) @@ -183,7 +187,7 @@ Quote_iterator::process (Moment m) if (me_pitch) mp = *me_pitch; - Pitch diff = interval (mp, qp); + Pitch diff = pitch_interval (qp, mp); SCM copy = ly_deep_mus_copy (mus->self_scm ()); mus = unsmob_music (copy); diff --git a/lily/recording-group-engraver.cc b/lily/recording-group-engraver.cc index 96c0ffc964..86137b8399 100644 --- a/lily/recording-group-engraver.cc +++ b/lily/recording-group-engraver.cc @@ -13,15 +13,15 @@ class Recording_group_engraver : public Engraver_group_engraver { - void start (); public: TRANSLATOR_DECLARATIONS (Recording_group_engraver); virtual bool try_music (Music *m); - virtual void start_translation_timestep (); + void add_music (SCM, SCM); virtual void stop_translation_timestep (); virtual void finalize (); virtual void initialize (); virtual void derived_mark () const; + SCM now_events_; SCM accumulator_; }; @@ -36,51 +36,31 @@ void Recording_group_engraver::initialize () { Engraver_group_engraver::initialize (); - start (); } Recording_group_engraver::Recording_group_engraver () { accumulator_ = SCM_EOL; + now_events_ = SCM_EOL; } void -Recording_group_engraver::start_translation_timestep () +Recording_group_engraver::add_music (SCM music, SCM success) { - Engraver_group_engraver::start_translation_timestep (); - - - /* - We have to do this both in initialize () and - start_translation_timestep (), since start_translation_timestep () - isn't called on the first time-step. - */ - start () ; + now_events_ = scm_cons (scm_cons (music, success), now_events_); } -void -Recording_group_engraver::start () -{ - if (!scm_is_pair (accumulator_)) - accumulator_ = scm_cons (SCM_EOL, SCM_EOL); - if (!scm_is_pair (ly_car (accumulator_))) - { - /* - Need to store transposition for every moment; transposition changes during pieces. - */ - scm_set_car_x (accumulator_, scm_cons (scm_cons (now_mom ().smobbed_copy (), - get_property ("instrumentTransposition")), - SCM_EOL)); - } -} void Recording_group_engraver::stop_translation_timestep () { Engraver_group_engraver::stop_translation_timestep (); - scm_set_cdr_x (accumulator_, scm_cons (ly_car (accumulator_), ly_cdr (accumulator_))); - scm_set_car_x (accumulator_, SCM_EOL); + accumulator_ = scm_acons (scm_cons (now_mom ().smobbed_copy (), + get_property ("instrumentTransposition")), + now_events_, + accumulator_); + now_events_ = SCM_EOL; } void @@ -91,8 +71,6 @@ Recording_group_engraver::finalize () if (ly_c_procedure_p (proc)) scm_call_2 (proc, context ()->self_scm (), ly_cdr (accumulator_)); - - accumulator_ = SCM_EOL; } bool @@ -100,12 +78,7 @@ Recording_group_engraver::try_music (Music *m) { bool retval = Translator_group::try_music (m); - SCM seq = ly_cdar (accumulator_); - seq = scm_cons (scm_cons (m->self_scm (), ly_bool2scm (retval)), - seq); - - scm_set_cdr_x (ly_car (accumulator_), seq); - + add_music (m->self_scm (), ly_bool2scm (retval)); return retval; } diff --git a/lily/translator-scheme.cc b/lily/translator-scheme.cc index a80b4c1661..35054fd0d2 100644 --- a/lily/translator-scheme.cc +++ b/lily/translator-scheme.cc @@ -36,7 +36,7 @@ LY_DEFINE (ly_translator_description, "ly:translator-description", int Translator::print_smob (SCM s, SCM port, scm_print_state *) { - Translator *me = (Translator*) ly_cdr (s); + Translator *me = (Translator*) SCM_CELL_WORD_1 (s); scm_puts ("#", port); diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly index 70755dff3b..07802d74b2 100644 --- a/ly/music-functions-init.ly +++ b/ly/music-functions-init.ly @@ -25,6 +25,9 @@ applycontext = #(def-music-function (location proc) (procedure?) 'origin location 'procedure proc)) +displayMusic = #(def-music-function (location music) (ly:music?) + (display-music music) + music) applyoutput = #(def-music-function (location proc) (procedure?) (make-music 'ApplyOutputEvent 'origin location diff --git a/scm/define-context-properties.scm b/scm/define-context-properties.scm index 3606f84226..7a9815b775 100644 --- a/scm/define-context-properties.scm +++ b/scm/define-context-properties.scm @@ -227,7 +227,9 @@ the @code{instr} property labels following lines.") (instrumentEqualizer ,procedure? " Function taking a string (instrument name), and returning a (@var{min} . @var{max}) pair of numbers for the loudness range of the instrument. ") - (instrumentTransposition ,ly:pitch? "Define the transposition of the instrument. This is used to transpose the MIDI output, and @code{\\quote}s.") + (instrumentTransposition ,ly:pitch? "Defines the transposition of +the instrument. Its value is the pitch that sounds like middle C. This +is used to transpose the MIDI output, and @code{\\quote}s.") (keyAccidentalOrder ,list? " Alist that defines in what order alterations should be printed. The format is (@var{name} diff --git a/scm/music-functions.scm b/scm/music-functions.scm index 3212e52159..4f4152a275 100644 --- a/scm/music-functions.scm +++ b/scm/music-functions.scm @@ -605,6 +605,7 @@ Syntax: )) ) + (if (string? quoted-name) (if (vector? quoted-vector) (set! (ly:music-property music 'quoted-events) quoted-vector) diff --git a/scm/part-combiner.scm b/scm/part-combiner.scm index 5cc2cfb8d2..e206d0d121 100644 --- a/scm/part-combiner.scm +++ b/scm/part-combiner.scm @@ -193,6 +193,8 @@ Voice-state objects (set! part-combine-listener x)) (define-public (notice-the-events-for-pc context lst) + "add CONTEXT-ID, EVENT list to NOTICED variable." + (set! noticed (acons (ly:context-id context) lst noticed))) (define-public (make-part-combine-music music-list) @@ -508,9 +510,11 @@ the mark when there are no spanners active." (let* ((tab (eval 'musicQuotes (current-module) )) (context (ly:run-translator (context-spec-music mus 'Voice) part-combine-listener)) - (evs (last-pair noticed))) - (if (pair? evs) + (first-voice-handle (last-pair noticed))) + + (if (pair? first-voice-handle) (hash-set! tab name ;; cdr : skip name string - (list->vector (reverse! (cdar evs) '())))))) + (list->vector (reverse! (cdar first-voice-handle) + '())))))) -- 2.39.5