Skip to content

Instantly share code, notes, and snippets.

@unohee
Last active May 3, 2016 00:22
Show Gist options
  • Select an option

  • Save unohee/6b6e04231349b8220147403270b0ab40 to your computer and use it in GitHub Desktop.

Select an option

Save unohee/6b6e04231349b8220147403270b0ab40 to your computer and use it in GitHub Desktop.
Sequencer snippets for Infinite Machine
void Sequencer::setup(unsigned int length, int pulse, float _radius, int mode){
angle = 360.f / (float)length;
seq_len = length;
radius = _radius;
nrCircle = 1;
angleStep = 360 / nrCircle;
Bjorklund::setup(length, pulse);
iter();
//init array
steps.clear();
innerPoly.setMode(OF_PRIMITIVE_LINE_LOOP);
//GUI UPDATE
for(int i=0; i < gui.size();i++){
delete gui[i];
}
gui.clear();
for(int i =0; i < nrCircle; i ++){
circleGUI* circleButtons = new circleGUI();
circleButtons->centre = centre;
circleButtons->radius = radius;
circleButtons->createMesh();
gui.push_back(circleButtons);
}
}
//--------------------------------------------------------------
void Sequencer::setClock(int BPM, int ticks){
bps = BPM / 60.f * ticks;
}
//--------------------------------------------------------------
void Sequencer::setNote(int pitch){
note = pitch;
}
//--------------------------------------------------------------
void Sequencer::update(int x,int y){
centre = ofVec2f(posX, posY);
float currentX = x - centre.x;
float currentY = y - centre.y;
cout<<"Mouse X :"<<currentX<<" Y : "<<currentY<<endl;
//updating all position of steps
for(int i = 0; i < seq_len; i++){
steps.insert(steps.begin()+i, ofVec2f(centre.x + radius * cos(angle*i*PI/180),centre.y + radius * sin(angle*i*PI/180)));
}
vector<ofVec3f> polyOutline;
//updating vertices of all sequence's step
for(int i = 0; i < seq_len; i++){
if(slots.size() > 0){
if(slots.at(i)== true){
//updating inner mesh
innerPoly.addVertex(steps.at(i)); //front vertices
innerPoly.setupIndicesAuto();
innerPoly.addColor(ofFloatColor(1,1,1));
polyOutline.push_back(steps.at(i));
if(currentX == steps.at(i).x-centre.x && currentY == steps.at(i).y-centre.y){
cout<<"CONTACTED"<<endl;
}
}
}
//Clock
clock.addVertex(ofPoint(centre));
clock.addVertex(steps.at(playHead));
}
for(int i =0; i < innerPoly.getNumVertices();i++){
circle* detectionArea = new circle();
detectionArea->radius = 15.0f;
detectionArea->position = polyOutline.at(i)-centre;
detectionArea->display();
detectionArea->update(currentX, currentY);
areas.push_back(detectionArea);
}
vector<ofVec3f> translated;
for(int i=0; i < polyOutline.size();i++){
translated.push_back(polyOutline.at(i)-centre);
}
}
//--------------------------------------------------------------
void Sequencer::draw(int x, int y){
posX = x;posY = y;
bool curved = false;
glPushMatrix();
//Cyclical Polygon
innerPoly.draw();
innerPoly.clear();
ofSetColor(255, 0, 0);
if(bPlay && slots.size() > 0){
if(slots.at(playHead) == true && bPlay)clock.draw();
clock.clear();
}
glPopMatrix();
}
//--------------------------------------------------------------
void Sequencer::offset(int offset){
vector<bool>seq;
// simple rotation to the left
std::rotate(slots.begin(), slots.begin() + offset, slots.end());
}
//--------------------------------------------------------------
void Sequencer::play(bool isPlay){
bPlay = isPlay;
//clock ticks here..
currentCount=floor(counter.phasor(bps));//this sets up the metronome that ticks in every second, amount of tick is based on BPM conversion above.
//iterate playHead with Sequences.
if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound
if(isPlay)
{
notePlayed=getSequence(playHead%seq_len); //get the value out of the array for the sequence.
playHead++;
if(playHead==seq_len) playHead = 0;
lastCount=0;
sendNote(note,127, 200,notePlayed);
}
else{
playHead = 0;
}
}
}
//--------------------------------------------------------------
bool Sequencer::trigger(){
if(notePlayed){
return 1;
}else{
return 0;
}
return NAN;
}
//--------------------------------------------------------------
#ifndef Sequencer_h
#define Sequencer_h
#include "ofxMaxim.h"
#include "Bjorklund.h"
#include "Network.h"
#include "circleGUI.h"
class Sequencer : public Bjorklund, public Network, public ofBaseApp {
public:
void setup(unsigned int length, int pulse, float radius, int mode);
void setClock(int BPM, int ticks);
void setNote(int pitch);
void setNote(float frequency);
void offset(int offset);
void update(int x, int y);
void draw(int x, int y);
void play(bool isPlay);
bool trigger();
void mouse(int x, int y);
ofPoint centre;
private:
bool notePlayed;
bool bPlay;
int nrCircle;
float angleStep;
int seq_len;
int note;
float angle, radius, innerRadius;
float posX, posY;
//Graphics
vector<ofPoint>steps;
ofMesh innerPoly;
ofPolyline clock;
vector<circleGUI*> gui;
//play method
//Transport Control (Maximilian)
maxiOsc counter; //Phasor object
maxiClock mClock;
double bps;
int currentCount;
int lastCount, playHead;
};
#endif /* Sequencer_h */
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment