encoder-control-bpm #1

Merged
dominic merged 4 commits from encoder-control-bpm into master 2026-02-19 23:23:31 -05:00
3 changed files with 0 additions and 171 deletions
Showing only changes of commit 95d8951846 - Show all commits

87
Out.cpp
View file

@ -1,87 +0,0 @@
// Out.cpp
#include "Arduino.h"
#include "Out.h"
#include "globals.h"
Out::Out(byte pin) {
this->pin = pin;
state = LOW;
divideMode = 1; // 1 divison | 0 multiplication
modifier = 1; // divide mode modifier (4x, /32, etc)
div = 1; // cycles needed before a pulse based on divide mode and modifier
cycle = 0; // how many cycles have passed since last pulse
divString = ""; // string for screen .. probably does not belong here
dur = 0; // how long pulse is on
width = 50; // pulse width
len = 0; // max len a pulse can be on, as determined by width
p = 100; // probability of a pulse
pinMode(pin, OUTPUT);
}
int Out::getState() {
return state;
}
void Out::setLen(unsigned long currentPeriod) {
len = (unsigned long)((double)currentPeriod * (width / 100.0) / 1000.0);
}
void Out::setDiv(int modifier, byte divide = 1) {
if (divide == 1) {
div = ppqn * modifier;
divString = "/" + modifier;
} else {
div = ppqn / modifier;
divString = "x" + modifier;
}
divideMode = divide;
this->modifier = modifier;
};
void Out::setWidth(int newWidth) {
width = newWidth;
if (divideMode == 1) {
len = (unsigned long)((double)(minute / BPM) * (width / 100.0) / 1000.0);
} else {
len = (unsigned long)((double)(minute / BPM / modifier) * (width / 100.0) / 1000.0);
}
};
void Out::setP(int prob) {
this->p = prob;
}
void Out::turnOn() {
cycle += 1;
byte pRes = 1;
if (cycle == div) {
if (p < 100) {
long r = random(1, 101);
if (r > p) {
pRes = 0;
}
}
if (pRes == 1) {
state = HIGH;
digitalWrite(pin, state);
dur = millis();
}
cycle = 0;
};
}
void Out::turnOff() {
if (state == HIGH && millis() - dur >= len) {
state = LOW;
digitalWrite(pin, state);
dur = 0;
};
}

33
Out.h
View file

@ -1,33 +0,0 @@
// Out.h
#ifndef Out_h
#define Out_h
#include <Arduino.h>
class Out {
private:
byte pin;
unsigned char state;
int cycle;
unsigned long dur;
unsigned long len;
byte width;
byte divideMode;
int div;
int modifier;
String divString;
int p;
public:
Out(byte pin);
void turnOn();
void turnOff();
void setLen(unsigned long currentPeriod);
void setDiv(int newDiv, byte divide = 1);
void setWidth(int newWidth);
void setP(int prob);
int getState();
};
#endif

View file

@ -1,51 +0,0 @@
#ifndef GLOBALS_H
#define GLOBALS_H
#include <Arduino.h>
extern byte BPM;
extern unsigned long minute;
extern unsigned long period;
extern byte ppqn;
#endif // GLOBALS_H
/*
TODO:
PRE-DAC:
[x] Figure out multiplicative beats X2 X4 X8 X16 X32?
[ ] Swing/Phase (same thing)
[x] Probability
[ ] Humanization
[ ] Euclidian Rhythms
[ ] Steps - # of steps for a full pattern
[ ] Hits - how many hits across the steps, must be less than steps
[ ] Offset - move the starting point of the pattern
[ ] Logic (NO | AND | OR | XOR)
[ ] Mute
[ ] Save
[ ] Load
POST-DAC:
[ ] Different Wave Forms
[ ] Different Voltage levels
[ ] v/oct?
100BPM
4800BPM
POSSIBLE DIVISIONS:
1: x48
16: x32
32: x16
40: x8
44: x4
46: x2
---
48*1: 1 ** THIS NEEDS TO BE PASSED IN AS DIVIDE MODE
48*2 = 96: /2
48*4 = 192: /4
48*8 = /8
48*16 = /16
*/