Skip to content

Commit adbc788

Browse files
author
tlr
committed
polyphony fix timestamps of notes pressed at the same time
1 parent 0c09504 commit adbc788

5 files changed

Lines changed: 16 additions & 14 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
66

77
option(BUILD_STANDALONE "Build Standalone plugin format" ON) # Allow overriding from the command line
88

9-
project(RipplerX VERSION 1.5.17)
9+
project(RipplerX VERSION 1.5.18)
1010

1111
add_compile_definitions(PROJECT_VERSION="${PROJECT_VERSION}")
1212
set(CMAKE_CXX_STANDARD 17)

src/PluginProcessor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,15 +437,15 @@ void RipplerXAudioProcessor::onNote(MIDIMsg msg)
437437
auto vel_mallet_stiff = (double)params.getRawParameterValue("vel_mallet_stiff")->load();
438438
auto malletFreq = fmax(100.0, fmin(5000.0, exp(log(mallet_stiff) + msg.vel / 127.0 * vel_mallet_stiff * 2.0 * (log(5000.0) - log(100.0)))));
439439

440-
voice.trigger(srate, msg.note, msg.vel / 127.0, mallet_type, malletFreq, mallet_ktrack, skip_fadeout, mtsClientPtr);
440+
voice.trigger(++note_press_count, srate, msg.note, msg.vel / 127.0, mallet_type, malletFreq, mallet_ktrack, skip_fadeout, mtsClientPtr);
441441
}
442442

443443
void RipplerXAudioProcessor::offNote(MIDIMsg msg)
444444
{
445445
for (int i = 0; i < polyphony; ++i) {
446446
Voice& voice = *voices[i];
447447
if (voice.note == msg.note && !voice.isRelease) {
448-
voice.release();
448+
voice.release(++note_release_count);
449449
}
450450
}
451451
}

src/PluginProcessor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class RipplerXAudioProcessor : public juce::AudioProcessor, public juce::AudioP
5656
MTSClient *mtsClientPtr;
5757
MalletType l_mallet_type = MalletType::kImpulse; // used to detect mallet type changes
5858
bool sustainPedal = false;
59+
uint64_t note_press_count = 0;
60+
uint64_t note_release_count = 0;
5961
// pitch bend
6062
double bendStep = 0.1;
6163
double startBend = 1.0;

src/dsp/Voice.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ double Voice::note2freq(int _note, MTSClient *mts)
1515
}
1616

1717
// Triggers mallet and noise generator
18-
void Voice::trigger(double _srate, int _note, double _vel, MalletType _malletType, double _malletFreq, double _mallet_ktrack, bool skip_fadeout, MTSClient* mts)
18+
void Voice::trigger(uint64_t timestamp, double _srate, int _note, double _vel, MalletType _malletType, double _malletFreq, double _mallet_ktrack, bool skip_fadeout, MTSClient* mts)
1919
{
2020
srate = _srate;
2121
malletType = _malletType;
@@ -26,6 +26,10 @@ void Voice::trigger(double _srate, int _note, double _vel, MalletType _malletTyp
2626
newFreq = note2freq(newNote, mts);
2727
malletKtrack = _mallet_ktrack;
2828

29+
isRelease = false;
30+
isPressed = true;
31+
pressed_ts = timestamp;
32+
2933
// fade out active voice before re-triggering
3034
if (skip_fadeout) {
3135
triggerStart(false);
@@ -57,9 +61,6 @@ void Voice::triggerStart(bool reset)
5761
resA.clear();
5862
resB.clear();
5963
}
60-
isRelease = false;
61-
isPressed = true;
62-
pressed_ts = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
6364
note = newNote;
6465
vel = newVel;
6566
freq = newFreq;
@@ -71,11 +72,11 @@ void Voice::triggerStart(bool reset)
7172
updateResonators();
7273
}
7374

74-
void Voice::release()
75+
void Voice::release(uint64_t timestamp)
7576
{
7677
isRelease = true;
7778
isPressed = false;
78-
release_ts = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
79+
release_ts = timestamp;
7980
noise.release();
8081
updateResonators();
8182
}

src/dsp/Voice.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#pragma once
88
#include <array>
9-
#include <chrono>
109
#include "Mallet.h"
1110
#include "Noise.h"
1211
#include "Resonator.h"
@@ -25,10 +24,10 @@ class Voice
2524
~Voice() {}
2625

2726
double note2freq(int _note, MTSClient *mts);
28-
void trigger(double srate, int _note, double vel, MalletType malletType, double malletFreq, double malletKTrack, bool skip_fade, MTSClient *mts);
27+
void trigger(uint64_t timestamp, double srate, int _note, double vel, MalletType malletType, double malletFreq, double malletKTrack, bool skip_fade, MTSClient *mts);
2928
void triggerStart(bool reset);
3029
double fadeOut();
31-
void release();
30+
void release(uint64_t timestamp);
3231
void clear();
3332
void setPitch(double a_coarse, double b_coarse, double a_fine, double b_fine, double pitch_bend);
3433
void setRatio(double _a_ratio, double _b_ratio);
@@ -54,8 +53,8 @@ class Voice
5453
double srate = 44100.0;
5554
double a_ratio = 1.0; // used to recalculate models
5655
double b_ratio = 1.0; // used to recalculate models
57-
int64_t pressed_ts = 0; // timestamp used to order notes
58-
int64_t release_ts = 0; // timestamp used to order notes
56+
uint64_t pressed_ts = 0; // timestamp used to order notes
57+
uint64_t release_ts = 0; // timestamp used to order notes
5958

6059
// used to fade out on repeat notes
6160
bool isFading = false;

0 commit comments

Comments
 (0)