commonsound
kits ... forum ... about us ... contact ... license ... 4ms Pedals
 
Building How-to » Bend Matrix » MIDI SYNC IN / tempo implementation question
MIDI SYNC IN / tempo implementation question [message #2455] Thu, 18 February 2010 14:32 Go to next message
smrl  is currently offline smrl
Messages: 23
Registered: February 2010
Junior Member
OK, looking at MIDI, I'm noticing it hasn't been implemented how I had thought it might be.

So, am I correct here: the MIDI clock signal gets applied to the changing of patches ONLY, and does not get predicted as an internal tempo?

The internal tempo (denoted by the blinking LED that's not on the char. display) seems to be the tempo source that drives the arpeggiation, but is not altered by incoming sync.

Re: MIDI SYNC IN / tempo implementation question [message #2459] Sat, 20 February 2010 11:35 Go to previous messageGo to next message
dann  is currently offline dann
Messages: 829
Registered: December 2002
Location: Austin TX
Senior Member
The incoming MIDI clock should drive the bend matrix's internal clock just like the tempo knob/flashing LED does. Actually it merges the internal clock with the external (MIDI sync) clock, so any time either of those generates a pulse, it will go to the next step in the sequence.
If you want to run just the external clock, turn the internal clock down to 2bpm (or something slower than the MIDI clock) and make sure the MIDI mode isn't "nOC" (NO-CLOCK mode). You can just set it to "ALL" to be safe...



The code for this is in midi.c, in the read_midi() function. First it checks to see if we're in NO-CLOCK mode. If not, then it counts how many times we receive a 0xF8 MIDI command (clock sync). When it gets 24 of clcok sync commands, it sets the clockreceived flag to 1. This is the standard MIDI use of clock sync, to send them out 24x the bpm that you actually are using

if (midi_mode!=4){ 	//mode 4 is NO-Clock mode
	if (midi_in == 0xF8) {
		if (++clocks_recvd==24) {
			clocks_recvd=0;
			clockreceived=1;
			seven_seg[3]|=BIT(1);
		}  else if (clocks_recvd==6) seven_seg[3]&=~BIT(1);
	}
}


(The stuff with seven_seg[3] is just for flashing the light on the bpm display)

Then in bendmatrix.c, in the do_play_mode() function, it checks to see if the internal clock has timed out (play_timer), or if clockreceived has been set (by the code above):

if ((inttimerreached(&play_timer,60000/use_bpm)) || (clockreceived)){
...
get_nextstep(&nextbank,&nextcur);
Re: MIDI SYNC IN / tempo implementation question [message #2461] Sat, 20 February 2010 13:06 Go to previous messageGo to next message
smrl  is currently offline smrl
Messages: 23
Registered: February 2010
Junior Member
OK, I think I follow. So use_bpm is the internal clock which you OR with clockreceived?

The arp knob effect doesn't reference clockreceived at all. It seems to be arpeggiating at the rate determined by use_bpm.

If this is the case, the arpeggiation will always be out-of-sync with the MIDI clock, to some degree...

This is the relevant snippet


uint8_t do_arp(uint8_t k, uint8_t directionain, uint8_t speedain, uint8_t matrixhalf, uint8_t *somethingchanged){

...

	use_bpm=get_use_bpm();

	timebase=15000/(use_bpm*speedain);
	if (speedain<15)  timebase=timebase*4; //gets around having to use 60000 which is not a short integer

	if (k==0) 	timerstepped=inttimerreached(&arp_timer0,timebase);
	else if (k==1) 	timerstepped=inttimerreached(&arp_timer1,timebase);
	else if (k==2) 	timerstepped=inttimerreached(&arp_timer2,timebase);
	else 			timerstepped=inttimerreached(&arp_timer3,timebase);

	if (k==0) arp_i=arp_i0;
	else if (k==1) arp_i=arp_i1;
	else if (k==2) arp_i=arp_i2;
	else if (k==3) arp_i=arp_i3;
			

	*somethingchanged=0;
	if (timerstepped || just_stepped){

Re: MIDI SYNC IN / tempo implementation question [message #2464] Sat, 20 February 2010 23:38 Go to previous message
dann  is currently offline dann
Messages: 829
Registered: December 2002
Location: Austin TX
Senior Member
Ah, I understand your OP now. You're right, use_bpm (and thus arp mode) doesn't know anything about the external MIDI clock. I could patch this feature in by having read_midi() calculate the amount of time passed between 24 MIDI sync messages, and store this in a variable ext_bpm. Then get_use_bpm() could return ext_bpm if we're synced to an external clock... or it could return the interal clock (which is what it's already doing) if we're on internal clock.

this might mean changing how the user selects internal or external clock, right now the internal clock is always active. There would have to be a way to turn the internal clock off (at least for arp mode) and use the external clock only. Or maybe get_use_bpm() could return the *faster* of ext_bpm and the internal bpm? hmm....
Previous Topic:voltage check failure
Next Topic:Enclosure depth?
Goto Forum:
  


Current Time: Sat May 18 06:31:27 EDT 2013
.:: Contact :: Home ::.

Powered by: FUDforum 2.6.6.
Copyright ©2001-2004 FUD Forum Bulletin Board Software