Page 1 of 1

Sequencer/Arpeggiator?

Posted: Wed Jun 09, 2021 8:36 am
by aintteyen
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.

Re: Sequencer/Arpeggiator?

Posted: Wed Jun 09, 2021 9:48 am
by honki-bobo
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

Code: Select all

double tempo = 120.0;
double division = 1.0;
double samplesPerBeat = Values.SampleRate * 60.0 / (tempo * division);
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

Re: Sequencer/Arpeggiator?

Posted: Wed Jun 09, 2021 9:52 am
by aintteyen
honki-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 take

Code: Select all

double tempo = 120.0;
double division = 1.0;
double samplesPerBeat = Values.SampleRate * 60.0 / (tempo * division);
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
Thank you, i'll try this out

Re: Sequencer/Arpeggiator?

Posted: Wed Jun 09, 2021 6:27 pm
by aintteyen
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?

Posted: Wed Jun 09, 2021 8:27 pm
by robgray
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?

Posted: Thu Jun 10, 2021 11:43 am
by aintteyen
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.

Re: Sequencer/Arpeggiator?

Posted: Thu Jun 10, 2021 9:34 pm
by honki-bobo
Use a double[] to store the CV values of your sequence

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;
and set the values in Notify accordingly:
(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);
			}
		}
	}
}
In ProcessSample(), count past samples and update stepCounter accordingly:

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?

Posted: Fri Jun 11, 2021 6:30 am
by aintteyen
A big thanks to everyone for your help, now i finally understand how it's done.