2004-10-02 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ * 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
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},
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);
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 ("#<Duration ", port);
scm_display (scm_makfrom0str (r->to_string ().to_str0 ()), port);
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_
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)
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 ("#<Grob ", port);
scm_puts ((char *) sc->name ().to_str0 (), port);
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);
};
int compare (Array<Pitch>*, Array<Pitch>*);
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 */
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. */
Lily_parser::print_smob (SCM s, SCM port, scm_print_state*)
{
scm_puts ("#<my_lily_parser ", port);
- Lily_parser *parser = (Lily_parser*) ly_cdr (s);
+ Lily_parser *parser = (Lily_parser*) SCM_CELL_WORD_1 (s);
(void) parser;
scm_puts (" >", port);
return 1;
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 ("#<Mom ", port);
String str = r->to_string ();
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))
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);
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);
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);
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 ());
}
$$->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);
}
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 (),
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 ("#<Pitch ", port);
scm_display (scm_makfrom0str (r->to_string ().to_str0 ()), port);
scm_puts (" >", port);
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_
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
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))
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);
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_;
};
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
if (ly_c_procedure_p (proc))
scm_call_2 (proc, context ()->self_scm (), ly_cdr (accumulator_));
-
- accumulator_ = SCM_EOL;
}
bool
{
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;
}
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 ("#<Translator ", port);
scm_puts (classname (me), port);
scm_puts (" >", port);
'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
(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}
))
)
+
(if (string? quoted-name)
(if (vector? quoted-vector)
(set! (ly:music-property music 'quoted-events) quoted-vector)
(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)
(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)
+ '()))))))