Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Send MIDI note-off instead of note-on with velocity zero when:
- adding note to sequence
- playing sequence
  • Loading branch information
riban committed Oct 15, 2022
1 parent 21ff4ca commit 399a74d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
19 changes: 9 additions & 10 deletions zynlibs/zynseq/track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ SEQ_EVENT* Track::getEvent()
if(pEvent && pEvent->getPosition() == m_nNextStep)
{
//printf(" found event at %u\n", m_nNextStep);
seqEvent.msg.command = pEvent->getCommand() | m_nChannel;
// Found event at (or before) this step
if(m_nEventValue == pEvent->getValue2end())
{
Expand All @@ -175,22 +176,20 @@ SEQ_EVENT* Track::getEvent()
{
// Already processed start value
m_nEventValue = pEvent->getValue2end(); //!@todo Currently just move straight to end value but should interpolate for CC
if(seqEvent.msg.command == MIDI_NOTE_ON)
seqEvent.msg.command = MIDI_NOTE_OFF | m_nChannel;
seqEvent.time = m_nLastClockTime + pEvent->getDuration() * pPattern->getClocksPerStep() * m_dSamplesPerClock - 1; // -1 to send note-off one sample before next step
//printf("Scheduling note off. Event duration: %u, clocks per step: %u, samples per clock: %u\n", pEvent->getDuration(), pPattern->getClocksPerStep(), m_nSamplePerClock);
}
seqEvent.msg.value1 = pEvent->getValue1start();
seqEvent.msg.value2 = m_nEventValue;
//printf("Track::getEvent Scheduled event %u,%u,%u at %u currentTime: %u duration: %u clkperstep: %u sampleperclock: %f event position: %u\n", seqEvent.msg.command, seqEvent.msg.value1, seqEvent.msg.value2, seqEvent.time, m_nLastClockTime, pEvent->getDuration(), pPattern->getClocksPerStep(), m_dSamplesPerClock, pEvent->getPosition());
return &seqEvent;
}
else
{
m_nEventValue = -1;
m_nEventValue = -1;
// if(++m_nNextStep >= pPattern->getSteps())
// m_nNextStep = 0;
return NULL;
}
seqEvent.msg.command = pEvent->getCommand() | m_nChannel;
seqEvent.msg.value1 = pEvent->getValue1start();
seqEvent.msg.value2 = m_nEventValue;
//printf("Track::getEvent Scheduled event %u,%u,%u at %u currentTime: %u duration: %u clkperstep: %u sampleperclock: %f event position: %u\n", seqEvent.msg.command, seqEvent.msg.value1, seqEvent.msg.value2, seqEvent.time, m_nLastClockTime, pEvent->getDuration(), pPattern->getClocksPerStep(), m_dSamplesPerClock, pEvent->getPosition());
return &seqEvent;
return NULL;
}

uint32_t Track::updateLength()
Expand Down
2 changes: 1 addition & 1 deletion zynlibs/zynseq/zynseq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ void noteOffTimer(uint8_t note, uint8_t channel, uint32_t duration)
{
std::this_thread::sleep_for(std::chrono::milliseconds(duration));
MIDI_MESSAGE* pMsg = new MIDI_MESSAGE;
pMsg->command = MIDI_NOTE_ON | (channel & 0x0F);
pMsg->command = MIDI_NOTE_OFF | (channel & 0x0F);
pMsg->value1 = note;
pMsg->value2 = 0;
sendMidiMsg(pMsg);
Expand Down

2 comments on commit 399a74d

@jofemodo
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we sould replace all note-on with velocity 0 by note-off. I know that MIDI standard makes no difference and both should work, but some engines doesn't like it.
For instance, I get stucked notes when playing some SMFs with some engines, etc.

@riban-bw
Copy link
Contributor

@riban-bw riban-bw commented on 399a74d Oct 19, 2022

Choose a reason for hiding this comment

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

Agreed! I will do this. Background: I used note-on vel=0 to facilitate running status, a MIDI thinning mechanism. We don't implement this in Zynthian MIDI router (but we should) so a pragmatic fix is to just use note-off throughout. We should ideally implement running status and get "faulty (upstream) modules" fixed but that can be a longer term goal. (See issue: zynthian/zynthian-issue-tracking#727)

Please sign in to comment.