Sequencer/Arpeggiator?

Post Reply
aintteyen
Posts: 7
Joined: Fri Jan 08, 2021 5:05 pm

Sequencer/Arpeggiator?

Post by aintteyen » Wed Jun 09, 2021 8:36 am

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.

User avatar
honki-bobo
Posts: 146
Joined: Sat Nov 09, 2019 1:18 pm

Re: Sequencer/Arpeggiator?

Post by honki-bobo » 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
Image
Monkey Business Audio
Modules - Forum

aintteyen
Posts: 7
Joined: Fri Jan 08, 2021 5:05 pm

Re: Sequencer/Arpeggiator?

Post by aintteyen » Wed Jun 09, 2021 9:52 am

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

aintteyen
Posts: 7
Joined: Fri Jan 08, 2021 5:05 pm

Re: Sequencer/Arpeggiator?

Post by aintteyen » Wed Jun 09, 2021 6:27 pm

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 :(

robgray
Posts: 24
Joined: Wed May 06, 2020 2:06 pm

Re: Sequencer/Arpeggiator?

Post by robgray » Wed Jun 09, 2021 8:27 pm

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.

aintteyen
Posts: 7
Joined: Fri Jan 08, 2021 5:05 pm

Re: Sequencer/Arpeggiator?

Post by aintteyen » Thu Jun 10, 2021 11:43 am

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.

User avatar
honki-bobo
Posts: 146
Joined: Sat Nov 09, 2019 1:18 pm

Re: Sequencer/Arpeggiator?

Post by honki-bobo » Thu Jun 10, 2021 9:34 pm

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()
Image
Monkey Business Audio
Modules - Forum

aintteyen
Posts: 7
Joined: Fri Jan 08, 2021 5:05 pm

Re: Sequencer/Arpeggiator?

Post by aintteyen » Fri Jun 11, 2021 6:30 am

A big thanks to everyone for your help, now i finally understand how it's done.

Post Reply