i was testing with simple sketch for synth to make monophonic synth using this sketch
from above code i playing keyboard with serial communication. getting succesfully note_on on Particular key press & Note_off on Key release.
first ... please check below
am I using correct code in "void loop() " for Note_on & Note_off event ????
Because i am feeling a little latency in Fast fingering.
if No , Please describe here correct way...
and Second Main thing to ask:---
please try to understand what i want to ask. I do not know what word is used for event of synth process inwhich " in mono mode , if any new key is released after holded a old key , old key should begin sound.
i want my synth behave like below.
for example in sequence :- suppose : [Note1 for Key1 , Note2 for Key2 , Note3 for Key3
step1:- i press and hold key1 >>Note1 will sound on ,
step2:- i press and hold key2 without release key 1 >>> Note1 will sound off and Note2 will sound on.
step3:-i press and hold key3 without release Key1 & Key2 >> Note2 will sound off Note3 will sound on.
step4:-now if i will release Key3 without release Key1 & Key2 >> Note3 will sound off and Note2 should be sound on.because of key2 was holded before presses key3
step5:- now if i will release Key2 without release key1 >>> Note1 should be sound on because of already hold of Key1
just like Professional Synthesizor Keyboard in Mono Mode Patches.
I am sorry i you did not understand my wording.
if anyone my senior understand above event of NoteOn/NoteOFF, please describe How to write it in code
Code:
#include <Keypad.h>
#include <Arduino.h>
#include <Audio.h>
#include <SD.h>
#include <TeensyVariablePlayback.h>
#include <SPI.h>
#include <Wire.h>
#include "PlaySynthMusic.h"
#include <SoftwareSerial.h>
const uint8_t ROWS = 7; // 7 rows
const uint8_t COLS = 4; //4 columns
char keys[ROWS][COLS] = {
{ 1, 2, 3, 4 },
{ 5, 6, 7, 8 },
{ 9, 10, 11, 12 },
{ 13, 14, 15, 16 },
{ 17, 18, 19, 20 },
{ 21, 22, 23, 24 },
{ 25, 26, 27, 28 }
};
uint8_t rowPins[ROWS] = { 33, 34, 35, 36, 37, 38, 39 };
uint8_t colPins[COLS] = { 40, 41, 14, 16 };
Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// GUItool: begin automatically generated code
AudioSynthWaveform waveform1; //xy=175.7142857142857,257.1428571428571
AudioSynthWaveform waveform2;
AudioSynthWaveform waveform3;
AudioSynthWaveform waveform4;
AudioPlaySdResmp playSdWav1; //xy=185.00003814697266,190.0000171661377
AudioEffectEnvelope envelope1; //xy=324.2857131958008,255.7142848968506
AudioMixer4 mixer1; //xy=754.2857494354248,214.28570938110352
AudioAmplifier amp1; //xy=949.9999656677246,191.42856407165527
AudioAmplifier amp2; //xy=952.8571510314941,242.8571376800537
AudioOutputI2S i2s1; //xy=1099.9999542236328,228.5714282989502
AudioConnection patchCord1(waveform1, envelope1);
AudioConnection patchCord2(waveform3, 0, mixer1, 0);
AudioConnection patchCord3(playSdWav1, 1, mixer1, 1);
AudioConnection patchCord4(envelope1, 0, mixer1, 2);
AudioConnection patchCord9(waveform2, 0, mixer1, 3);
AudioConnection patchCord5(mixer1, amp1);
AudioConnection patchCord6(mixer1, amp2);
AudioConnection patchCord7(amp1, 0, i2s1, 0);
AudioConnection patchCord8(amp2, 0, i2s1, 1);
AudioControlSGTL5000 audioShield; //xy=654.2857131958008,335.71429920196533
// GUItool: end automatically generated code
int RAGA[] = {50,52,54,55,57,59,61,62,64,66,67,69,71,73, 74,76,78};
SoftwareSerial mySerial(0, 1); // RX,TX
void setup() {
mySerial.begin(115200);
Serial.begin(9600);
kpd.setHoldTime(2000);
if (!(SD.begin(BUILTIN_SDCARD))) {
while (1) { Serial.println("Unable to access the SD card");
delay(500); } }
AudioMemory(128);
audioShield.enable();
audioShield.volume(1.0);
amp1.gain(1.0);
amp2.gain(1.0);
playSdWav1.enableInterpolation(true);
waveform1.begin(WAVEFORM_TRIANGLE);
waveform2.begin(WAVEFORM_SQUARE);
waveform3.begin(WAVEFORM_SINE);
}
unsigned long t=0;
void loop() {
if (kpd.getKeys()) {
for (int i = 0; i < LIST_MAX; i++)
{ int mykey = (kpd.key[i].kchar);
if ((kpd.key[i].stateChanged) && (mykey<29) && (mykey>0)) // -----------------------------------------Key Changed----------------
{ switch (kpd.key[i].kstate) {
case PRESSED:
break;
case RELEASED:
break;
}
} //--------------------------------------------------------------------------------------------------
} }
// --------------------------------Read serial--------------------------------------------------------------
int type, note, velocity, channel, d1, d2;
if (mySerial.available()>=2)
{
type = mySerial.read();
note = mySerial.read();
if (type==101) { Serial.println(note); Serial.println("on");
envelope1.releaseNoteOn(0);
waveform1.begin(1.0,Pitch_Freq[note+52],WAVEFORM_SAWTOOTH);
envelope1.noteOn();
envelope1.attack(5);
envelope1.hold(0);
envelope1.decay(0);
envelope1.sustain(1.0);
Serial.println(Pitch_Freq[note+52]); }
else if (type==100) { Serial.println("off");
envelope1.noteOff();
}
}
// --------------------------------Read serial------------------------------------------------------------
}
first ... please check below
am I using correct code in "void loop() " for Note_on & Note_off event ????
Because i am feeling a little latency in Fast fingering.
Code:
// --------------------------------Read serial--------------------------------------------------------------
int type, note, velocity, channel, d1, d2;
if (mySerial.available()>=2)
{
type = mySerial.read();
note = mySerial.read();
if (type==101) { Serial.println(note); Serial.println("on");
envelope1.releaseNoteOn(0);
waveform1.begin(1.0,Pitch_Freq[note+52],WAVEFORM_SAWTOOTH);
envelope1.noteOn();
envelope1.attack(5);
envelope1.hold(0);
envelope1.decay(0);
envelope1.sustain(1.0);
Serial.println(Pitch_Freq[note+52]); }
else if (type==100) { Serial.println("off");
envelope1.noteOff();
}
}
// --------------------------------Read serial------------------------------------------------------------
and Second Main thing to ask:---
please try to understand what i want to ask. I do not know what word is used for event of synth process inwhich " in mono mode , if any new key is released after holded a old key , old key should begin sound.
i want my synth behave like below.
for example in sequence :- suppose : [Note1 for Key1 , Note2 for Key2 , Note3 for Key3
step1:- i press and hold key1 >>Note1 will sound on ,
step2:- i press and hold key2 without release key 1 >>> Note1 will sound off and Note2 will sound on.
step3:-i press and hold key3 without release Key1 & Key2 >> Note2 will sound off Note3 will sound on.
step4:-now if i will release Key3 without release Key1 & Key2 >> Note3 will sound off and Note2 should be sound on.because of key2 was holded before presses key3
step5:- now if i will release Key2 without release key1 >>> Note1 should be sound on because of already hold of Key1
just like Professional Synthesizor Keyboard in Mono Mode Patches.
I am sorry i you did not understand my wording.
if anyone my senior understand above event of NoteOn/NoteOFF, please describe How to write it in code