void initADSR(struct ADSR* adsr, unsigned a, unsigned d, float s, unsigned r){ setSustain(adsr, s); setAttack(adsr, a); setDecay(adsr, d); setRelease(adsr, r); adsr->index = 0; adsr->level = 0.00000000001f; }
//============================================================================== ADSRComponent::ADSRComponent () { addAndMakeVisible (attackSlider = new Slider ("Attack slider")); attackSlider->setTooltip (TRANS("Attack")); attackSlider->setRange (5, 15000, 0); attackSlider->setSliderStyle (Slider::LinearVertical); attackSlider->setTextBoxStyle (Slider::TextBoxBelow, false, 80, 20); attackSlider->addListener (this); attackSlider->setSkewFactor (0.4); addAndMakeVisible (decaySlider = new Slider (String::empty)); decaySlider->setTooltip (TRANS("Decay")); decaySlider->setRange (5, 15000, 0); decaySlider->setSliderStyle (Slider::LinearVertical); decaySlider->setTextBoxStyle (Slider::TextBoxBelow, false, 80, 20); decaySlider->addListener (this); decaySlider->setSkewFactor (0.4); addAndMakeVisible (sustainSlider = new Slider (String::empty)); sustainSlider->setTooltip (TRANS("Sustain")); sustainSlider->setRange (0, 1, 0); sustainSlider->setSliderStyle (Slider::LinearVertical); sustainSlider->setTextBoxStyle (Slider::TextBoxBelow, false, 80, 20); sustainSlider->addListener (this); addAndMakeVisible (releaseSlider = new Slider (String::empty)); releaseSlider->setTooltip (TRANS("Release")); releaseSlider->setRange (5, 15000, 0); releaseSlider->setSliderStyle (Slider::LinearVertical); releaseSlider->setTextBoxStyle (Slider::TextBoxBelow, false, 80, 20); releaseSlider->addListener (this); releaseSlider->setSkewFactor (0.4); addAndMakeVisible (attackLabel = new Label (String::empty, TRANS("A"))); attackLabel->setFont (Font (15.00f, Font::bold)); attackLabel->setJustificationType (Justification::centred); attackLabel->setEditable (false, false, false); attackLabel->setColour (TextEditor::textColourId, Colours::black); attackLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000)); addAndMakeVisible (decayLabel = new Label (String::empty, TRANS("D"))); decayLabel->setFont (Font (15.00f, Font::bold)); decayLabel->setJustificationType (Justification::centred); decayLabel->setEditable (false, false, false); decayLabel->setColour (TextEditor::textColourId, Colours::black); decayLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000)); addAndMakeVisible (sustainLabel = new Label (String::empty, TRANS("S"))); sustainLabel->setFont (Font (15.00f, Font::bold)); sustainLabel->setJustificationType (Justification::centred); sustainLabel->setEditable (false, false, false); sustainLabel->setColour (TextEditor::textColourId, Colours::black); sustainLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000)); addAndMakeVisible (releaseLabel = new Label (String::empty, TRANS("R"))); releaseLabel->setFont (Font (15.00f, Font::bold)); releaseLabel->setJustificationType (Justification::centred); releaseLabel->setEditable (false, false, false); releaseLabel->setColour (TextEditor::textColourId, Colours::black); releaseLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000)); //[UserPreSize] //[/UserPreSize] setSize (600, 400); //[Constructor] You can add your own custom stuff here.. setAttack(5); setDecay(5); setSustain(1); setRelease(5); //[/Constructor] }
bool MidiArp::handleEvent(MidiEvent inEv, int tick, int keep_rel) { int bufPtr, index; if (inEv.channel != chIn) return(true); if ((inEv.type == EV_CONTROLLER) && (inEv.data == CT_FOOTSW)) { setSustain((inEv.value == 127), tick); return(false); } if (inEv.type != EV_NOTEON) return(true); if (((inEv.data < indexIn[0]) || (inEv.data > indexIn[1])) || ((inEv.value < rangeIn[0]) || (inEv.value > rangeIn[1]))) { return(true); } if (inEv.value) { // This is a NOTE ON event if (!getPressedNoteCount() || trigLegato) { purgeLatchBuffer(); if (restartByKbd) restartFlag = true; if (trigByKbd) { initArpTick(tick); // if we have been triggered, remove pending release notes if (release_time > 0) { for (int l1 = 0; l1 < noteCount; l1++) { if (notes[noteBufPtr][3][l1]) removeNote(¬es[noteBufPtr][0][l1], -1, 0); releaseNoteCount--; } } } } // modify buffer that is not accessed by arpeggio output bufPtr = (noteBufPtr) ? 0 : 1; if (!noteCount || (inEv.data > notes[bufPtr][0][noteCount - 1])) index = noteCount; else { index = 0; while (inEv.data > notes[bufPtr][0][index]) index++; for (int l3 = 0; l3 < 4; l3++) { for (int l2 = noteCount; l2 > index; l2--) { notes[bufPtr][l3][l2] = notes[bufPtr][l3][l2 - 1]; } } } notes[bufPtr][0][index] = inEv.data; notes[bufPtr][1][index] = inEv.value; notes[bufPtr][2][index] = tick; notes[bufPtr][3][index] = 0; noteCount++; if (repeatPatternThroughChord == 2) noteOfs = noteCount - 1; if (trigByKbd && ((noteCount == 1) || trigLegato)) { nextTick = tick + 2; //schedDelayTicks; gotKbdTrig = true; } } else { // This is a NOTE OFF event // modify buffer that is not accessed by arpeggio output bufPtr = (noteBufPtr) ? 0 : 1; if (!noteCount) { return(false); } if (sustain) { sustainBuffer.replace(sustainBufferCount, inEv.data); sustainBufferCount++; return(false); } if (latch_mode) { latchBuffer.replace(latchBufferCount, inEv.data); latchBufferCount++; if (latchBufferCount != noteCount) { if ((uint)tick > (uint)(lastLatchTick + 30) && (latchBufferCount > 1)) purgeLatchBuffer(); lastLatchTick = tick; } return(false); } if ((!keep_rel) || (!release_time)) { //definitely remove from buffer if (inEv.data == notes[bufPtr][0][noteCount - 1]) { //note is on top of buffer: only decrement noteCount noteCount--; if (repeatPatternThroughChord == 2) noteOfs = noteCount - 1; } else { //note is not on top: take out the note and pull down all above index = 0; while ((index < noteCount) && (inEv.data > notes[bufPtr][0][index])) index++; deleteNoteAt(index, bufPtr); } } else tagAsReleased(inEv.data, tick, bufPtr); } copyNoteBuffer(); return(false); }