From 61ae0f044836f770237d0f4efb1c92b03f68c595 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Tue, 15 Apr 2003 23:34:16 +0000 Subject: [PATCH] (process_music): use octavation (a number) instead of original-pitch to store inversions. This fixes a problem with transposed chords with inversions. --- ChangeLog | 6 ++++++ aclocal.m4 | 3 +++ lily/event.cc | 5 +++++ lily/new-chord-name-engraver.cc | 17 +++++++++++++---- lily/parser.yy | 1 + lily/relative-octave-music.cc | 10 ++++++++++ scm/chord-entry.scm | 5 ++++- scm/music-property-description.scm | 5 +++-- 8 files changed, 45 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6762052362..f3ef6fdd0d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-04-16 Han-Wen Nienhuys + + * lily/new-chord-name-engraver.cc (process_music): use octavation + (a number) instead of original-pitch to store inversions. This + fixes a problem with transposed chords with inversions. + 2003-04-14 Jan Nieuwenhuizen * stepmake/aclocal.m4: Include compile fix for broken flex, as diff --git a/aclocal.m4 b/aclocal.m4 index eae65025b5..c1f4aee49b 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -1,4 +1,7 @@ dnl aclocal.m4 -*-shell-script-*- +dnl WARNING WARNING WARNING +dnl do not edit! this is aclocal.m4, generated from /home/hanwen/usr/src/lilypond/stepmake/aclocal.m4 +dnl aclocal.m4 -*-shell-script-*- dnl StepMake subroutines for configure.in diff --git a/lily/event.cc b/lily/event.cc index 944aa5417f..fd86b435ef 100644 --- a/lily/event.cc +++ b/lily/event.cc @@ -33,6 +33,11 @@ Event::compress (Moment m) void Event::transpose (Pitch delta) { + /* + TODO: should change music representation such that + _all_ pitch values are transposed automatically. + */ + Pitch *p = unsmob_pitch (get_mus_property ("pitch")); if (!p) return ; diff --git a/lily/new-chord-name-engraver.cc b/lily/new-chord-name-engraver.cc index 00a7215e55..65620defe6 100644 --- a/lily/new-chord-name-engraver.cc +++ b/lily/new-chord-name-engraver.cc @@ -65,7 +65,10 @@ New_chord_name_engraver::process_music () for (int i =0 ; i < notes_.size (); i++) { Music *n = notes_[i]; - SCM p = n->get_mus_property ("pitch");; + SCM p = n->get_mus_property ("pitch"); + if (!unsmob_pitch (p)) + continue; + if (n->get_mus_property ("inversion") == SCM_BOOL_T) { inversion_event = n; @@ -79,9 +82,15 @@ New_chord_name_engraver::process_music () if (inversion_event) { - SCM op = inversion_event->get_mus_property ("original-pitch"); - if (unsmob_pitch (op)) - pitches= gh_cons (op, pitches); + SCM oct = inversion_event->get_mus_property ("octavation"); + if (gh_number_p (oct)) + { + Pitch *p = unsmob_pitch (inversion_event->get_mus_property ("pitch")); + int octavation = gh_scm2int (oct); + Pitch orig = p->transposed (Pitch (-octavation, 0,0)); + + pitches= gh_cons (orig.smobbed_copy (), pitches); + } else programming_error ("Inversion does not have original pitch."); } diff --git a/lily/parser.yy b/lily/parser.yy index f7f13c4eb0..2373c83d12 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -1027,6 +1027,7 @@ relative_music: $$->set_mus_property ("element", p->self_scm ()); scm_gc_unprotect_object (p->self_scm ()); + $$->set_mus_property ("last-pitch", p->to_relative_octave (pit).smobbed_copy ()); } diff --git a/lily/relative-octave-music.cc b/lily/relative-octave-music.cc index b57f2a2ef6..ad2350fa39 100644 --- a/lily/relative-octave-music.cc +++ b/lily/relative-octave-music.cc @@ -13,6 +13,16 @@ Pitch Relative_octave_music::to_relative_octave (Pitch) { + /* + ugh: last-pitch should be junked. + + Change this for lilypond 2.0. When you do, + then B should start where A left off. + + \relative { A \relative { ...} B } + + */ + return * unsmob_pitch (get_mus_property ("last-pitch")); } diff --git a/scm/chord-entry.scm b/scm/chord-entry.scm index 52643961ba..7c9bbfe839 100644 --- a/scm/chord-entry.scm +++ b/scm/chord-entry.scm @@ -244,7 +244,10 @@ DURATION, and INVERSION." (if inv-note (begin (ly:set-mus-property! inv-note 'inversion #t) - (ly:set-mus-property! inv-note 'original-pitch original-inv-pitch) + (ly:set-mus-property! inv-note 'octavation + (- (ly:pitch-octave inversion) + (ly:pitch-octave original-inv-pitch)) + ) (set! nots (cons inv-note nots)))) (make-event-chord nots) diff --git a/scm/music-property-description.scm b/scm/music-property-description.scm index cc43d7d106..8f04d64b96 100644 --- a/scm/music-property-description.scm +++ b/scm/music-property-description.scm @@ -58,8 +58,9 @@ TODO: consider making type into symbol ") (music-property-description 'name symbol? "Name of this music object") (music-property-description 'numerator integer? "numerator of a time signature") (music-property-description 'once boolean? "Apply this operation only during one time step?") -(music-property-description 'original-pitch ly:pitch? - "Pitch before inversion. Needed to reconstruct chord name.") +(music-property-description 'octavation integer? + "This pitch was octavated by how many octaves? +For chord inversions, this is negative.") (music-property-description 'origin ly:input-location? "where was this piece of music defined?") (music-property-description 'penalty number? "Penalty for break hint.") (music-property-description 'pitch ly:pitch? "the pitch of this note") -- 2.39.2