mirror of
https://github.com/yokemura/Magical8bitPlug2.git
synced 2025-07-17 11:04:16 -04:00
Legato
This commit is contained in:
@ -16,7 +16,9 @@
|
||||
// The base for pulse/triangle (Abstract)
|
||||
//
|
||||
//---------------------------------------------
|
||||
TonalVoice::TonalVoice (SettingRefs* sRefs) : BaseVoice (sRefs) {}
|
||||
TonalVoice::TonalVoice (SettingRefs* sRefs) : BaseVoice (sRefs) {
|
||||
// testArpeggioNotes();
|
||||
}
|
||||
|
||||
void TonalVoice::startNote (int midiNoteNumber, float velocity, SynthesiserSound*, int currentPitchBendPosition)
|
||||
{
|
||||
@ -30,6 +32,12 @@ void TonalVoice::startNote (int midiNoteNumber, float velocity, SynthesiserSound
|
||||
float time = * (settingRefs->sweepTime);
|
||||
currentAutoBendAmount = iniPitch;
|
||||
autoBendDelta = -1.0 * iniPitch / (time * getSampleRate());
|
||||
|
||||
portamentoTime = 0;
|
||||
currentArpeggioFrame = 0;
|
||||
arpeggioFrameTimer = 0;
|
||||
arpeggioFrameLength = 0;
|
||||
currentNumNoteBuffer = 0;
|
||||
}
|
||||
|
||||
void TonalVoice::advanceControlFrame()
|
||||
@ -90,6 +98,127 @@ void TonalVoice::controllerMoved (int type, int amount)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TonalVoice::setLegatoMode(double time) {
|
||||
portamentoTime = time;
|
||||
// currentNumNoteBuffer = 1;
|
||||
// noteBuffer[0] = noteNumber;
|
||||
}
|
||||
|
||||
void TonalVoice::addLegatoNote (int midiNoteNumber, float velocity) {
|
||||
if (currentNumNoteBuffer >= 10) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Push to last
|
||||
// noteBuffer[currentNumNoteBuffer] = midiNoteNumber;
|
||||
// currentNumNoteBuffer++;
|
||||
|
||||
int previousNoteNo = noteNumber;
|
||||
BaseVoice::changeNote(midiNoteNumber, velocity);
|
||||
|
||||
// Portamento implementation is just applying auto bend
|
||||
if (portamentoTime > 0) {
|
||||
currentAutoBendAmount = (double)(previousNoteNo - midiNoteNumber);
|
||||
autoBendDelta = -1.0 * currentAutoBendAmount / (portamentoTime * getSampleRate());
|
||||
}
|
||||
}
|
||||
|
||||
int TonalVoice::removeLegatoNote(int midiNoteNumber) {
|
||||
// if (currentNumNoteBuffer==0) {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// int i;
|
||||
// for (i=0; i<currentNumNoteBuffer; i++) {
|
||||
// if (noteBuffer[i] == midiNoteNumber) break;
|
||||
// }
|
||||
// if (i == currentNumNoteBuffer) { // not found
|
||||
// return currentNumNoteBuffer;
|
||||
// }
|
||||
// shiftNoteBuffer(i);
|
||||
// currentNumNoteBuffer--;
|
||||
|
||||
if (midiNoteNumber == noteNumber) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TonalVoice::setArpeggioMode(double interval)
|
||||
{
|
||||
arpeggioFrameLength = interval;
|
||||
arpeggioFrameTimer = 0;
|
||||
currentArpeggioFrame = 0;
|
||||
currentNumNoteBuffer = 1;
|
||||
noteBuffer[0] = noteNumber;
|
||||
}
|
||||
|
||||
void TonalVoice::addArpeggioNoteAscending(int midiNoteNumber)
|
||||
{
|
||||
if (currentNumNoteBuffer >= 10) {
|
||||
return;
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i<currentNumNoteBuffer; i++) {
|
||||
if (noteBuffer[i] > midiNoteNumber) break;
|
||||
}
|
||||
|
||||
pushNoteBuffer(i, midiNoteNumber);
|
||||
|
||||
currentNumNoteBuffer++;
|
||||
}
|
||||
|
||||
void TonalVoice::addArpeggioNoteDescending(int midiNoteNumber)
|
||||
{
|
||||
if (currentNumNoteBuffer >= 10) {
|
||||
return;
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i<currentNumNoteBuffer; i++) {
|
||||
if (noteBuffer[i] < midiNoteNumber) break;
|
||||
}
|
||||
|
||||
pushNoteBuffer(i, midiNoteNumber);
|
||||
|
||||
currentNumNoteBuffer++;
|
||||
}
|
||||
|
||||
/// Returns number of remaining arpeggio notes
|
||||
int TonalVoice::removeArpeggioNote(int midiNoteNumber)
|
||||
{
|
||||
if (currentNumNoteBuffer==0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int i;
|
||||
for (i=0; i<currentNumNoteBuffer; i++) {
|
||||
if (noteBuffer[i] == midiNoteNumber) break;
|
||||
}
|
||||
if (i == currentNumNoteBuffer) { // not found
|
||||
return currentNumNoteBuffer;
|
||||
}
|
||||
shiftNoteBuffer(i);
|
||||
currentNumNoteBuffer--;
|
||||
|
||||
return currentNumNoteBuffer;
|
||||
}
|
||||
|
||||
void TonalVoice::pushNoteBuffer(int index, int value) {
|
||||
for (int i=9; i>index; i--) {
|
||||
noteBuffer[i] = noteBuffer[i-1];
|
||||
}
|
||||
noteBuffer[index] = value;
|
||||
}
|
||||
|
||||
void TonalVoice::shiftNoteBuffer(int index) {
|
||||
for (int i=index; i<9; i++) {
|
||||
noteBuffer[i] = noteBuffer[i+1];
|
||||
}
|
||||
}
|
||||
|
||||
double TonalVoice::noteNoToHeltzDouble (double noteNoInDouble, const double frequencyOfA)
|
||||
{
|
||||
return frequencyOfA * std::pow (2.0, (noteNoInDouble - 69) / 12.0);
|
||||
|
Reference in New Issue
Block a user