Jump to content

MIOS Beginner's 16 step seq project


DrBunsen

Recommended Posts

This is a way for beginners to learn how to work with PIC and MIOS code from the ground up, by building a very simple device.

/edit/ TK, should I move this into the MIOS programming forum?

Basic ideas:

Instead of stripping features out of the MIDIbox SEQ to arrive at a Roland x0x clone, start simple and build in only what you need.  The basic version doesn't even use MIDI.

Start with 16 steps, one output.  DIN sync input for timing, can be provided by the Clockbox (see below), or another drum machine (no MIDI handling required).  The output is a +ve voltage pulse for triggering analogue drums.

Modularise the code as much as possible to allow for expansion to future cases - ie more voices, more steps ... but

Avoid feature creep - this is intended as the MIOS equivalent of a "Hello World!" program.

See this thread

/snip/

Check out the Clockbox under MIOS toy of the week.  And this link here implements a simple 16 step seq without even a PIC - just logic.  There are good suggestions there we could use.

Here is an 80 LED matrix off one core - actually 80 connections to red-green-blue LEDs but it comes to the same thing.  80 is 16 steps by 5 voices.

Have a large box of pre-assembled LED matrixes, will trade for parts.

Link to comment
Share on other sites

  • 3 months later...
  • 1 month later...

Hey, i'm very interested too !

A basic 16 step loop sequencer could be a very good start.

So, where is the code ?? ;)

I'm on the idea, but i didn't start, i even dont know how the pattern structure will look like, but i want to stick with very simple stuff, fixed length notes and velocity, strictly (basic) rythm minded as a starting point.

Link to comment
Share on other sites

Good to hear mate :)

Plan at the moment is something like this... We start with the ClockBox app. First thing is a single 8-step pattern with fixed values for everything so basically a C-Major scale or something, with a play, pause and a stop button. After that, introduce features one-by-one, and share the code with everyone as we go. So next up might be note values, then looping/direction, then velocity, then note length, then extra tracks, then more steps per track, etc etc.

As each person reaches a point where they need to branch off then they can do just that, no sweat. For example, if we were to go in the same order as above, once I get past the items I have listed, my next step would be multiple clocks, and that's probably where I'll end up solo...

Link to comment
Share on other sites

  • 4 weeks later...

Don't worry about the delay, it's not a problem :) (I have plenty of stuff to keep me busy  ::))

Man I'm sorry to hear about the accident!! I hope you're left handed!  :-\ I'm not, and I broke my right hand a few years back, it was such a pain in the ass! (Not to mention my hand, heheheh) What kind of fracture is it? Never mind, I won't ask you to type!

Take good care, and I hope you're back in action soon!

Link to comment
Share on other sites

  • 2 weeks later...

Here we go.

So, as mentioned before, this is a very simple, as a tutorial, sequencer example using the TK clockbox program as base...

The variables, counters etc, are written in a "beginner friendly" way ;)

In file mclock.c, func MCLOCK_Tick(void) is called periodicaly, 24 times per step, and theres 4 step in a mesure.

