Skip to content

Commit

Permalink
Add support for SFZ seq_position opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Bullock committed Sep 28, 2017
1 parent 6c802bb commit 9f72ce7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
4 changes: 4 additions & 0 deletions module/SFZero/SFZero/SFZReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ void SFZReader::read(const char* text, unsigned int length)
buildingRegion->loop_start = (unsigned long) value.getLargeIntValue();
else if (opcode == "loop_end" || opcode == "loopend")
buildingRegion->loop_end = (unsigned long) value.getLargeIntValue();
else if (opcode == "seq_length")
buildingRegion->seq_length = value.getIntValue();
else if (opcode == "seq_position")
buildingRegion->seq_position = value.getIntValue();
else if (opcode == "transpose")
buildingRegion->transpose = value.getIntValue();
else if (opcode == "tune")
Expand Down
7 changes: 7 additions & 0 deletions module/SFZero/SFZero/SFZRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ void SFZRegion::clear()
ampeg_veltrack.clearMod();
modeg.clear();
initialFilterFc = 0x7FFF;
seq_length = 1;
seq_position = 1;
seq_count = 1; // seq_count counts from 1 <= seq_length
}


Expand Down Expand Up @@ -170,6 +173,10 @@ void SFZRegion::sf2ToSFZ()
initialFilterQ = 0;
}

void SFZRegion::incrementSeqCount()
{
seq_count = (seq_count % seq_length) + 1;
}

void SFZRegion::dump()
{
Expand Down
19 changes: 16 additions & 3 deletions module/SFZero/SFZero/SFZRegion.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <math.h>

#include "SFZDebug.h"

namespace SFZero {

class SFZSample;
Expand Down Expand Up @@ -39,14 +41,21 @@ class SFZRegion {
void addForSF2(SFZRegion* other);
void sf2ToSFZ();
void dump();
void incrementSeqCount();

bool matches(unsigned char note, unsigned char velocity, Trigger _trigger) {
return
bool matches(unsigned char note, unsigned char velocity, Trigger _trigger, bool use_seq_count = false) {
bool match =
note >= lokey && note <= hikey &&
velocity >= lovel && velocity <= hivel &&
(_trigger == trigger ||
(trigger == attack && (_trigger == first || _trigger == legato)));
}

if (match && use_seq_count) {
if (seq_count != seq_position) match = false;
incrementSeqCount();
}
return match;
}

SFZSample* sample;
unsigned char lokey, hikey;
Expand All @@ -64,6 +73,7 @@ class SFZRegion {
int tune;
int pitch_keycenter, pitch_keytrack;
int bend_up, bend_down;
int seq_length, seq_position;

float volume, pan;
float amp_veltrack;
Expand All @@ -79,6 +89,9 @@ class SFZRegion {
static inline double timecents2Secs(double timecents) { return pow(2.0, timecents / 1200.0); }
static inline float timecents2Secs(float timecents) { return powf(2.0f, timecents / 1200.0f); }
static inline float cents2Hertz(float cents) { return 8.176f * powf(2.0f, cents / 1200.0f); }

private:
int seq_count;
};

}
Expand Down
2 changes: 1 addition & 1 deletion module/SFZero/SFZero/SFZSynth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void SFZSynth::noteOn(int midiChannel, int midiNoteNumber, float velocity)
int numRegions = sound->getNumRegions();
for (i = 0; i < numRegions; ++i) {
SFZRegion* region = sound->regionAt(i);
if (region->matches((unsigned char)midiNoteNumber, (unsigned char)midiVelocity, trigger)) {
if (region->matches((unsigned char)midiNoteNumber, (unsigned char)midiVelocity, trigger, true)) {
SFZVoice* voice =
dynamic_cast<SFZVoice*>(
findFreeVoice(
Expand Down

0 comments on commit 9f72ce7

Please sign in to comment.