SCM split_list_;
- Stream_event *unisono_event_;
- Stream_event *solo_one_event_;
- Stream_event *solo_two_event_;
Stream_event *mmrest_event_;
enum Status
Part_combine_iterator::Part_combine_iterator ()
{
mmrest_event_ = 0;
- unisono_event_ = 0;
- solo_two_event_ = 0;
- solo_one_event_ = 0;
first_iter_ = 0;
second_iter_ = 0;
scm_gc_mark (first_iter_->self_scm ());
if (second_iter_)
scm_gc_mark (second_iter_->self_scm ());
- if (unisono_event_)
- scm_gc_mark (unisono_event_->self_scm ());
if (mmrest_event_)
scm_gc_mark (mmrest_event_->self_scm ());
- if (solo_one_event_)
- scm_gc_mark (solo_one_event_->self_scm ());
- if (solo_two_event_)
- scm_gc_mark (solo_two_event_->self_scm ());
}
void
if (playing_state_ != PLAYING_UNISONO
&& newstate == UNISONO)
{
- if (!unisono_event_)
- {
- unisono_event_ = new Stream_event
- (scm_call_1 (ly_lily_module_constant ("ly:make-event-class"),
- ly_symbol2scm ("unisono-event")));
- unisono_event_->unprotect ();
- }
-
- Context *out = (newpart == 2 ? second_iter_ : first_iter_)
- ->get_outlet ();
- out->event_source ()->broadcast (unisono_event_);
playing_state_ = PLAYING_UNISONO;
}
state_ = newstate;
kill_mmrest (CONTEXT_TWO);
kill_mmrest (CONTEXT_SHARED);
- if (playing_state_ != PLAYING_SOLO1)
- {
- if (!solo_one_event_)
- {
- solo_one_event_ = new Stream_event
- (scm_call_1 (ly_lily_module_constant ("ly:make-event-class"),
- ly_symbol2scm ("solo-one-event")));
- solo_one_event_->unprotect ();
- }
-
- first_iter_->get_outlet ()->event_source ()->broadcast (solo_one_event_);
- }
playing_state_ = PLAYING_SOLO1;
}
}
chosen_part_ = 2;
substitute_both (CONTEXT_NULL, CONTEXT_SOLO);
- if (playing_state_ != PLAYING_SOLO2)
- {
- if (!solo_two_event_)
- {
- solo_two_event_ = new Stream_event
- (scm_call_1 (ly_lily_module_constant ("ly:make-event-class"),
- ly_symbol2scm ("solo-two-event")));
- solo_two_event_->unprotect ();
- }
-
- second_iter_->get_outlet ()->event_source ()->broadcast (solo_two_event_);
- playing_state_ = PLAYING_SOLO2;
- }
+ playing_state_ = PLAYING_SOLO2;
}
}
(set! (ly:music-property arg 'parenthesize) #t))
arg)
+#(define (make-directed-part-combine-music
+ parser direction chord-range part1 part2
+ one-context-settings
+ two-context-settings
+ shared-context-settings)
+
+ (let ((pc-music (make-part-combine-music
+ parser (list part1 part2) direction chord-range)))
+ #{ \context Staff <<
+ \context Voice = "one" \with #one-context-settings {}
+ \context Voice = "two" \with #two-context-settings {}
+ \context Voice = "shared" \with #shared-context-settings {}
+ #pc-music
+ #(make-part-combine-marks
+ default-part-combine-mark-state-machine
+ (ly:music-property pc-music 'split-list))
+ >> #} ))
+
partcombine =
#(define-music-function (parser location chord-range part1 part2)
((number-pair? '(0 . 8)) ly:music? ly:music?)
and @var{part2} are combined into one voice where appropriate.
Optional @var{chord-range} sets the distance in steps between notes
that may be combined into a chord or unison.")
- #{ \context Staff <<
- \context Voice = "one" \with {
- \voiceOne
- \override DynamicLineSpanner.direction = #UP
- } {}
- \context Voice = "two" \with {
- \voiceTwo
- \override DynamicLineSpanner.direction = #DOWN
- } {}
- \context Voice = "shared" {}
- #(make-part-combine-music parser (list part1 part2) #f chord-range)
- >> #} )
+ (make-directed-part-combine-music parser #f chord-range part1 part2
+ #{ \with { \voiceOne \override DynamicLineSpanner.direction = #UP } #}
+ #{ \with { \voiceTwo \override DynamicLineSpanner.direction = #DOWN } #}
+ #{ #} ))
partcombineUp =
#(define-music-function (parser location chord-range part1 part2)
((number-pair? '(0 . 8)) ly:music? ly:music?)
(_i "Take the music in @var{part1} and @var{part2} and typeset so
that they share a staff with stems directed upward.")
- #{ \context Staff <<
- \context Voice = "one" \with {
- \voiceOne
- \override DynamicLineSpanner.direction = #UP
- } {}
- \context Voice = "two" \with {
- \voiceThree
- \override DynamicLineSpanner.direction = #UP
- } {}
- \context Voice = "shared" \with {
- \voiceOne
- \override DynamicLineSpanner.direction = #UP
- } {}
- #(make-part-combine-music parser (list part1 part2) UP chord-range)
- >> #} )
+ (make-directed-part-combine-music parser UP chord-range part1 part2
+ #{ \with { \voiceOne \override DynamicLineSpanner.direction = #UP } #}
+ #{ \with { \voiceThree \override DynamicLineSpanner.direction = #UP } #}
+ #{ \with { \voiceOne \override DynamicLineSpanner.direction = #UP } #} ))
partcombineDown =
#(define-music-function (parser location chord-range part1 part2)
((number-pair? '(0 . 8)) ly:music? ly:music?)
(_i "Take the music in @var{part1} and @var{part2} and typeset so
that they share a staff with stems directed downward.")
- #{ \context Staff <<
- \context Voice = "one" \with {
- \voiceFour
- \override DynamicLineSpanner.direction = #DOWN
- } {}
- \context Voice = "two" \with {
- \voiceTwo
- \override DynamicLineSpanner.direction = #DOWN
- } {}
- \context Voice = "shared" \with {
- \voiceTwo
- \override DynamicLineSpanner.direction = #DOWN
- } {}
- #(make-part-combine-music parser (list part1 part2) DOWN chord-range)
- >> #} )
+ (make-directed-part-combine-music parser DOWN chord-range part1 part2
+ #{ \with { \voiceFour \override DynamicLineSpanner.direction = #DOWN } #}
+ #{ \with { \voiceTwo \override DynamicLineSpanner.direction = #DOWN } #}
+ #{ \with { \voiceTwo \override DynamicLineSpanner.direction = #DOWN } #} ))
partcombineForce =
#(define-music-function (location parser type once) (boolean-or-symbol? boolean?)
(display result))
result))
+(define-public default-part-combine-mark-state-machine
+ ;; (current-state . ((split-state-event .
+ ;; (output-voice output-event next-state)) ...))
+ '((Initial . ((solo1 . (solo SoloOneEvent Solo1))
+ (solo2 . (solo SoloTwoEvent Solo2))
+ (unisono . (shared UnisonoEvent Unisono))))
+ (Solo1 . ((apart . (#f #f Initial))
+ (chords . (#f #f Initial))
+ (solo2 . (solo SoloTwoEvent Solo2))
+ (unisono . (shared UnisonoEvent Unisono))))
+ (Solo2 . ((apart . (#f #f Initial))
+ (chords . (#f #f Initial))
+ (solo1 . (solo SoloOneEvent Solo1))
+ (unisono . (shared UnisonoEvent Unisono))))
+ (Unisono . ((apart . (#f #f Initial))
+ (chords . (#f #f Initial))
+ (solo1 . (solo SoloOneEvent Solo1))
+ (solo2 . (solo SoloTwoEvent Solo2))))))
+
+(define-public (make-part-combine-marks state-machine split-list)
+ "Generate a sequence of part combiner events from a split list"
+
+ (define (get-state state-name)
+ (assq-ref state-machine state-name))
+
+ (let ((full-seq '()) ; sequence of { \context Voice = "x" {} ... }
+ (segment '()) ; sequence within \context Voice = "x" {...}
+ (prev-moment ZERO-MOMENT)
+ (prev-voice #f)
+ (state (get-state 'Initial)))
+
+ (define (commit-segment)
+ "Add the current segment to the full sequence and begin another."
+ (if (pair? segment)
+ (set! full-seq
+ (cons (make-music 'ContextSpeccedMusic
+ 'context-id (symbol->string prev-voice)
+ 'context-type 'Voice
+ 'element (make-sequential-music (reverse! segment)))
+ full-seq)))
+ (set! segment '()))
+
+ (define (handle-split split)
+ (let* ((moment (car split))
+ (action (assq-ref state (cdr split))))
+ (if action
+ (let ((voice (car action))
+ (part-combine-event (cadr action))
+ (next-state-name (caddr action)))
+ (if part-combine-event
+ (let ((dur (ly:moment-sub moment prev-moment)))
+ ;; start a new segment when the voice changes
+ (if (not (eq? voice prev-voice))
+ (begin
+ (commit-segment)
+ (set! prev-voice voice)))
+ (if (not (equal? dur ZERO-MOMENT))
+ (set! segment (cons (make-music 'SkipEvent
+ 'duration (make-duration-of-length dur)) segment)))
+ (set! segment (cons (make-music part-combine-event) segment))
+
+ (set! prev-moment moment)))
+ (set! state (get-state next-state-name))))))
+
+ (for-each handle-split split-list)
+ (commit-segment)
+ (make-sequential-music (reverse! full-seq))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;