Author |
Message |
blue hell
Site Admin
Joined: Apr 03, 2004 Posts: 24079 Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320
|
Posted: Fri Jul 12, 2013 11:37 am Post subject:
|
|
|
OK
You probably will want to handle MIDI reception in an interrupt routine of your own. Likely you will also want to have a means to look up the time of reception of the Midi clock bytes ... this may need some tinkering.
Once you have two times from the difference of thosetimes you can calculate the needed delay for your sequencer.
To get a good reference clock you may need a timer interrupt, and the tinkering will be in what to do when you get a time overflow - or maybe you will find a trick to avoid overflows.
That should be about it, in principle. _________________ Jan
also .. could someone please turn down the thermostat a bit.
|
|
Back to top
|
|
|
capicoso
Joined: Nov 19, 2012 Posts: 128 Location: Argentina
|
Posted: Fri Jul 12, 2013 12:49 pm Post subject:
|
|
|
Ok, thanks. I'll try everything...
Searching i found this:
http://little-scale.blogspot.com.ar/2008/05/how-to-deal-with-midi-clock-signals-in.html
I thought i could do something like, put the note events inside void sync(). And if i want to send a note every 1/4, i would put a counter inside the sync() when the counter reachs 24(1/4 right?) it sends the note, if i want to send at 1/8 note, it'd count to 12 and then send it and reset to 0. Does this make sense? The idea would be that that 24, 12, 8 and etc, are dynamic, so if step one is at 1/4 duration, it counts to 24, then if the next one is at 1/8 duration it counts to 12... |
|
Back to top
|
|
|
blue hell
Site Admin
Joined: Apr 03, 2004 Posts: 24079 Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320
|
Posted: Fri Jul 12, 2013 3:32 pm Post subject:
|
|
|
trying would not hurt
could be a good solution even, as long as you only want a sequencer
the reason i brought in some extra complexities is that in my work experience there has always been something like .. customer wish creep. ...
anyway, try it, and when you run into a wall ... there are some ways out. _________________ Jan
also .. could someone please turn down the thermostat a bit.
|
|
Back to top
|
|
|
MusicMan11712
Joined: Aug 08, 2009 Posts: 1082 Location: Out scouting . . .
|
Posted: Fri Jul 12, 2013 8:48 pm Post subject:
|
|
|
[This post in its entirety (including the quote within it) is quoted below.] Last edited by MusicMan11712 on Mon Nov 21, 2016 11:06 am; edited 1 time in total |
|
Back to top
|
|
|
capicoso
Joined: Nov 19, 2012 Posts: 128 Location: Argentina
|
Posted: Sun Jul 14, 2013 6:02 pm Post subject:
|
|
|
MusicMan11712 wrote: | capicoso wrote: | Ok, thanks. I'll try everything...
Searching i found this:
http://little-scale.blogspot.com.ar/2008/05/how-to-deal-with-midi-clock-signals-in.html
I thought i could do something like, put the note events inside void sync(). And if i want to send a note every 1/4, i would put a counter inside the sync() when the counter reachs 24(1/4 right?) it sends the note, if i want to send at 1/8 note, it'd count to 12 and then send it and reset to 0. Does this make sense? The idea would be that that 24, 12, 8 and etc, are dynamic, so if step one is at 1/4 duration, it counts to 24, then if the next one is at 1/8 duration it counts to 12... |
I haven't tried this, but couldn't you use midi library callbacks to update your sequencer clock based on the incoming midi clock data? So far as I can see, no need for you to write interrupt handlers.
Steve |
I would have to read about callbacks... Will check it in the reference |
|
Back to top
|
|
|
capicoso
Joined: Nov 19, 2012 Posts: 128 Location: Argentina
|
Posted: Tue Jul 16, 2013 9:16 pm Post subject:
|
|
|
Hey, i modified the sketch a lot, it had some redundant things and some other non-senses... Now it's much better, i just wanted to see if i could get the time accuracy better but nope. I'm using a timer on puredata via midi to compare the time, i don't know precise it's. But with a simple sketch that sends midi note, delay(250), and nothing else, it was the same... So i'm happy because i thought i was doing something very wrong.
The question, i know i won't be able to make a perfect clock, it's not my objetive, since i'll sync it to midi clock. But could a crystal oscillator make it better, than the ceramic resonator my board has? |
|
Back to top
|
|
|
MusicMan11712
Joined: Aug 08, 2009 Posts: 1082 Location: Out scouting . . .
|
Posted: Wed Jul 17, 2013 2:15 am Post subject:
|
|
|
Have you tried using the arduino as your midi clock source? If so, how does it compare with having the arduino as the slave?
Steve |
|
Back to top
|
|
|
capicoso
Joined: Nov 19, 2012 Posts: 128 Location: Argentina
|
Posted: Thu Jul 18, 2013 10:13 pm Post subject:
|
|
|
MusicMan11712 wrote: | Have you tried using the arduino as your midi clock source? If so, how does it compare with having the arduino as the slave?
Steve |
Nope. Just now i'm trying receiving midi clock from computer to arduino. Used little-scale code, i think callbacks were more complicated... and trying this
void Sync() {
if(counter == 24){
digitalWrite(13, LOW);
counter = 0;}
else{digitalWrite(13, HIGH);
counter++;}
// do something for every MIDI Clock pulse when the sequencer is running
}
Measuring d13 output with my oscilloscope i see periods from(at 120bpm) 499.6ms to 501ms. It's the best a computer can do i guess? As long as all the instruments are synced... |
|
Back to top
|
|
|
MusicMan11712
Joined: Aug 08, 2009 Posts: 1082 Location: Out scouting . . .
|
Posted: Fri Jul 19, 2013 1:52 pm Post subject:
|
|
|
[See quoted post below.] Last edited by MusicMan11712 on Mon Nov 21, 2016 11:09 am; edited 2 times in total |
|
Back to top
|
|
|
capicoso
Joined: Nov 19, 2012 Posts: 128 Location: Argentina
|
Posted: Fri Jul 19, 2013 3:15 pm Post subject:
|
|
|
MusicMan11712 wrote: | Could it be that the variation in your counter is due to some variation in the serial buffer? I seem to remember reading something about that and also a way to see how much is in the buffer. I will see if I can find the reference.
This is not the reference I was looking for, but it might be useful if you really want to fine tune the clock handling: http://electro-music.com/forum/post-373369.html#373369
I think there was something else that led me to this: http://arduino.cc/en/Serial/Available (more details about accessing the serial buffer).
Steve |
I'll check those links.
But i think the variation is because the midi clock isn't 100% precise, luckily. I searched for a external clock for midi "atomic clock" 5000usd
Now i changed the led part and it was sending a note on on every 23 tick.
So i finally tested with my ears and it's all in sync, so the one to blame is the midi clock, but as long as they're all synced... The only weird thing is that the note on at speeds over 120bpm, sometimes it's a bit shorter so i have to put a bit of relase in my ADSR to hear it. In the oscilloscope when connected to the led i saw that too, sometimes the pulse is a bit shorter, this would be annoying. But in my actual sketch, the pulse will send a noteOff, so it won't bother, and the note on will last 24 ticks if its a 1/4, 12 if its 1/8, and so on.
I thought maybe that my optocoupler isn't fast enough or something? I'm using the whitey one 4n28. It was the first result that google returned when searching for midi in arduino. But when i was putting it all together i read that it was the worst option, and the 6n138 would be better...
About the interrupts, i'm not using anymore, i thought i really needed them but no... the thing was that i needed the note on to send just a pulse, and not constantly inside the loop(). But i added a counter that sums +1 when the note on is sent, and when the counter is = 1, the note off is sent. This way it's just a pulse. The code is a lot cleaner now, if you're interested i post it here |
|
Back to top
|
|
|
smidirin
Joined: May 01, 2007 Posts: 14 Location: analogfx.studio
|
Posted: Wed Jul 24, 2013 5:09 am Post subject:
|
|
|
Quote: | The code is a lot cleaner now, if you're interested i post it here |
please do capicoso!
i am not very capable of understanding the arduino at this stage.
i'm always trying but so far not a lot of success
is it usb midi you are syncing as well?
i have a nano i want to use as slave & have had problems where to modify my code..
i have a 6n138 setup too as well as inbuilt usb and wonder if i can use a midi cable to slave & still output usb midi to PC?? |
|
Back to top
|
|
|
capicoso
Joined: Nov 19, 2012 Posts: 128 Location: Argentina
|
Posted: Wed Jul 24, 2013 8:51 am Post subject:
|
|
|
smidirin wrote: | Quote: | The code is a lot cleaner now, if you're interested i post it here |
please do capicoso!
i am not very capable of understanding the arduino at this stage.
i'm always trying but so far not a lot of success
is it usb midi you are syncing as well?
i have a nano i want to use as slave & have had problems where to modify my code..
i have a 6n138 setup too as well as inbuilt usb and wonder if i can use a midi cable to slave & still output usb midi to PC?? |
Here it is
http://sourceforge.net/projects/arduinovariseq/files/arduinovariseq.ino/download
it doesn't do anything new like the midi clock or anything, it's the same code but optimized
I'm not using usb, just standar midi din and now adding midi in with 4n28 opto. Did you try the hiduino firmware?
Right now in the code midi in is not implemented
i'm experimenting it now. My latest code(not uploaded yet) has midi clock in, and the sequence syncs to the midi clock, also i added a trasposition pot for the sequence. The schematic will be available soon |
|
Back to top
|
|
|
smidirin
Joined: May 01, 2007 Posts: 14 Location: analogfx.studio
|
Posted: Wed Jul 24, 2013 5:34 pm Post subject:
|
|
|
thanks, i'll keep an eye on your project!
i have looked into hiduino but never tried it. there is also gretel's MIDIsync. |
|
Back to top
|
|
|
xarolium
Joined: Oct 25, 2011 Posts: 19 Location: France
|
Posted: Thu Jul 25, 2013 1:04 pm Post subject:
|
|
|
Hi capicoso,
Did you solve your problem to receive Midi Clock?
try this code it work fine. I built a Midi to DIN converter with arduino and i didn't miss any 0xF8 clock message I hope it'll help you
Quote: |
void Midi_Synchro(){
if(Serial.available()>0){
byte data;
data = Serial.read();//Store incoming byte
switch (data){
//MIDI START
case 0xfa:
play=1;
ppqn_count=0;
break;
//MIDI STOP
case 0xfc:
play=0;
step_count=0;
break;
//MIDI CLOCK
case 0xf8:
ppqn_count++;
break;
}
}
if(play){
if (ppqn_count>=6){//24PPQN = 6pulse per step in 1/16 scale
ppqn_count=0;
step_count++;
if(step_count>=16){//max step 16
step_count=0;
}
}
}
}
|
|
|
Back to top
|
|
|
MusicMan11712
Joined: Aug 08, 2009 Posts: 1082 Location: Out scouting . . .
|
Posted: Fri Jul 26, 2013 11:01 am Post subject:
|
|
|
This looks quite straightforward and compact; I will have to give it a try myself. Thanks for sharing.
Steve |
|
Back to top
|
|
|
xarolium
Joined: Oct 25, 2011 Posts: 19 Location: France
|
Posted: Fri Jul 26, 2013 12:53 pm Post subject:
|
|
|
Quite simple but powerful if you don't need to read other MIDI message like noteOn or NoteOFF |
|
Back to top
|
|
|
capicoso
Joined: Nov 19, 2012 Posts: 128 Location: Argentina
|
Posted: Fri Jul 26, 2013 2:31 pm Post subject:
|
|
|
xarolium wrote: | Hi capicoso,
Did you solve your problem to receive Midi Clock?
try this code it work fine. I built a Midi to DIN converter with arduino and i didn't miss any 0xF8 clock message I hope it'll help you
Quote: |
void Midi_Synchro(){
if(Serial.available()>0){
byte data;
data = Serial.read();//Store incoming byte
switch (data){
//MIDI START
case 0xfa:
play=1;
ppqn_count=0;
break;
//MIDI STOP
case 0xfc:
play=0;
step_count=0;
break;
//MIDI CLOCK
case 0xf8:
ppqn_count++;
break;
}
}
if(play){
if (ppqn_count>=6){//24PPQN = 6pulse per step in 1/16 scale
ppqn_count=0;
step_count++;
if(step_count>=16){//max step 16
step_count=0;
}
}
}
}
|
|
Yes, i solved it. Thanks though
The code is similar... The counter goes +1 every tick, and a if statement for the note off and on events. Length potentiometers controls the variable at which number the counter resets to 0. So if step 1 is 12, and 2nd step is 24, it'd play a 1/8 and then a 1/4 note. Right now i'm not on my computer, i'll upload this part of the code. The rest is the same |
|
Back to top
|
|
|
capicoso
Joined: Nov 19, 2012 Posts: 128 Location: Argentina
|
Posted: Fri Jul 26, 2013 5:50 pm Post subject:
|
|
|
here it's
Code: |
void clock() {
if(counter > durnota ){
//MIDI.sendNoteOff(60, 0, 1);
eventoNoteoff();
counter = 0;
}
else if(counter == 0){
eventoNoteon();
counter++;
}
} |
at every clock tick, the function clock is called. Durnota is the note duration, defined by each of the potentiometers(this is in the main loop). They're fixed values like 11, 22, ...
When the counter starts at 0 it sends the noteon event, and depending on the durnota value it'll last longer or shorter. Then it resets to 0 and on to next step... |
|
Back to top
|
|
|
MusicMan11712
Joined: Aug 08, 2009 Posts: 1082 Location: Out scouting . . .
|
Posted: Sat Jul 27, 2013 3:47 pm Post subject:
|
|
|
xarolium wrote: | Quite simple but powerful if you don't need to read other MIDI message like noteOn or NoteOFF |
It seems to me that if you stored the 1st byte and tested it for being a midi timing byte, you could pass that first byte to a second midi handler that processed two-byte and three-byte midi commands.
Steve |
|
Back to top
|
|
|
capicoso
Joined: Nov 19, 2012 Posts: 128 Location: Argentina
|
|
Back to top
|
|
|
capicoso
Joined: Nov 19, 2012 Posts: 128 Location: Argentina
|
|
Back to top
|
|
|
capicoso
Joined: Nov 19, 2012 Posts: 128 Location: Argentina
|
|
Back to top
|
|
|
capicoso
Joined: Nov 19, 2012 Posts: 128 Location: Argentina
|
Posted: Thu Aug 07, 2014 10:17 pm Post subject:
|
|
|
now it has 16 steps, with 2x8 mode, and the first eight are transposing the steps 9-12 |
|
Back to top
|
|
|
n.d
Joined: Dec 15, 2011 Posts: 52 Location: Talos IV
|
Posted: Fri Jan 29, 2016 2:19 pm Post subject:
|
|
|
Awesome!
Any new features? |
|
Back to top
|
|
|
|