(I'm not sure about the wording  :-\ )

Here, we're going to play 16 notes in a mesure (so each step is divided by 4)

In that function, we're going to call our own function "STEPSEQ();"

  // increment the meter counters
  STEPSEQ();
We have to set 16 notes in a pattern, i set them this way :
//unsigned char pattern[16];//16 notes pattern
const char pattern[16]={//16 notes pattern (values are midi notes number)
	{48},//note 1
	{60},//note 2
	{48},//
	{60},//
	{48},//
	{60},//
	{72},//
	{60},//
	{48},//
	{50},//
	{62},//
	{50},//
	{62},//
	{70},//
	{80},//
	{95},//note 16
};

/*
Notes to midi table
-------------------
Octave||                     Note Numbers (midi)
   #  ||
      || C   | C#  | D   | D#  | E   | F   | F#  | G   | G#  | A   | A#  | B
-----------------------------------------------------------------------------
   0  ||   0 |   1 |   2 |   3 |   4 |   5 |   6 |   7 |   8 |   9 |  10 | 11
   1  ||  12 |  13 |  14 |  15 |  16 |  17 |  18 |  19 |  20 |  21 |  22 | 23
   2  ||  24 |  25 |  26 |  27 |  28 |  29 |  30 |  31 |  32 |  33 |  34 | 35
   3  ||  36 |  37 |  38 |  39 |  40 |  41 |  42 |  43 |  44 |  45 |  46 | 47
   4  ||  48 |  49 |  50 |  51 |  52 |  53 |  54 |  55 |  56 |  57 |  58 | 59
   5  ||  60 |  61 |  62 |  63 |  64 |  65 |  66 |  67 |  68 |  69 |  70 | 71
   6  ||  72 |  73 |  74 |  75 |  76 |  77 |  78 |  79 |  80 |  81 |  82 | 83
   7  ||  84 |  85 |  86 |  87 |  88 |  89 |  90 |  91 |  92 |  93 |  94 | 95
   8  ||  96 |  97 |  98 |  99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107
   9  || 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119
  10  || 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 |*/

Before the MCLOCK_Tick(void) declaration, we have to set the STEPSEQ() func :
void STEPSEQ(void){

	if( _tik == 24 )_tik=0;
	// PATTERN PLAY //

	if(_tik==0 || _tik==6 || _tik==12 || _tik==18){ // Times are divised by for this way (there 24 _tik in a time)

		if(step==16){
			step=0;//16 step reset
		}

		// NOTE OFF (previously played note)
		MIOS_MIDI_TxBufferPut(144 + 0);//Note On, channel 0 (+1)
		MIOS_MIDI_TxBufferPut(lastep);//last played note
		MIOS_MIDI_TxBufferPut(0x00);//velocity 0 (=> equ Note off)

		// PLAY NOTE
		MIOS_MIDI_TxBufferPut(144 + 0);//Note On, channel 0 (+1)
		MIOS_MIDI_TxBufferPut(pattern[step]);//play note
		MIOS_MIDI_TxBufferPut(0x7f);//velocity 127

		lastep=pattern[step];//mem last played note, to turn it off next time
		step++;//16 step counter
	}
	_tik++;
	return;
}

This should work.

Now you can add velocity,

more steps, multiple channels, CC's etc, i hope it can help some peoples who dont know how to start ;)

get a ready made mclock.c file here : http://jambonbill.free.fr/DIY/miniseq/mclock.c

I'm not a C guru, please feel free to comment and correct anything.

Enjoy

Link to comment
Share on other sites

Here we go.

I'm not a C guru, please feel free to comment and correct anything.

//unsigned char pattern[16];//16 notes pattern
const char pattern[16]={//16 notes pattern (values are midi notes number)
	{48},//note 1
	{60},//note 2
	{48},//
	{60},//
	{48},//
	{60},//
	{72},//
	{60},//
	{48},//
	{50},//
	{62},//
	{50},//
	{62},//
	{70},//
	{80},//
	{95},//note 16
};
It's a minor nit but there is no need to put braces { } around the individual values in the initialization of the pattern array.
const char pattern = { 48, 60, 48, 60,  48, 60, 72, 60, 48, 50,  62, 50, 62, 70, 80, 95};

I'll look at the rest when I get home tonight.  Thanks for sharing this code with us!

Link to comment
Share on other sites

You could improve the readability of a sequence by using constants (#define) for each note value.

Unfortunately # (for major) is not allowed in a macro name, but "m" should do the same:


#define NOTE_____  0
#define NOTE_Cm0  1
#define NOTE_D_0  2
#define NOTE_Dm0  3
...
#define NOTE_C_4  48
#define NOTE_Cm4  49
#define NOTE_D_4  50
...
[/code] Now you can program sequences in this way:
[code]
const char pattern[] = {
  NOTE_C_4,
  NOTE_C_5,
  NOTE_C_4,
  NOTE_C_5,
...
};

As you can see, I've already prepared a NOTE____ for an empty step. This is a simple solution, because it's very unlikely that somebody wants to play C_0

Alternatively, you could define an empty note as 0x80 ... in fact, 0x80 and 0xff can be easily used for extensions, such as chords, arpeggio definitions (entry number in the sorted list of held keys), or other control words

Back to the implementation: the #define's should be put into a seperate include file

You could also think about the integration of your sequencer routines into a seperate .c file - than earlier, than better.

Just do it in a similar way like it has been done for the MCLOCK_* routines. Create a seq.c and seq.h file, and announce the new .c file in MAKEFILE.spec

Best Regards, Thorsten.

Link to comment
Share on other sites

Note: if the 16 step encoders are not stuffed' date=' the parameters can be modified by pressing the appr. general purpose button two times. Thereafter the value can be changed with the datawheel (hint: this means that [b']a nice MBSEQ based drum computer can be built without the 16 encoders)

!!!

Those magic words from TK that I missed all along have changed my mind.  I am likely to start with the SEQ app, strip out note and melody handling etc, to make room for new features, like extra DOUT or CV triggers, LED matrix, button matrix etc.  There's too much good code already written (thanks TK - a "Magic 5000" gift is on its way) to throw away IMHO.  However, I am still interested in sharing code amongst all, and I hope the independant ideas progress.

One idea I've just had - a 2 bit AOUT!  Four analogue values (3 + 0v) would be enough to implement velocity on each voice.  I have been wracking my brains to come up with a simple velocity implementation, and this is the simplest I can come up with in hardware.  No idea about the coding.

First task for me is to complete a basic SEQ hardware and play with it.  Then with a firm idea of the handling, I will know where I want to extend or simplify it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...