Old 12-12-2017, 12:43 PM   #1
TonE
Human being with feelings
 
Join Date: Feb 2009
Location: Reaper HAS send control via midi !!!
Posts: 4,032
Default Slonimskiator as jsfx?

Having Slonimskiator as jsfx would be cool, any skilled jsfx devs maybe?

video: https://vimeo.com/126063428
project description, blog post: https://medium.com/atchai/john-coltr...1-97c2eb889ff4
arduino code: https://github.com/johngriffin/slonimskiator

Of course improvements over this code are welcome.

Above code here, as it is quite short, 128 lines:
PHP Code:
#include <SoftwareSerial.h>

SoftwareSerial midi(56); // RX, TX

#define LED 3    // LED pin on Arduino board
#define RESET 2  // Reset button
#define MIDINOTEON 144 //144 = 10010000 in binary, note on command
#define MINNOTE 25
#define MAXNOTE 127
#define MINVELOCITY 90
#define MAXVELOCITY 90
#define P_RANGE 3
#define P_TRANSPOSE 4
#define P_LENGTH 5
#define P_SPEED 6
#define P_STARTNOTE 7

int transpose 1;
int length 1;
int range 0;
int speed 0;
int startnote 30;
int velocity 100;
boolean inReset false;

void setup() {
  
midi.begin(31250);        // Set MIDI baud rate: 31250
  
Serial.begin(115200);
  
  
randomSeed(analogRead(0));
  
  
pinMode(RESETINPUT);
  
attachInterrupt(0resetSequenceRISING);
}

void resetSequence()
{
  
digitalWrite(13, !digitalRead(13));    // Toggle LED on pin 13
  
inReset true;
}

// return a random sequence with a given length of notes
void generateSequence(int notes[], int num_notesint range) {
  
randomSeed(analogRead(0));
  for (
int i=0;i<num_notes;i++) {
    
notes[i] = random((1-range), (range-1));
  }
}

void loop() {

  
int note=startnote;
  
int breakout=false;
  
char direction 'A';  // Ascending or Descending  
  
updatePots();
  
int sequence[length];
  
generateSequence(sequencelengthrange);

  while (
1) {
    
    
// play inter/infra/ultra-polated sequence starting on note
    
for (int i=0i<lengthi++)  {
      
int seq_note note sequence[i];
      
MIDImessage(MIDINOTEONseq_noterandom(MINVELOCITYMAXVELOCITY)); //turn note on
      
delay(speed); //hold note
      
MIDImessage(MIDINOTEONseq_note0); //turn note off
      
delay(speed); //wait until triggering next note
      
      // if new pot values, or reset button is pressed, break the while loop
      
if (updatePots() || inReset) {
        
inReset false;
        return;
      }
      
      
// update speed and startnote without generating a new sequence
      
speed quantizePot(P_SPEED500);
      
int new_startnote quantizePot(P_STARTNOTE100);
      if (
new_startnote != startnote) {
        
note startnote new_startnote;
      }
    }
    
    
// switch direction between ascending and descending
    
if ((direction == 'A') && (note transpose range) > MAXNOTE) {
      
direction 'D';
    }
    if ((
direction == 'D') && (note transpose range) < startnote) {
      
direction 'A';
    }
    
    
// transpose
    
if (direction == 'A') {
      
note note transpose;
    }
    else 
note note transpose;
  }
}

boolean updatePots() {
  
int transpose_new quantizePot(P_TRANSPOSE12);
  
int length_new quantizePot(P_LENGTH5);
  
int range_new quantizePot(P_RANGE12);
  
int speed_new quantizePot(P_SPEED500);
  
  if ((
length == length_new) && (transpose == transpose_new) && (range == range_new)) return false;
  else {
    
length length_new;
    
transpose transpose_new;
    
range range_new;
    return 
true;
  }
}

int quantizePot(int pinint range) {
  
float sensorValue analogRead(pin);
  
  
// assume pot value is 0 - 1024
  // quantize to value between 1 and range
  
float value = ((sensorValue 1024) * (range-1)) + 1;
  return (int)
lround(value);
}

//send MIDI message
void MIDImessage(int commandint MIDInoteint MIDIvelocity) {
  
midi.write(command);//send note on or note off command 
  
midi.write(MIDInote);//send pitch data
  
midi.write(MIDIvelocity);//send velocity data

TonE is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:09 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.