From 0491b3a22f6914606e04ed04bce6320c1daa7ed0 Mon Sep 17 00:00:00 2001 From: kylewilk Date: Sun, 20 Nov 2022 14:12:42 -0500 Subject: [PATCH 1/2] Add check for extra rest duration --- client/transmitter/osc.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/client/transmitter/osc.go b/client/transmitter/osc.go index 48fb8579..e0f89faa 100644 --- a/client/transmitter/osc.go +++ b/client/transmitter/osc.go @@ -311,7 +311,7 @@ func (oe OSCTransmitter) ScoreToOSCBundle( // of the score. scoreLength := 0.0 - for _, event := range events { + for index, event := range events { eventOffset := event.EventOffset() // Filter out events before the `--from` time marking / marker, when @@ -327,6 +327,21 @@ func (oe OSCTransmitter) ScoreToOSCBundle( switch event := event.(type) { case model.NoteEvent: + + // Add offset for any rests done after the last Note + // Additional rests at the end of a code sequence create a timing mismatch + // between Part.CurrentOffset and this note event's Offset + duration + // Part.CurrentOffset should equal Note Offset + Note Duration, so this statement + // Increments Note Duration so that they become equal + restOffset := int32(0) + if index == len(events)-1 { + lastEvent := event + // Last event offset + duration must equal score.duration + currNoteEnd := int32(math.Round(lastEvent.Duration)) + int32(lastEvent.EventOffset()) + partOffset := int32(score.CurrentParts[len(score.CurrentParts)-1].CurrentOffset) + restOffset = partOffset - currNoteEnd + } + track := tracks[event.Part] // We subtract `startOffset` from the offset so that when the `--from` @@ -383,7 +398,7 @@ func (oe OSCTransmitter) ScoreToOSCBundle( track, offsetRounded, event.MidiNote, - int32(math.Round(event.Duration)), + int32(math.Round(event.Duration)+float64(restOffset)), int32(math.Round(event.AudibleDuration)), int32(math.Round(event.Volume*127)), )) From 86dd107d6e28de842939dc28c98d7a13e286c507 Mon Sep 17 00:00:00 2001 From: kylewilk Date: Mon, 21 Nov 2022 09:02:51 -0500 Subject: [PATCH 2/2] Change use event part instead of last score part for repl patch --- client/transmitter/osc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/transmitter/osc.go b/client/transmitter/osc.go index e0f89faa..3656a1d3 100644 --- a/client/transmitter/osc.go +++ b/client/transmitter/osc.go @@ -338,7 +338,7 @@ func (oe OSCTransmitter) ScoreToOSCBundle( lastEvent := event // Last event offset + duration must equal score.duration currNoteEnd := int32(math.Round(lastEvent.Duration)) + int32(lastEvent.EventOffset()) - partOffset := int32(score.CurrentParts[len(score.CurrentParts)-1].CurrentOffset) + partOffset := int32(lastEvent.Part.CurrentOffset) restOffset = partOffset - currNoteEnd }