Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for extra rest duration #462

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions client/transmitter/osc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Copy link
Member

@daveyarwood daveyarwood Nov 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think selecting the last Part in the score is potentially error-prone, as it might not be the Part that the note belongs to. I think lastEvent.Part is probably what we want here.

restOffset = partOffset - currNoteEnd
}

track := tracks[event.Part]

// We subtract `startOffset` from the offset so that when the `--from`
Expand Down Expand Up @@ -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)),
))
Expand Down