well this 3rd post will keep the main.c uptodate, the code is simple but may be interesting
/* main.c
* TekkStar
*
* build 2 Midimize a Tama Techstar 306 >>> Do something usefull with it...
* 4 Velocity per Voice, 8 Voices (6 Drums + 1Filter +1 Amp).
* 4 Velocity Depending Note Killswitches
* random Note Kill Fader
* Velocity Offset Fader
*
* Hardware:
* 1stDOUTX4: 1st Voice: Pin0-3 =Velocity 0-3 (use different Resistor Values)
* 2nd Voice: Pin4-7 =Velocity 0-3 (I used: 5K6,4K7,2K2,1K)
* .... 8th Voice: Pin28-31 =Velocity 0-3 (Connect together: all 4 Resistors @ Trig-out-side)
* 2ndDOUTX4: Pin 32 = Kill-Button-Velocity 3
* Pin 33 = Kill-Button-Velocity 2
* Pin 34 = Kill-Button-Velocity 1
* Pin 35 = Kill-Button-Velocity 0
* Pin 36 = Kill-Button-Velo-Trigger-Indicator3 (easier find which BTNs make Effect...)
* Pin 37 = Kill-Button-Velo-Trigger-Indicator2 (...not all 4 Velocitys are always used...)
* Pin 38 = Kill-Button-Velo-Trigger-Indicator1 (...sometime you hear nothing...)
* Pin 39 = Kill-Button-Velo-Trigger-Indicator0 (...and thats may be not good...)
* 3rdDOUTX4: Pin 40 = Gate Indicator 4 Random Kill > Flashes if Notes get killed
* Pin 41 = Velocity Invert Button > Inverts the 4 Velocity Stages (lo=hi, hi=lo)
* Pin 42 = OverRoll --- Take every incoming Notes and place it on all Triggers
* J5 of 8Bit Core: Analog Input 0: random Kill
* Analog Input 1: Velocit Offset (0=-64,64=Orginal,127=+64)
*
*
* ==========================================================================
* Copyright - Phatline aka Crimic aka GreatFullTekk
* Licensed for personal non-commercial use only. All other rights reserved.
* ==========================================================================
*/
/////////////////////////////////////////////////////////////////////////////
//Include files
#include <cmios.h>
#include <pic18fregs.h>
#include "main.h"
/////////////////////////////////////////////////////////////////////////////
// VARIABLES --- Global & Local//////////////////////////////////////////////
app_flags_t app_flags; // status of app (see bitfield declaration in main.h)
unsigned char last_ain_pin;
unsigned char last_din_pin;
unsigned char last_dout_pin;
// Midisetup
int CHON;
int CHOF;
int N0;
int N1;
int N2;
int N3;
int N4;
int N5;
int N6;
int N7;
// Pots
unsigned int random;
unsigned int VelOff;
unsigned int VelInvert; //Invert the Pins by Velocity spreading....
unsigned int random1;
int velocity;
int velopin;
int KillBtn1;
int KillBtn2;
int KillBtn3;
int KillBtn4;
int OverRoll;
unsigned char random_seed_l;
unsigned char random_seed_h;
unsigned int random_tmp;
unsigned int random_nr;
int rgate;
/////////////////////////////////////////////////////////////////////////////
// INITALIZE ////////////////////////////////////////////////////////////////
void Init(void) __wparam
{
MIOS_AIN_NumberSet(7);
MIOS_AIN_UnMuxed();
MIOS_AIN_DeadbandSet(7);
//DIN DOUT AIN Setup
MIOS_SRIO_UpdateFrqSet(1); //set shift register update frequency in ms
MIOS_SRIO_NumberSet(9); // we need to set at least one IO shift register pair
MIOS_SRIO_DebounceSet(10); //debouncing value for DINs
MIOS_SRIO_TS_SensitivitySet(0);
// Midisetup (Channels, Note Numbers for Trigger)
CHON = 153; //Ch1:90, 2:91, 3:92, 4:93, 5:94, 6:95, 7:96, 8:97, 9:98, 10:153, 11:9A, 12:9B, 13:9C...
CHOF = 137; //Ch1:80, 2:81, 3:82, 4:83, 5:84, 6:85, 7:86, 8:87, 9:88, 10:137, 11:8A, 12:8B, 13:8C...
N0 = 48; //Note - Input Nr.
N1 = 49;
N2 = 50;
N3 = 51;
N4 = 52;
N5 = 53;
N6 = 54;
N7 = 55;
velocity = 0;
velopin = 0;
KillBtn1 = 1; MIOS_DOUT_PinSet(32, 1);
KillBtn2 = 1; MIOS_DOUT_PinSet(33, 1);
KillBtn3 = 1; MIOS_DOUT_PinSet(34, 1);
KillBtn4 = 1; MIOS_DOUT_PinSet(35, 1);
OverRoll = 0;
random = 0; //Analog In: randomly Kill Notes Events --- 0=0Kill 255=All Kill
VelOff = 64; //Shifts Velocity Spreading for the DOUTs (where differnt Resistor Values soldered..)
VelInvert = 0; //Invert the Pins by Velocity spreading....
random1 = 0; //1st Kill Function (Operator only -used 4 coding)
random_seed_l = 0;
random_seed_h = 127;
rgate = 1;
random_tmp = 64;
random_nr = 127;
}
/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS in the mainloop when nothing else is to do
/////////////////////////////////////////////////////////////////////////////
void Tick(void) __wparam
{}
/////////////////////////////////////////////////////////////////////////////
// This function is periodically called by MIOS. The frequency has to be
// initialized with MIOS_Timer_Set
/////////////////////////////////////////////////////////////////////////////
void Timer(void) __wparam
{}
/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when the display content should be
// initialized. Thats the case during startup and after a temporary message
// has been printed on the screen
/////////////////////////////////////////////////////////////////////////////
void DISPLAY_Init(void) __wparam
{
MIOS_LCD_Clear(); // clear screen
MIOS_LCD_CursorSet(0x00); //step2 1st Line
MIOS_LCD_PrintCString("TekkStar"); //message 1st Line
MIOS_LCD_CursorSet(0x40); //step2 2nd Line
MIOS_LCD_PrintCString("GreatFullTekk"); //message 2nd Line
}
/////////////////////////////////////////////////////////////////////////////
// This function is called in the mainloop when no temporary message is shown
// on screen. Print the realtime messages here
/////////////////////////////////////////////////////////////////////////////
void DISPLAY_Tick(void) __wparam
{
// do nothing if no update has been requested
if( !app_flags.DISPLAY_UPDATE_REQ )
return;
// clear request
app_flags.DISPLAY_UPDATE_REQ = 0;
}
/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when a complete MIDI event has been received
/////////////////////////////////////////////////////////////////////////////
void MPROC_NotifyReceivedEvnt(unsigned char evnt0, unsigned char evnt1, unsigned char evnt2) __wparam
{
if(evnt0 == CHOF) { // if note off: force evnt2 to 0 for easier handling of 'LED off'
evnt2 = 0;
MIOS_DOUT_PinSet(0, 0); //1st DOUT-Shift-Register --- Turn Off
MIOS_DOUT_PinSet(1, 0);
MIOS_DOUT_PinSet(2, 0);
MIOS_DOUT_PinSet(3, 0);
MIOS_DOUT_PinSet(4, 0);
MIOS_DOUT_PinSet(5, 0);
MIOS_DOUT_PinSet(6, 0);
MIOS_DOUT_PinSet(7, 0);
MIOS_DOUT_PinSet(8, 0); //2nd DOUT-Shift-Register --- Turn Off
MIOS_DOUT_PinSet(9, 0);
MIOS_DOUT_PinSet(10, 0);
MIOS_DOUT_PinSet(11, 0);
MIOS_DOUT_PinSet(12, 0);
MIOS_DOUT_PinSet(13, 0);
MIOS_DOUT_PinSet(14, 0);
MIOS_DOUT_PinSet(15, 0);
MIOS_DOUT_PinSet(16, 0); //3rd DOUT-Shift-Register --- Turn Off
MIOS_DOUT_PinSet(17, 0);
MIOS_DOUT_PinSet(18, 0);
MIOS_DOUT_PinSet(19, 0);
MIOS_DOUT_PinSet(20, 0);
MIOS_DOUT_PinSet(21, 0);
MIOS_DOUT_PinSet(22, 0);
MIOS_DOUT_PinSet(23, 0);
MIOS_DOUT_PinSet(24, 0); //4th DOUT-Shift-Register --- Turn Off
MIOS_DOUT_PinSet(25, 0);
MIOS_DOUT_PinSet(26, 0);
MIOS_DOUT_PinSet(27, 0);
MIOS_DOUT_PinSet(28, 0);
MIOS_DOUT_PinSet(29, 0);
MIOS_DOUT_PinSet(30, 0);
MIOS_DOUT_PinSet(31, 0);
MIOS_DOUT_PinSet(36, 0); //5th DOUT-Shift-Register --- Turn Off (Velo-Split-Indicator)
MIOS_DOUT_PinSet(37, 0); //5th DOUT-Shift-Register --- Turn Off (Velo-Split-Indicator)
MIOS_DOUT_PinSet(38, 0); //5th DOUT-Shift-Register --- Turn Off (Velo-Split-Indicator)
MIOS_DOUT_PinSet(39, 0); //5th DOUT-Shift-Register --- Turn Off (Velo-Split-Indicator)
}
//random Number Set
if(evnt0==CHON) {
random_tmp = random_seed_l * random_seed_h;
random_seed_l = TMR0L + (random_tmp & 0xff); //TMR0L = Timer
random_seed_h = 0x69 + (random_tmp >> 8);
random_nr = random_tmp % 127; //>> 2; // divede by 2 > bitshifting - thx2"kpete"
}
//random Number <= random Poti?
if( (evnt0==CHON) && (random < random_nr) ) {rgate = 1; MIOS_DOUT_PinSet(40, 0);}//Pass Notes
if( (evnt0==CHON) && (random > random_nr) ) {rgate = 0; MIOS_DOUT_PinSet(40, 1);} //Kill Notes
//velocity + velocity offset
if(evnt0==CHON) {velocity = evnt2 + (VelOff - 64);} //@64=orginal, @0=velo-64, @127=velo+64
//velocity > spreading 2 DOUT-Pins > split in 4 velocity groups (4Dout Pins, 4 different Resistors)
//Normal
if((evnt0==CHON) && (velocity < 30) && (VelInvert==0))
{velopin = 0; MIOS_DOUT_PinSet(36, 1);} //1K
if((evnt0==CHON) && (velocity > 30) && (velocity < 64) && (VelInvert==0))
{velopin = 1; MIOS_DOUT_PinSet(37, 1);} //2K2
if((evnt0==CHON) && (velocity > 64) && (velocity < 96) && (VelInvert==0))
{velopin = 2; MIOS_DOUT_PinSet(38, 1);} //4K7
if((evnt0==CHON) && (velocity > 90) && (VelInvert==0))
{velopin = 3; MIOS_DOUT_PinSet(39, 1);} //5K6
//Pins Inverted / swapped
if((evnt0==CHON) && (velocity < 30) && (VelInvert==1))
{velopin = 3; MIOS_DOUT_PinSet(39, 1);} //LED: Indicates Trigger - easier to find Effectiv Killbutton...
if((evnt0==CHON) && (velocity > 30) && (velocity < 64) && (VelInvert==1))
{velopin = 2; MIOS_DOUT_PinSet(38, 1);}
if((evnt0==CHON) && (velocity > 64) && (velocity < 96) && (VelInvert==1))
{velopin = 1; MIOS_DOUT_PinSet(37, 1);}
if((evnt0==CHON) && (velocity > 90) && (VelInvert==1))
{velopin = 1; MIOS_DOUT_PinSet(36, 1);}
//Trigger1 Detection - random Gate - Velocity set - Kill Pins - Overroll
if( (evnt0==CHON) && ((evnt1==N0) || (OverRoll==1)) && (rgate==1) && (velopin==3) && (KillBtn1==1) )
{MIOS_DOUT_PinSet(0, 1);} //1.Trigger, 1.Velociy
if( (evnt0==CHON) && ((evnt1==N0) || (OverRoll==1)) && (rgate==1) && (velopin==2) && (KillBtn2==1) )
{MIOS_DOUT_PinSet(1, 1);} //1.Trigger, 2.Velociy
if( (evnt0==CHON) && ((evnt1==N0) || (OverRoll==1)) && (rgate==1) && (velopin==1) && (KillBtn3==1) )
{MIOS_DOUT_PinSet(2, 1);} //1.Trigger, 3.Velociy
if( (evnt0==CHON) && ((evnt1==N0) || (OverRoll==1)) && (rgate==1) && (velopin==0) && (KillBtn4==1) )
{MIOS_DOUT_PinSet(3, 1);} //1.Trigger, 2.Velociy
//Trigger2 Detection - random Gate - Velocity set - Kill Pins
if( (evnt0==CHON) && ((evnt1==N1) || (OverRoll==1)) && (rgate==1) && (velopin==3) && (KillBtn1==1) )
{MIOS_DOUT_PinSet(4, 1);} //1.Trigger, 1.Velociy
if( (evnt0==CHON) && ((evnt1==N1) || (OverRoll==1)) && (rgate==1) && (velopin==2) && (KillBtn2==1) )
{MIOS_DOUT_PinSet(5, 1);} //1.Trigger, 2.Velociy
if( (evnt0==CHON) && ((evnt1==N1) || (OverRoll==1)) && (rgate==1) && (velopin==1) && (KillBtn3==1) )
{MIOS_DOUT_PinSet(6, 1);} //1.Trigger, 3.Velociy
if( (evnt0==CHON) && ((evnt1==N1) || (OverRoll==1)) && (rgate==1) && (velopin==0) && (KillBtn4==1) )
{MIOS_DOUT_PinSet(7, 1);} //1.Trigger, 2.Velociy
//Trigger3 Detection - random Gate - Velocity set - Kill Pins
if( (evnt0==CHON) && ((evnt1==N2) || (OverRoll==1)) && (rgate==1) && (velopin==3) && (KillBtn1==1) )
{MIOS_DOUT_PinSet(8, 1);} //1.Trigger, 1.Velociy
if( (evnt0==CHON) && ((evnt1==N2) || (OverRoll==1)) && (rgate==1) && (velopin==2) && (KillBtn2==1) )
{MIOS_DOUT_PinSet(9, 1);} //1.Trigger, 2.Velociy
if( (evnt0==CHON) && ((evnt1==N2) || (OverRoll==1)) && (rgate==1) && (velopin==1) && (KillBtn3==1) )
{MIOS_DOUT_PinSet(10, 1);} //1.Trigger, 3.Velociy
if( (evnt0==CHON) && ((evnt1==N2) || (OverRoll==1)) && (rgate==1) && (velopin==0) && (KillBtn4==1) )
{MIOS_DOUT_PinSet(11, 1);} //1.Trigger, 2.Velociy
//Trigger4 Detection - random Gate - Velocity set - Kill Pins
if( (evnt0==CHON) && ((evnt1==N3) || (OverRoll==1)) && (rgate==1) && (velopin==3) && (KillBtn1==1) )
{MIOS_DOUT_PinSet(12, 1);} //1.Trigger, 1.Velociy
if( (evnt0==CHON) && ((evnt1==N3) || (OverRoll==1)) && (rgate==1) && (velopin==2) && (KillBtn2==1) )
{MIOS_DOUT_PinSet(13, 1);} //1.Trigger, 2.Velociy
if( (evnt0==CHON) && ((evnt1==N3) || (OverRoll==1)) && (rgate==1) && (velopin==1) && (KillBtn3==1) )
{MIOS_DOUT_PinSet(14, 1);} //1.Trigger, 3.Velociy
if( (evnt0==CHON) && ((evnt1==N3) || (OverRoll==1)) && (rgate==1) && (velopin==0) && (KillBtn4==1) )
{MIOS_DOUT_PinSet(15, 1);} //1.Trigger, 2.Velociy
//Trigger5 Detection - random Gate - Velocity set - Kill Pins
if( (evnt0==CHON) && ((evnt1==N4) || (OverRoll==1)) && (rgate==1) && (velopin==3) && (KillBtn1==1) )
{MIOS_DOUT_PinSet(16, 1);} //1.Trigger, 1.Velociy
if( (evnt0==CHON) && ((evnt1==N4) || (OverRoll==1)) && (rgate==1) && (velopin==2) && (KillBtn2==1) )
{MIOS_DOUT_PinSet(17, 1);} //1.Trigger, 2.Velociy
if( (evnt0==CHON) && ((evnt1==N4) || (OverRoll==1)) && (rgate==1) && (velopin==1) && (KillBtn3==1) )
{MIOS_DOUT_PinSet(18, 1);} //1.Trigger, 3.Velociy
if( (evnt0==CHON) && ((evnt1==N4) || (OverRoll==1)) && (rgate==1) && (velopin==0) && (KillBtn4==1) )
{MIOS_DOUT_PinSet(19, 1);} //1.Trigger, 2.Velociy
//Trigger6 Detection - random Gate - Velocity set - Kill Pins
if( (evnt0==CHON) && ((evnt1==N5) || (OverRoll==1)) && (rgate==1) && (velopin==3) && (KillBtn1==1) )
{MIOS_DOUT_PinSet(20, 1);} //1.Trigger, 1.Velociy
if( (evnt0==CHON) && ((evnt1==N5) || (OverRoll==1)) && (rgate==1) && (velopin==2) && (KillBtn2==1) )
{MIOS_DOUT_PinSet(21, 1);} //1.Trigger, 2.Velociy
if( (evnt0==CHON) && ((evnt1==N5) || (OverRoll==1)) && (rgate==1) && (velopin==1) && (KillBtn3==1) )
{MIOS_DOUT_PinSet(22, 1);} //1.Trigger, 3.Velociy
if( (evnt0==CHON) && ((evnt1==N5) || (OverRoll==1)) && (rgate==1) && (velopin==0) && (KillBtn4==1) )
{MIOS_DOUT_PinSet(23, 1);} //1.Trigger, 2.Velociy
//Trigger7 Detection - random Gate - Velocity set - Kill Pins
if( (evnt0==CHON) && ((evnt1==N6) || (OverRoll==1)) && (rgate==1) && (velopin==3) && (KillBtn1==1) )
{MIOS_DOUT_PinSet(24, 1);} //1.Trigger, 1.Velociy
if( (evnt0==CHON) && ((evnt1==N6) || (OverRoll==1)) && (rgate==1) && (velopin==2) && (KillBtn2==1) )
{MIOS_DOUT_PinSet(25, 1);} //1.Trigger, 2.Velociy
if( (evnt0==CHON) && ((evnt1==N6) || (OverRoll==1)) && (rgate==1) && (velopin==1) && (KillBtn3==1) )
{MIOS_DOUT_PinSet(26, 1);} //1.Trigger, 3.Velociy
if( (evnt0==CHON) && ((evnt1==N6) || (OverRoll==1)) && (rgate==1) && (velopin==0) && (KillBtn4==1) )
{MIOS_DOUT_PinSet(27, 1);} //1.Trigger, 2.Velociy
//Trigger8 Detection - random Gate - Velocity set - Kill Pins
if( (evnt0==CHON) && ((evnt1==N7) || (OverRoll==1)) && (rgate==1) && (velopin==3) && (KillBtn1==1) )
{MIOS_DOUT_PinSet(28, 1);} //1.Trigger, 1.Velociy
if( (evnt0==CHON) && ((evnt1==N7) || (OverRoll==1)) && (rgate==1) && (velopin==2) && (KillBtn2==1) )
{MIOS_DOUT_PinSet(29, 1);} //1.Trigger, 2.Velociy
if( (evnt0==CHON) && ((evnt1==N7) || (OverRoll==1)) && (rgate==1) && (velopin==1) && (KillBtn3==1) )
{MIOS_DOUT_PinSet(30, 1);} //1.Trigger, 3.Velociy
if( (evnt0==CHON) && ((evnt1==N7) || (OverRoll==1)) && (rgate==1) && (velopin==0) && (KillBtn4==1) )
{MIOS_DOUT_PinSet(31, 1);} //1.Trigger, 2.Velociy
}
/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when a MIDI event has been received
// which has been specified in the MIOS_MPROC_EVENT_TABLE
/////////////////////////////////////////////////////////////////////////////
void MPROC_NotifyFoundEvent(unsigned entry, unsigned char evnt0, unsigned char evnt1, unsigned char evnt2) __wparam
{}
/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when a MIDI event has not been completly
// received within 2 seconds
/////////////////////////////////////////////////////////////////////////////
void MPROC_NotifyTimeout(void) __wparam
{}
/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when a MIDI byte has been received
/////////////////////////////////////////////////////////////////////////////
void MPROC_NotifyReceivedByte(unsigned char byte) __wparam
{}
/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS before the shift register are loaded
/////////////////////////////////////////////////////////////////////////////
void SR_Service_Prepare(void) __wparam
{}
/////////////////////////////////////////////////////////////////////////////
// Shiftregister has been loaded?
/////////////////////////////////////////////////////////////////////////////
void SR_Service_Finish(void) __wparam
{}
/////////////////////////////////////////////////////////////////////////////
// Buttons has toggled?
// pin_value is 1 when button released, and 0 when button pressed
/////////////////////////////////////////////////////////////////////////////
void DIN_NotifyToggle(unsigned char pin, unsigned char pin_value) __wparam
{
//Toggle Kill-Switches & Kill-LEDs
if(pin == 0 && pin_value == 0){KillBtn1 =! KillBtn1;} //toggle
if(KillBtn1 == 0){MIOS_DOUT_PinSet(32, 0);}
if(KillBtn1 == 1){MIOS_DOUT_PinSet(32, 1);}
if(pin == 1 && pin_value == 0){KillBtn2 =! KillBtn2;} //toggle
if(KillBtn2 == 0){MIOS_DOUT_PinSet(33, 0);}
if(KillBtn2 == 1){MIOS_DOUT_PinSet(33, 1);}
if(pin == 2 && pin_value == 0){KillBtn3 =! KillBtn3;} //toggle
if(KillBtn3 == 0){MIOS_DOUT_PinSet(34, 0);}
if(KillBtn3 == 1){MIOS_DOUT_PinSet(34, 1);}
if(pin == 3 && pin_value == 0){KillBtn4 =! KillBtn4;} //toggle
if(KillBtn4 == 0){MIOS_DOUT_PinSet(35, 0);}
if(KillBtn4 == 1){MIOS_DOUT_PinSet(35, 1);}
if(pin == 4 && pin_value == 0){VelInvert =! VelInvert;} //toggle
if(VelInvert == 0){MIOS_DOUT_PinSet(41, 0);}
if(VelInvert == 1){MIOS_DOUT_PinSet(41, 1);}
if(pin == 5 && pin_value == 1){OverRoll = 0;} //Momentary
if(OverRoll == 0){MIOS_DOUT_PinSet(42, 1);}
if(pin == 5 && pin_value == 0){OverRoll = 1;} //Momentary
if(OverRoll == 0){MIOS_DOUT_PinSet(42, 0);}
MIOS_LCD_Clear(); // clear screen
MIOS_LCD_CursorSet(0x00); //step2 1st Line
MIOS_LCD_PrintBCD3(pin); //message 1st Line
MIOS_LCD_CursorSet(0x40); //step2 2nd Line
MIOS_LCD_PrintBCD3(pin_value); //message 2nd Line
}
/////////////////////////////////////////////////////////////////////////////
// Encoder has Mooved?
// incrementer is positive when encoder has been turned clockwise, else
// it is negative
/////////////////////////////////////////////////////////////////////////////
void ENC_NotifyChange(unsigned char encoder, char incrementer) __wparam
{}
/////////////////////////////////////////////////////////////////////////////
// Potentiometer has Mooved?
/////////////////////////////////////////////////////////////////////////////
void AIN_NotifyChange(unsigned char pin, unsigned int pin_value) __wparam
{
random = MIOS_AIN_Pin7bitGet(0);
VelOff = MIOS_AIN_Pin7bitGet(1);
}