Audacity Bug Summary
••• Introduction •••
••• Keywords •••
    Audacity 3.0.3 development began 19th April 2021

Audacity Bugzilla



Bug 1707 - MIDI Loop Play misses first few notes on looping.
MIDI Loop Play misses first few notes on looping.
Status: RESOLVED QUICKFIXED
Product: Audacity
Classification: Unclassified
Component: Audio IO
2.2.0
Per OS All
: P5 Repeatable
Assigned To: Default Assignee for New Bugs
: MIDI, test_single_OS
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2017-07-31 10:59 UTC by James Crook
Modified: 2018-08-20 11:46 UTC (History)
8 users (show)

See Also:
Steps To Reproduce:
1. Import MIDI (a single track) JamesBond theme tune shows the problem clearly. 2. Select a range that has notes at start and end, about 4s of audio. The problem shows clearly selecting exactly the range 30s to 34s 3. Loop play Notice that the early notes are played correctly, but on looping those same early notes at the start of the selection (first 3 seconds!) are not played.
Release Note:
First Git SHA:
Group: ---
Workaround:
Closed: 2018-08-20 00:00:00


Attachments
James Bond MIDI file. (45.69 KB, application/octet-stream)
2017-07-31 13:00 UTC, James Crook
Details

Note You need to log in before you can comment on or make changes to this bug.
Description James Crook 2017-07-31 10:59:24 UTC
Loop play seems to take several beats to recover playing on looping, missing out notes you would expect to hear played.
Comment 1 Peter Sampson 2017-07-31 11:13:29 UTC
(In reply to James Crook from comment #0)
I cannot reproduce this on either W10-CE audacity-win-ra45f3bb-2.2.0-alpha-22-jul-17
or macOS Sierra 10.12.6 6cb8852

On both I get perfect loop play

Are you sure you are selecting the beginning of the "notes" - if you select in the middle of a "note" and press play the "note on" command will not be sent (this is a known "feature").
Comment 2 James Crook 2017-07-31 13:00:19 UTC
Created attachment 731 [details]
James Bond MIDI file.

Loop play from 30s to 34s
Comment 3 James Crook 2017-07-31 13:02:09 UTC
*** STEPS UPDATED ***
I think I've narrowed the problem down a bit further as a result of comment 1.  MIDI does not send note off events for the notes it is abandoning at the end of the loop, and those can suppress the new notes coming in at the start.

I've attached the james bond theme tune so that you can try it out.  Yes I am sure of the problem.
Comment 4 James Crook 2017-07-31 18:33:05 UTC
It's specifically channel #8 that is causing the problem.  It's a 'drone' background.  Click 8 to mute it and the other loop play channels play once again.

One gets an even more marked effect buy selecting 31s to 34s.
Comment 5 Peter Sampson 2017-08-01 05:56:07 UTC
(In reply to James Crook from comment #2)
OK - yes I confirm I see this on W10 with your James Bond30-34 seconds
Comment 6 James Crook 2017-08-01 06:56:02 UTC
Added keyword MIDI.
Comment 7 Paul L 2017-08-03 06:57:16 UTC
AudioIO::AllNotesOff, with AUDIO_IO_GB_MIDI_WORKAROUND defined (as it is), looks like just the thing to fix this looping, although the original motivation for that code was to compensate for GarageBand not stopping the notes when it should have.

It uses simple tracking of notes-on that are not yet paired with notes-off.

The place to insert the call would be at the comment

         // jump back to beginning of loop

in AudioIO::OutputEvent.

James, will you try this out?

PRL
Comment 8 James Crook 2017-08-03 09:22:09 UTC
Re Comment#7

Didn't work.  The code reads:

   if (mNextEvent == &gAllNotesOff) {
      AllNotesOff();
      if (mPlayMode == gAudioIO->PLAY_LOOPED) {
         // jump back to beginning of loop
         mMidiLoopOffset += (mT1 - mT0);
         PrepareMidiIterator(false, mMidiLoopOffset);
      } else {
         mNextEvent = NULL;
      }
      return;
   }

Adding an extra AllNotesOff() makes no difference, as the code has just executed one. 

MIDI is 2.9 seconds in to the second time round the loop before it gets in to this 'if'.  So other code is setting mNextEvent to gAllNotesOff 2.9s too late.  Possibly (mistakenly) adding note-off events that are past mT1 to the queue?

I think I've got a fix for this and am checking I didn't break anything else in the process.  Will update this bug shortly.
Comment 10 Peter Sampson 2017-08-04 05:34:16 UTC
(In reply to James Crook from comment #9)
Tested on macOS Sierra 10.12.6 aae0c4c 04Aug17

Used the James bond theme MIDI file
Set snap to seconds
selected 30-34 seconds
Pressed Shift+Play button
Result - pefect looped playback

So I will mark this as ok on Mac.

I can't test on Windows as there are still no Windows nightlies!

------------------------------------

One oddity this testing has uncovered - which will probably need to be logged as a separate bug:  pressing Shift+Space does not invoke the loop play (it shows in the prefs as the shortcut and it works with auudio tracks),  Happend on Windows as well as Mac.
Comment 11 James Crook 2017-08-04 06:33:18 UTC
This has the test_single_OS keyword and was tested on Mac by Peter; Therefore RESOLVED FIXED

(I tested on Windows as part of fixing it, but that does not count as fixer does not close)