Skip to content

Commit

Permalink
Update Keyboard
Browse files Browse the repository at this point in the history
added control for ADSR an Filter
  • Loading branch information
AaronCollins1999 committed Mar 21, 2022
1 parent 8643702 commit 24ea4ee
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 23 deletions.
71 changes: 55 additions & 16 deletions src/Keyboard.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#include "Keyboard.h"
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include "Controller.h"
#include <set>
#include <alsa/asoundlib.h>

//#include "defs.hpp"

using namespace SYNTHPI;
using namespace audio;

Keyboard::Keyboard(Controller *controller, int keyId, int keyPort, int verbosity,
const int vol_ID, const int wavemix_ID, const int Bank_ID):
Keyboard::Keyboard(Controller *controller, int keyId, int keyPort, int verbosity, const int vol_ID,
const int wavemix_ID, const int Bank_ID,const int Attack_ID,const int Decay_ID, const int Sustain_ID,
const int Release_ID,const int Cutoff_ID,const int Res_ID):
announce(verbosity > 0),
CC1(vol_ID),
CC2(wavemix_ID),
CC3(Bank_ID),
CC4(Attack_ID),
CC5(Decay_ID),
CC6(Sustain_ID),
CC7(Release_ID),
CC8(Cutoff_ID),
CC9(Res_ID)
{

this->controller = controller;
Expand Down Expand Up @@ -94,9 +95,9 @@ void Keyboard::connectKeyboard()

void Keyboard::noteOn(unsigned char note, unsigned char velocity) {
// Send a note off if already sounding
if (deferred_noteoff.find(note) != deferred_noteoff.end()){
controller->keyEvent(true, note);
}
// if (deferred_noteoff.find(note) != deferred_noteoff.end()){
// controller->keyEvent(true, note);
// }
// sound the note (velocity is ignored)
controller->keyEvent(false, note);

Expand Down Expand Up @@ -139,12 +140,14 @@ void Keyboard::midiAction() {
note = event->data.note.note;
velocity = event->data.note.velocity;

if (velocity != 0)
if (velocity != 0){
noteOn(note, velocity);
else
break;
}
else{
noteOff(note);

break;
break;
}

case SND_SEQ_EVENT_NOTEOFF:
note = event->data.note.note;
Expand Down Expand Up @@ -188,6 +191,42 @@ void Keyboard::midiAction() {
break;
}

if (p==CC4){ //Attack time CC
//std::cout<<"in CC4 if loop"<<std::endl;
controller->updateAttack(v);
break;
}

if (p==CC5){ // Decay time CC
//std::cout<<"in CC5 if loop"<<std::endl;
controller->updateDecay(v);
break;
}

if (p==CC6){ //Sustain Level CC
//std::cout<<"in CC6 if loop"<<std::endl;
controller->updateSustain(v);
break;
}

if (p==CC7){ //Release time CC
//std::cout<<"in CC7 if loop"<<std::endl;
controller->updateRelease(v);
break;
}

if (p==CC8){ // Cutoff Frequency CC
//std::cout<<"in CC8 if loop"<<std::endl;
controller->updateCutoff(v);
break;
}

if (p==CC9){ // Resonance amount CC
//std::cout<<"in CC9 if loop"<<std::endl;
controller->updateRes(v);
break;
}

}

snd_seq_free_event(event);
Expand Down
21 changes: 14 additions & 7 deletions src/Keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include <stdlib.h>
#include <unistd.h>

#include "Thread.h"
#include "Lock.h"
#include "defs.hpp"
#include <Thread.h>
#include <Lock.h>
#include <defs.hpp>
#include "Controller.h"


Expand All @@ -27,26 +27,32 @@ class Keyboard : public Thread {

Controller* controller;
snd_seq_t* sequencer;

int myId;
int myPort;
int keyboardId;
int keyboardPort;
int announce;



typedef std::set<int> keyset;

/** A list of note off commands not yet sent
* because the sustain pedal is pressed.
*/
keyset deferred_noteoff;

bool sustain=false; /**< whether sustain pedal is depressed */


const int CC1;
const int CC2;
const int CC3;
const int CC4;
const int CC5;
const int CC6;
const int CC7;
const int CC8;
const int CC9;

/**
* Send a MIDI note on event, taking the sustain pedal into account
Expand Down Expand Up @@ -99,8 +105,9 @@ class Keyboard : public Thread {
* @param keyPort Port number on the given client
* @param verbosity Print note on/off announcement if > 0
*/
Keyboard(Controller* controller, int keyId, int keyPort,
int verbosity,const int vol_ID, const int wavemix_ID,const int Bank_ID);
Keyboard(Controller* controller, int keyId, int keyPort, int verbosity,const int vol_ID,
const int wavemix_ID, const int Bank_ID, const int Attack_ID,const int Decay_ID, const int Sustain_ID,
const int Release_ID, const int Cutoff_ID,const int Res_ID);

/**
* Poll the MIDI keyboard for key events.
Expand Down

0 comments on commit 24ea4ee

Please sign in to comment.