Sequencer/Arpeggiator?
Sequencer/Arpeggiator?
So i am designing a sequencer, 8 knobs with -5V to 5V range each and additional tempo knob. I would really appreciate any help and tips about how to make this iterating sequence of values.
- honki-bobo
- Posts: 310
- Joined: Sat Nov 09, 2019 1:18 pm
Re: Sequencer/Arpeggiator?
Hi there,
you will need to count samples and switch to the next value after a certain number of samples. E.g. at 120 BPM a single beat (usually 1/4 note) will take
where division is a multiple or a fraction of 1/4, depending on the clock you need. For 1/8th note division would be 2, for 1/16th note it would be 4 and so on.
You will also need some sort of playback control (start, stop), a reset mechanism to make the sequencer play from the beginning and maybe the ability to trigger the next value by an external clock signal.
Hope this gives you some ideas.
Happy coding and best regards,
Martin
you will need to count samples and switch to the next value after a certain number of samples. E.g. at 120 BPM a single beat (usually 1/4 note) will take
Code: Select all
double tempo = 120.0;
double division = 1.0;
double samplesPerBeat = Values.SampleRate * 60.0 / (tempo * division);
You will also need some sort of playback control (start, stop), a reset mechanism to make the sequencer play from the beginning and maybe the ability to trigger the next value by an external clock signal.
Hope this gives you some ideas.
Happy coding and best regards,
Martin
Re: Sequencer/Arpeggiator?
Thank you, i'll try this outhonki-bobo wrote: ↑Wed Jun 09, 2021 9:48 am Hi there,
you will need to count samples and switch to the next value after a certain number of samples. E.g. at 120 BPM a single beat (usually 1/4 note) will takewhere division is a multiple or a fraction of 1/4, depending on the clock you need. For 1/8th note division would be 2, for 1/16th note it would be 4 and so on.Code: Select all
double tempo = 120.0; double division = 1.0; double samplesPerBeat = Values.SampleRate * 60.0 / (tempo * division);
You will also need some sort of playback control (start, stop), a reset mechanism to make the sequencer play from the beginning and maybe the ability to trigger the next value by an external clock signal.
Hope this gives you some ideas.
Happy coding and best regards,
Martin
Re: Sequencer/Arpeggiator?
Could somebody please explain me the way how to switch to the next value after calculating number of samples? i have tried TimerTask, conditions, Named Timer but i am definitely lacking knowledge on how to do it right
Re: Sequencer/Arpeggiator?
processSample is called once per sample. All you need to do is create a persistent counter that increments. If it reaches samplesPerBeat as Martin explained, there you go.
Re: Sequencer/Arpeggiator?
i need to do 8 different SetValue after every samplesPerBeat is passed and then when sequence reaches the last value it should reset and start over. I didn't manage to do this with for, while loops. there is probably easier and obvious solution but i am really stupid to see this.
- honki-bobo
- Posts: 310
- Joined: Sat Nov 09, 2019 1:18 pm
Re: Sequencer/Arpeggiator?
Use a double[] to store the CV values of your sequence
and set the values in Notify accordingly:
(assuming knob_1 to knob_8 are your sequence knobs 1 to 8)
In ProcessSample(), count past samples and update stepCounter accordingly:
Some general advice:
- keep ProcessSample() as short as possible
- keep GUI code out of ProcessSample()
Code: Select all
// Add your own variables and functions here
double[] knobs = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
double tempo = 120.0;
double division = 1.0;
double samplesPerBeat = Values.SampleRate * 60.0 / (tempo * division);
int stepCounter = 0;
int sampleCounter = 0;
(assuming knob_1 to knob_8 are your sequence knobs 1 to 8)
Code: Select all
public boolean Notify( VoltageComponent component, ModuleNotifications notification, double doubleValue, long longValue, int x, int y, Object object ) {
switch( notification ) {
case Knob_Changed: {
if (component == knob_1) {
knobs[0] = doubleValue;
}
else if (component == knob_2) {
knobs[1] = doubleValue;
}
else if (component == knob_3) {
knobs[2] = doubleValue;
}
else if (component == knob_4) {
knobs[3] = doubleValue;
}
else if (component == knob_5) {
knobs[4] = doubleValue;
}
else if (component == knob_6) {
knobs[5] = doubleValue;
}
else if (component == knob_7) {
knobs[6] = doubleValue;
}
else if (component == knob_8) {
knobs[7] = doubleValue;
}
else if (component == tempo_knob) {
tempo = doubleValue;
samplesPerBeat = Values.SampleRate * 60.0 / (tempo * division);
}
// if you don't have a division knob, you can omit this
else if (component == division_knob) {
division = doubleValue;
samplesPerBeat = Values.SampleRate * 60.0 / (tempo * division);
}
}
}
}
Code: Select all
public void ProcessSample()
{
if (sampleCounter >= samplesPerBeat) {
sampleCounter = 0;
stepCounter = (stepCounter + 1) % 8;
}
outputJack.SetValue(knobs[stepCounter]);
sampleCounter++;
}
Some general advice:
- keep ProcessSample() as short as possible
- keep GUI code out of ProcessSample()
Re: Sequencer/Arpeggiator?
A big thanks to everyone for your help, now i finally understand how it's done.