diff --git a/Software/Gravity/Gravity.ino b/Software/Gravity/Gravity.ino index ab93df3..537c004 100644 --- a/Software/Gravity/Gravity.ino +++ b/Software/Gravity/Gravity.ino @@ -6,48 +6,12 @@ #include #include +#include "config.h" +#include "fonts.h" + #define VERSION "V:1.2A" -byte memCode = 'G'; //Change to different letter if you changed the data structure - -#define PPQN 24 -#define PULSE_LENGTH 120 //1/10ms resolution. 12ms was failing at 1ms resolution at higher bpm. 60000/200/24 = 12.5 the max pulse length at 1ms resolution for 200bpm is 11ms -#define MAXBPM 200 //250 at 24ppqn with 5ms pulse will be 50/50 square wave -#define MINBPM 20 - -#define SCREEN_ADDRESS 0x3C - -// Rev 2+ Config -#define ENC_BTN_PIN 14 -#define ENC_D1_PIN 17 -#define ENC_D2_PIN 4 -#define START_STOP_BTN_PIN 5 -#define SHIFT_BTN_PIN 12 -#define EXT_INPUT_PIN 2 //needs to be an interrupt pin -#define ANALOGUE_INPUT_1_PIN A7 -#define ANALOGUE_INPUT_2_PIN A6 -const byte outsPins[6] = { 7, 8, 10, 6, 9, 11 }; -const byte clockOutPin = 3; -bool rotateScreen = false; -bool reverseEnc = false; -// - -/* Rev 1 Config -#define ENC_BTN_PIN 14 -#define ENC_D1_PIN 17 -#define ENC_D2_PIN 4 -#define START_STOP_BTN_PIN 5 -#define SHIFT_BTN_PIN 100 - -#define EXT_INPUT_PIN 2 //needs to be an interrupt pin -#define ANALOGUE_INPUT_1_PIN A2 -#define ANALOGUE_INPUT_2_PIN A1 - -const byte clockOutPin = 13; -const byte outsPins[6] = {6, 11, 7, 10, 8, 9}; -bool rotateScreen = true; -*/ - +byte memCode = 'D'; //Change to different letter if you changed the data structure uint16_t CV1Calibration = 512; uint16_t CV2Calibration = 512; @@ -60,15 +24,15 @@ byte bpmModulationChannel = 200; //0 - CV1, 1 - CV2, 255 - OFF byte bpmModulationRange = 0; struct channel { - byte mode; //0 - CLK, 1 - RND, 2 - SEQ, 3 - SWING, 4 - Gate - byte subDiv; - byte CV1Target; //0 - Off, 1 - Subdiv, 2 - RND, 3 - SeqPattern - byte CV2Target; - uint8_t offset; - byte random; - byte seqPattern; - uint8_t gate; - uint8_t swing; //some of this params can be combinde into 4+4 bits to save space + byte mode : 3; //mv: 7. 0 - CLK, 1 - RND, 2 - SEQ, 3 - SWING, 4 - Gate + byte subDiv : 5; //mv: 32 + byte CV1Target : 3; //0 - Off, 1 - Subdiv, 2 - RND, 3 - SeqPattern + byte CV2Target : 3; + uint8_t offset : 7; //mv: 128 + byte random : 4; //mv: 16 + byte seqPattern : 4; + uint8_t gate : 6; //mv: 64 + uint8_t swing : 4; //some of this params can be combinde into 4+4 bits to save space }; channel channels[6] = { //array of channel settings @@ -80,7 +44,7 @@ channel channels[6] = { //array of channel settings { 0, 7, 0, 0, 0, 0, 0, 23, 0 } }; -bool seqA1[16] = {1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1}; //switch to struct { uint32_t sequence; uint8_t length; uint8_t subdiv }. test with lengthOf +bool seqA1[16] = {1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1}; //switch to struct seqs { uint32_t sequence; uint8_t length; uint8_t subdiv }. test with lengthOf bool seqA2[16] = {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}; bool seqA3[16] = {1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0}; bool seqA4[16] = {0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1}; @@ -107,8 +71,8 @@ byte sixteenthPulseCount = 0; int playingModes[6]; // should be renamed to currentSubdivs or something. Updated from channels object on beat and with applied CV modulation int playingModesOld[6]; -unsigned int pulsePeriod; -bool isPlaying;// = false; +unsigned int pulsePeriod; +bool isPlaying;// = false; // replace to something like byte status where 1xxxxxx isPlaying, x1xxxxx isRecording etc bool isRecording = false; bool recordToNextStep = false; bool MIDIClockReceived = false; @@ -155,42 +119,7 @@ int extTriggerCount; U8G2_SSD1306_128X64_NONAME_2_HW_I2C u8g2(U8G2_R2, SCL, SDA, U8X8_PIN_NONE); RotaryEncoder encoder(ENC_D1_PIN, ENC_D2_PIN, RotaryEncoder::LatchMode::TWO03); -//Font -const PROGMEM uint8_t velvetscreen[437] U8G2_FONT_SECTION("velvetscreen") = - "\64\0\2\2\3\3\2\3\4\5\5\0\0\5\0\5\0\0\221\0\0\1\230 \4\200\134%\11\255tT" - "R\271RI(\6\252\334T\31)\7\252\134bJ\12+\7\233\345\322J\0,\5\221T\4-\5\213" - "f\6.\5\211T\2/\6\244\354c\33\60\10\254\354T\64\223\2\61\7\353\354\222\254\6\62\11\254l" - "\66J*\217\0\63\11\254l\66J\32\215\4\64\10\254l\242\34\272\0\65\11\254l\206\336h$\0\66" - "\11\254\354T^\61)\0\67\10\254lF\216u\4\70\11\254\354TL*&\5\71\11\254\354TL;" - ")\0:\6\231UR\0A\10\254\354T\34S\6B\11\254lV\34)\216\4C\11\254\354T\324\61" - ")\0D\10\254lV\64G\2E\10\254l\206\36z\4F\10\254l\206^\71\3G\11\254\354TN" - "\63)\0H\10\254l\242\34S\6I\6\251T\206\0J\10\254\354k\231\24\0K\11\254l\242J\62" - "\225\1L\7\254lr{\4M\11\255t\362ZI\353\0N\11\255t\362TI\356\0O\10\254\354T" - "\64\223\2P\11\254lV\34)g\0Q\10\254\354T\264b\12R\10\254lV\34\251\31S\11\254\354" - "FF\32\215\4T\7\253dVl\1U\10\254l\242\63)\0V\11\255t\262Ne\312\21W\12\255" - "t\262J*\251.\0X\11\254l\242L*\312\0Y\12\255tr\252\63\312(\2Z\7\253df*" - "\7p\10\255\364V\266\323\2q\7\255\364\216\257\5r\10\253d\242\32*\2t\6\255t\376#w\11" - "\255\364V\245FN\13x\6\233dR\7\0\0\0\4\377\377\0"; -const PROGMEM uint8_t stkL[569] U8G2_FONT_SECTION("stk-l") = - "\25\0\4\4\4\5\2\1\6\17\27\1\0\27\0\0\0\1\77\0\0\2\34%'\17\37\313\330R#&" - "\32!F\14\211I\310\24!\65\204(MF\21)Cd\304\10\62b\14\215\60Vb\334\20\0/\14" - "\272\336\336d\244\350\263q\343\0\60\37|\377\12\32\25\17\2\35\263\253ChD\30\21bB\14\242S" - "\306lv\350A\10\65H\0\61\24z\337\322\60R\205\314\234\31\61F\310\270\371\177\224\42\3\62\33|" - "\377\216\251$*\10\35\63\66r\206\304\314`c\252\34\301\221\263|\360\300\0\63\34|\377\216)\64*" - "\10\35\63\66r \71\332YIr\226\306\16\221P\203\312\14\0\64 |\377\226\220AC\306\20\31B" - "f\310\240\21\204F\214\32\61j\304(cv\366\200\305\312\371\0\65\32}\17\307\12.\206\316\213Bj" - "\226\214\42JtN\315\235\42\261&\325\31\0\66\33}\17\317\251\64+\206\235\63:/\314,aA\352" - "\234\335\235\42\261&\325\31\0\67\23|\377\302\212\7)\347Crt\70\345\300\221\363\16\0\70 |\377" - "\216)\64*\10\35\263\331!\22D\310\240\62\205\206\10\11B\307lv\210\204\32Tf\0\71\32|\377" - "\216)\64*\10\35\263\263C$\226\250I\71_\14\42\241\6\225\31\0A\26}\17S\271Si(\31" - "\65d\324\210q\366\356\301w\366\273\1B$}\17\203\232%KF\221\30\66b\330\210a#\206\215\30" - "Eb\311&\243H\14;g\317\36\204`\261\4\0D\33}\17C\42\65KF\15\31\66b\330\210q" - "\366\77;\66b\24\211%j\22\1E\21|\377\302\7)\347%\42\214F\316/\37<\60I\7so" - "\302\37$M$}\17\203\310r\346N\245Q\263\202E\12)L\224\60Q\302\310\20#C\214\14\61\23" - "\306L\30s\366\335\0T\15}\17\303\7\251\206\316\377\377\12\0X)~\37\303@\203\307H\14\33B" - "\210\14\21RC\206\241\63h\222(I\203\346\220\15\31E\204\14!\42\303F\20;h\341\0x\24\312" - "\336\302 CGH\240\61E\312\14\222)\6Y\64\0\0\0\0\4\377\377\0"; String version; @@ -246,7 +175,6 @@ void sendMIDIStop() { void receiveMIDI( uint8_t msg, uint8_t status ) { if (masterClockMode == 2) { - //int msg = NeoSerial.read(); if (msg == 0xF8) { //Clock MIDIClockReceived = true; } else if (msg == 0xFC) { //stop @@ -304,14 +232,7 @@ void clock() { // pull low all outputs after set pulse length if (tickCount >= PULSE_LENGTH) { for (byte i = 0; i < 6; i++) { - if (channels[i].mode == 4) { //channels in gate mode - if (gatePulseCount[i] == channels[i].gate * 100) { //I thought this would be number of pulses, but it seems to be msecs (??) that's why there's *100. need to investigate - digitalWrite(outsPins[i], LOW); - gatePulseCount[i] = 0; - } else { - gatePulseCount[i]++; - } - } else { //everything else + if (channels[i].mode != 4) { //everything but gate mode digitalWrite(outsPins[i], LOW); } } @@ -370,7 +291,7 @@ void externalClock() { } } -void sendTriggers() { +void sendTriggers() { //rename to onPulse or something for (byte i = 0; i < 6; i++) { if (playingModes[i] != subDivs[channels[i].subDiv] && playingModesOld[i] != playingModes[i]) { @@ -378,7 +299,6 @@ void sendTriggers() { playingModesOld[i] = playingModes[i]; } } - //16th notes for sequencer if (sixteenthPulseCount == 0) { bool *currentSeq; @@ -490,11 +410,19 @@ void sendTriggers() { randAmount = 10; } + if (channels[i].mode == 4) { //Gate mode turning off + gatePulseCount[i]++; + if (gatePulseCount[i] > channels[i].gate) { + digitalWrite(outsPins[i], LOW); + } + } + if ((channels[i].mode == 0 && channelPulseCount[i] == channels[i].offset) //CLK with offset || (channels[i].mode == 1 && channelPulseCount[i] == 0 && (random(10) + 1) > randAmount) //RND || (channels[i].mode == 4 && channelPulseCount[i] == 0) //gate ) { digitalWrite(outsPins[i], HIGH); + gatePulseCount[i] = 0; //reset gate here to avoid length "countdown" effect } if (channelPulseCount[i] < channelPulsesPerCycle[i]) { channelPulseCount[i]++; diff --git a/Software/Gravity/Interactions.ino b/Software/Gravity/Interactions.ino index 7f6822f..43860db 100644 --- a/Software/Gravity/Interactions.ino +++ b/Software/Gravity/Interactions.ino @@ -193,10 +193,10 @@ void checkInputs() { && displayTab != 0 && channels[displayTab - 1].mode == 4) { //Change GATE channels[displayTab - 1].gate = channels[displayTab - 1].gate + change; - if (channels[displayTab - 1].gate > 100) { + if (channels[displayTab - 1].gate > 63) { channels[displayTab - 1].gate = 0; - } else if (channels[displayTab - 1].gate > 40) { - channels[displayTab - 1].gate = 40; + } else if (channels[displayTab - 1].gate > 48) { + channels[displayTab - 1].gate = 48; } saveState(); } else if (insideTab && !shiftBtnPushed && !menuItemSelected) { @@ -395,8 +395,8 @@ void checkInputs() { if (!digitalRead(START_STOP_BTN_PIN) && !playBtnPushed) { if (masterClockMode == 0) { calculateBPMTiming(); - resetClocks(); if (!isPlaying) { + resetClocks(); isPlaying = true; sendMIDIStart(); } else { diff --git a/Software/Gravity/UI.ino b/Software/Gravity/UI.ino index 645102d..78c1b81 100644 --- a/Software/Gravity/UI.ino +++ b/Software/Gravity/UI.ino @@ -202,7 +202,7 @@ void updateScreen() { } else if (channels[displayTab - 1].mode == 3) { valueStr = F("SWING"); } else if (channels[displayTab - 1].mode == 4) { - valueStr = F("GATE"); + valueStr = F("PULSES"); } if ((!insideTab && shiftBtnPushed) || (insideTab && menuItem == 0)) { diff --git a/Software/Gravity/config.h b/Software/Gravity/config.h new file mode 100644 index 0000000..7df1f15 --- /dev/null +++ b/Software/Gravity/config.h @@ -0,0 +1,39 @@ +#pragma once + +#define PPQN 24 +#define PULSE_LENGTH 120 //1/10ms resolution. 12ms was failing at 1ms resolution at higher bpm. 60000/200/24 = 12.5 the max pulse length at 1ms resolution for 200bpm is 11ms +#define MAXBPM 200 //250 at 24ppqn with 5ms pulse will be 50/50 square wave +#define MINBPM 20 + +#define SCREEN_ADDRESS 0x3C + +// Rev 2+ Config +#define ENC_BTN_PIN 14 +#define ENC_D1_PIN 17 +#define ENC_D2_PIN 4 +#define START_STOP_BTN_PIN 5 +#define SHIFT_BTN_PIN 12 +#define EXT_INPUT_PIN 2 //needs to be an interrupt pin +#define ANALOGUE_INPUT_1_PIN A7 +#define ANALOGUE_INPUT_2_PIN A6 +const byte outsPins[6] = { 7, 8, 10, 6, 9, 11 }; +const byte clockOutPin = 3; +bool rotateScreen = false; +bool reverseEnc = false; +// + +/* Rev 1 Config +#define ENC_BTN_PIN 14 +#define ENC_D1_PIN 17 +#define ENC_D2_PIN 4 +#define START_STOP_BTN_PIN 5 +#define SHIFT_BTN_PIN 100 + +#define EXT_INPUT_PIN 2 //needs to be an interrupt pin +#define ANALOGUE_INPUT_1_PIN A2 +#define ANALOGUE_INPUT_2_PIN A1 + +const byte clockOutPin = 13; +const byte outsPins[6] = {6, 11, 7, 10, 8, 9}; +bool rotateScreen = true; +*/ diff --git a/Software/Gravity/fonts.h b/Software/Gravity/fonts.h new file mode 100644 index 0000000..667cdea --- /dev/null +++ b/Software/Gravity/fonts.h @@ -0,0 +1,39 @@ +#pragma once + + +//Font +const PROGMEM uint8_t velvetscreen[437] U8G2_FONT_SECTION("velvetscreen") = + "\64\0\2\2\3\3\2\3\4\5\5\0\0\5\0\5\0\0\221\0\0\1\230 \4\200\134%\11\255tT" + "R\271RI(\6\252\334T\31)\7\252\134bJ\12+\7\233\345\322J\0,\5\221T\4-\5\213" + "f\6.\5\211T\2/\6\244\354c\33\60\10\254\354T\64\223\2\61\7\353\354\222\254\6\62\11\254l" + "\66J*\217\0\63\11\254l\66J\32\215\4\64\10\254l\242\34\272\0\65\11\254l\206\336h$\0\66" + "\11\254\354T^\61)\0\67\10\254lF\216u\4\70\11\254\354TL*&\5\71\11\254\354TL;" + ")\0:\6\231UR\0A\10\254\354T\34S\6B\11\254lV\34)\216\4C\11\254\354T\324\61" + ")\0D\10\254lV\64G\2E\10\254l\206\36z\4F\10\254l\206^\71\3G\11\254\354TN" + "\63)\0H\10\254l\242\34S\6I\6\251T\206\0J\10\254\354k\231\24\0K\11\254l\242J\62" + "\225\1L\7\254lr{\4M\11\255t\362ZI\353\0N\11\255t\362TI\356\0O\10\254\354T" + "\64\223\2P\11\254lV\34)g\0Q\10\254\354T\264b\12R\10\254lV\34\251\31S\11\254\354" + "FF\32\215\4T\7\253dVl\1U\10\254l\242\63)\0V\11\255t\262Ne\312\21W\12\255" + "t\262J*\251.\0X\11\254l\242L*\312\0Y\12\255tr\252\63\312(\2Z\7\253df*" + "\7p\10\255\364V\266\323\2q\7\255\364\216\257\5r\10\253d\242\32*\2t\6\255t\376#w\11" + "\255\364V\245FN\13x\6\233dR\7\0\0\0\4\377\377\0"; + +const PROGMEM uint8_t stkL[569] U8G2_FONT_SECTION("stk-l") = + "\25\0\4\4\4\5\2\1\6\17\27\1\0\27\0\0\0\1\77\0\0\2\34%'\17\37\313\330R#&" + "\32!F\14\211I\310\24!\65\204(MF\21)Cd\304\10\62b\14\215\60Vb\334\20\0/\14" + "\272\336\336d\244\350\263q\343\0\60\37|\377\12\32\25\17\2\35\263\253ChD\30\21bB\14\242S" + "\306lv\350A\10\65H\0\61\24z\337\322\60R\205\314\234\31\61F\310\270\371\177\224\42\3\62\33|" + "\377\216\251$*\10\35\63\66r\206\304\314`c\252\34\301\221\263|\360\300\0\63\34|\377\216)\64*" + "\10\35\63\66r \71\332YIr\226\306\16\221P\203\312\14\0\64 |\377\226\220AC\306\20\31B" + "f\310\240\21\204F\214\32\61j\304(cv\366\200\305\312\371\0\65\32}\17\307\12.\206\316\213Bj" + "\226\214\42JtN\315\235\42\261&\325\31\0\66\33}\17\317\251\64+\206\235\63:/\314,aA\352" + "\234\335\235\42\261&\325\31\0\67\23|\377\302\212\7)\347Crt\70\345\300\221\363\16\0\70 |\377" + "\216)\64*\10\35\263\331!\22D\310\240\62\205\206\10\11B\307lv\210\204\32Tf\0\71\32|\377" + "\216)\64*\10\35\263\263C$\226\250I\71_\14\42\241\6\225\31\0A\26}\17S\271Si(\31" + "\65d\324\210q\366\356\301w\366\273\1B$}\17\203\232%KF\221\30\66b\330\210a#\206\215\30" + "Eb\311&\243H\14;g\317\36\204`\261\4\0D\33}\17C\42\65KF\15\31\66b\330\210q" + "\366\77;\66b\24\211%j\22\1E\21|\377\302\7)\347%\42\214F\316/\37<\60I\7so" + "\302\37$M$}\17\203\310r\346N\245Q\263\202E\12)L\224\60Q\302\310\20#C\214\14\61\23" + "\306L\30s\366\335\0T\15}\17\303\7\251\206\316\377\377\12\0X)~\37\303@\203\307H\14\33B" + "\210\14\21RC\206\241\63h\222(I\203\346\220\15\31E\204\14!\42\303F\20;h\341\0x\24\312" + "\336\302 CGH\240\61E\312\14\222)\6Y\64\0\0\0\0\4\377\377\0"; \ No newline at end of file