Last active
October 8, 2017 07:52
-
-
Save kuguma/015c8810901ba88dbe2fdc75a061cab5 to your computer and use it in GitHub Desktop.
Lifegame & MIDI Sequencer for ROLI BLOCKS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
<metadata description="The Lifegame" target="Lightpad" tags="Game;Midi;"> | |
<modes> | |
<mode name="Default"> | |
<variable name="xCC" value="113"/> | |
<variable name="yCC" value="114"/> | |
<variable name="zCC" value="115"/> | |
<variable name="channel" value="1"/> | |
<variable name="interval" value="4"/> | |
<variable name="colour" value="0xFF00FBFF"/> | |
<variable name="aftercolour" value="0xFF006062"/> | |
<variable name="backgroundColour" value="0xFF000402"/> | |
<variable name="send" value="All"/> | |
</mode> | |
</modes> | |
<variables> | |
<variable name="xCC" displayName="X axis CC" type="int" min="0" max="127" value="113" displayMode="stepper" /> | |
<variable name="yCC" displayName="Y axis CC" type="int" min="0" max="127" value="114" displayMode="stepper" /> | |
<variable name="zCC" displayName="Z axis CC" type="int" min="0" max="127" value="115" displayMode="stepper" /> | |
<variable name="channel" displayName="MIDI Channel" type="int" min="1" max="8" value="1" displayMode="stepper" /> | |
<variable name="interval" displayName="speed" type="int" min="0" max="6" value="4" displayMode="stepper" /> | |
<variable name="colour" displayName="Touch colour" type="colour" value="0x00FBFF" /> | |
<variable name="aftercolour" displayName="After colour" type="colour" value="0x006062" /> | |
<variable name="backgroundColour" displayName="Background colour" type="colour" value="0x000402" /> | |
<variable name="send" displayName="Send" type="option" value="All" options="All;X;Y;Z;" /> | |
</variables> | |
</metadata> | |
*/ | |
#heapsize: 466 | |
//============================================================================== | |
/* | |
Heap layout: | |
=== 25 x Pad === | |
0 1 byte x 225 on_off | |
225 1 byte x 225 on_off(buf) | |
=== Scale === | |
450 1 byte x 16 scale | |
*/ | |
int buf_toggle; | |
int current; | |
int next; | |
int cnt; | |
int prev_note; | |
int scale_offset; | |
int pitch_offset; | |
void initialise() | |
{ | |
for (int i = 0; i < 32; ++i) | |
setLocalConfigActiveState (i, false, false); | |
buf_toggle = 0; | |
prev_note = 0; | |
scale_offset = 450; | |
setHeapByte(scale_offset+0, 48); | |
setHeapByte(scale_offset+1, 55); | |
setHeapByte(scale_offset+2, 62); | |
setHeapByte(scale_offset+3, 64); | |
setHeapByte(scale_offset+4, 67); | |
setHeapByte(scale_offset+5, 69); | |
setHeapByte(scale_offset+6, 71); | |
setHeapByte(scale_offset+7, 74); | |
setHeapByte(scale_offset+8, 81); | |
setHeapByte(scale_offset+9, 55); | |
setHeapByte(scale_offset+10, 55); | |
setHeapByte(scale_offset+11, 55); | |
setHeapByte(scale_offset+12, 55); | |
setHeapByte(scale_offset+13, 55); | |
setHeapByte(scale_offset+14, 55); | |
setHeapByte(scale_offset+15, 55); | |
pitch_offset = 12; | |
} | |
void handleTouch (int index, float x, float y, float z, float scale) | |
{ | |
if (index == 1) | |
{ | |
if (send == 0 || send == 1) sendMIDI (0xB0 | (channel - 1), xCC, int (x * 0.5 * 127)); | |
if (send == 0 || send == 2) sendMIDI (0xB0 | (channel - 1), yCC, 127 - int (y * 0.5 * 127)); | |
if (send == 0 || send == 3) sendMIDI (0xB0 | (channel - 1), zCC, int (z * 127)); | |
addPressurePoint (colour, x, y, z * scale); | |
int x_int = int(x*7.5); | |
int y_int = int(y*7.5); | |
//drawNumber(scale_int, 0xffffffff, 0, 1); | |
setHeapByte(x_int+y_int*15+next, 0x01); | |
} | |
} | |
void handleButtonDown(int index){ | |
//drawNumber(index, 0xffffffff, 0, 1); | |
if (pitch_offset<20){ | |
pitch_offset = pitch_offset + 1; | |
}else{ | |
pitch_offset = 12; | |
} | |
} | |
void touchStart (int index, float x, float y, float z, float vz) | |
{ | |
handleTouch (index, x, y, z, 75.0); | |
} | |
void touchMove (int index, float x, float y, float z, float vz) | |
{ | |
handleTouch (index, x, y, z, 20.0); | |
} | |
void repaint() | |
{ | |
int velocity = 80; | |
int note = 55; | |
cnt++; | |
if (cnt==interval){ | |
cnt=0; | |
if (buf_toggle == 0) { | |
buf_toggle = 1; | |
current = 0; | |
next = 225; | |
}else{ | |
buf_toggle = 0; | |
current = 225; | |
next = 0; | |
} | |
fillRect (backgroundColour, 0, 0, 15, 15); | |
drawPressureMap(); | |
int total = 0; | |
for(int x=0; x<15; ++x){ | |
for(int y=0; y<15; ++y){ | |
int me=x+y*15; | |
int val = getHeapByte(me+current); | |
bool live = val==0x01; | |
if (val==0x01) fillPixel(colour, x,y); | |
if (val==0x02) fillPixel(aftercolour, x,y); | |
int x_dec = x==0?14:x-1; | |
int y_dec = y==0?14:y-1; | |
int x_inc = x==14?0:x+1; | |
int y_inc = y==14?0:y+1; | |
int l = getHeapByte(x_dec+y*15+current); | |
int r = getHeapByte(x_inc+y*15+current); | |
int u = getHeapByte(x+y_dec*15+current); | |
int d = getHeapByte(x+y_inc*15+current); | |
int lu = getHeapByte(x_dec+y_dec*15+current); | |
int ld = getHeapByte(x_dec+y_inc*15+current); | |
int ru = getHeapByte(x_inc+y_dec*15+current); | |
int rd = getHeapByte(x_inc+y_inc*15+current); | |
int sum = l+r+u+d+lu+ld+ru+rd; | |
int next_val = 0; | |
if(sum==3 && !live) next_val = 0x01; | |
else if( (sum==3 || sum==2) && live) next_val = 0x01; | |
else if(sum<=1 && live) next_val = 0x00; | |
else if(sum>=4 && live) next_val = 0x02; | |
setHeapByte(me+next,next_val); | |
total = total + next_val; | |
} | |
} | |
//drawNumber(total, 0xffffffff, 0, 1); | |
int limit = total/10; | |
int wait = getRandomInt(3); | |
sendNoteOff (channel, prev_note, velocity); | |
if (wait<limit+1){ //wait<limit+1 | |
note = getHeapByte(scale_offset+getRandomInt(limit)) + pitch_offset; | |
sendNoteOn (channel, note, velocity); | |
sendAftertouch(channel, note, limit*10); | |
} | |
prev_note = note; | |
} | |
fadePressureMap(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment