Commit e6129d99 authored by jhammen's avatar jhammen
Browse files

do not repeat samples within a layer

parent b7298a82
......@@ -23,23 +23,23 @@ namespace handrumr {
class Instrument {
string mName;
int mKey;
uint8_t mKey;
Layer *mLayers;
int mLayerCount;
uint16_t mLayerCount;
public:
~Instrument() { delete[] mLayers; }
string &name() { return mName; }
void name(const string &n) { mName = n; }
int key() { return mKey; }
void key(int key) { mKey = key; }
void layers(Layer *layers, int count) {
uint8_t key() { return mKey; }
void key(uint8_t key) { mKey = key; }
void layers(Layer *layers, uint16_t count) {
mLayers = layers;
mLayerCount = count;
}
Layer *layers() { return mLayers; }
int layerCount() { return mLayerCount; }
uint16_t layerCount() { return mLayerCount; }
Sample *sample(int velocity) {
int index = 0;
uint16_t index = 0;
while(index < mLayerCount
&& mLayers[index].min() < velocity) { index++; }
if(index == 0) { index = 1; }
......
......@@ -21,22 +21,28 @@
class Layer
{
int mMin;
uint8_t mMin;
Sample *mSamples;
int mSampleCount;
uint16_t mSampleCount;
uint16_t last;
public:
Layer() : mMin(0) {}
Layer() : mMin(0), last(0) {}
~Layer() { delete[] mSamples; }
void min(int val) { mMin = val; }
int min() { return mMin; }
void samples(Sample *samples, int count) {
void min(uint8_t val) { mMin = val; }
uint8_t min() { return mMin; }
void samples(Sample *samples, uint16_t count) {
mSamples = samples;
mSampleCount = count;
}
Sample *samples() { return mSamples; }
int sampleCount() { return mSampleCount; }
uint16_t sampleCount() { return mSampleCount; }
Sample *sample() {
return &mSamples[rand() % mSampleCount];
uint16_t pick = rand() % (mSampleCount - 1);
if(pick == last) {
last = pick = mSampleCount - 1;
}
else { last = pick; }
return &mSamples[pick];
}
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment