How to get midi working?

Official forum for open source FreePIE discussion and development.
Post Reply
andersbrontosaurus
One Eyed Hopeful
Posts: 6
Joined: Thu Sep 03, 2015 4:24 pm

How to get midi working?

Post by andersbrontosaurus »

I've read that freepie now can be used for midi but I can't grasp how to pull it off. I'd like to be able to use both gamepads and an extra qwerty-keyboard as midicontrollers with my music software (Which is jeskola buzz). If someone could push me towards a pedagogic tutorial I'd be utterly grateful.

Thx
Anders

CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: How to get midi working?

Post by CyberVillain »

You can check this thread for some samples

http://www.mtbs3d.com/phpBB/viewtopic.php?f=139&t=20537

edit: aha, we only support reading. Can look into writing too

CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: How to get midi working?

Post by CyberVillain »

I did a test shot, I havent tested it so cant tell if it works

Somethign like this to send on port 0, channel 0, control mode note off, data = 127

Code: Select all

midi[0].data.channel = 0
midi[0].data.status = MidiStatus.NoteOff
midi[0].data.dataOne = 127
edit: I do not support the these bits, maybe they are needed for the program to work?

Code: Select all

11110000= F0= 240	System Exclusive	**	**
11110001= F1= 241	MIDI Time Code Qtr. Frame	-see spec-	-see spec-
11110010= F2= 242	Song Position Pointer	LSB	MSB
11110011= F3= 243	Song Select (Song #)	(0-127)	none
11110100= F4= 244	Undefined (Reserved)	---	---
11110101= F5= 245	Undefined (Reserved)	---	---
11110110= F6= 246	Tune request	none	none
11110111= F7= 247	End of SysEx (EOX)	none	none
11111000= F8= 248	Timing clock	none	none
11111001= F9= 249	Undefined (Reserved)	---	---
11111010= FA= 250	Start	none	none
11111011= FB= 251	Continue	none	none
11111100= FC= 252	Stop	none	none
11111101= FD= 253	Undefined (Reserved)	---	---
11111110= FE= 254	Active Sensing	none	none
11111111= FF= 255	System Reset	none	none
You do not have the required permissions to view the files attached to this post.

andersbrontosaurus
One Eyed Hopeful
Posts: 6
Joined: Thu Sep 03, 2015 4:24 pm

Re: How to get midi working?

Post by andersbrontosaurus »

Sorry for not understanding.

Freepie downladed and installed. Then what?
I can't get my head around how or where to start.
Could someone put me infront of an understandable tutorial?
I've glanced at the forum, the homepage, youtube and even glovepies documentation but not really grasping things... :oops:

CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: How to get midi working?

Post by CyberVillain »

I gave you some pointers on the Swedish forum

andersbrontosaurus
One Eyed Hopeful
Posts: 6
Joined: Thu Sep 03, 2015 4:24 pm

Re: How to get midi working?

Post by andersbrontosaurus »

Hi. I decided to try for a while with fergo's tool at fergonez.net since it seemed like a soft start but it died on me with runtime error 380 so I decided to learn freepie way now.

Found a glovepie-script that I thought I could use as inspiration/guidance but it won't work. Is it at all compatible?

Code: Select all

    //DUEL ACTION GAMEPAD TO MIDI
    //WRITTEN FOR MIDI CHAN 1 ON JOYSTICK #1
    midi.DefaultChannel=1
    //BUTTONS
    midi.C1=joystick1.Button1
    midi.D1=joystick1.Button2
    midi.E1=joystick1.Button3
    midi.F1=joystick1.Button4
    //TOP BUTTONS
    midi.G1=joystick1.Button5
    midi.A1=joystick1.Button6
    midi.B1=joystick1.Button7
    midi.C2=joystick1.Button8
    //SELECT/START BUTTONS
    midi.D2=joystick1.Button9
    midi.E2=joystick1.Button10
    //STICK BUTTONS
    midi.F2=joystick1.Button11
    midi.G2=joystick1.Button12
    //POV
    midi.A2=joystick1.Pov1Up
    midi.B2=joystick1.Pov1Down
    midi.C3=joystick1.Pov1Left
    midi.D3=joystick1.Pov1Right
    //midi.E3=joystick1.Pov1Center
    //ANALOG STICKS
    midi.Control1=(joystick1.x/261)+64
    midi.Control2=(joystick1.y/261)+64
    midi.Control3=(joystick1.z/261)+64
    midi.Control4=(joystick1.roll/261)+64

CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: How to get midi working?

Post by CyberVillain »

FreePIE is based on python and have a completely different syntax.

I can wipe something up as a test for you, and you can work it from there

andersbrontosaurus
One Eyed Hopeful
Posts: 6
Joined: Thu Sep 03, 2015 4:24 pm

Re: How to get midi working?

Post by andersbrontosaurus »

ah. guess it's me cheating again, hoping for the best. I remember reading that freepie was a successor to glove pie so I thought they where more compatible.

if you would give me a headstart with something I could work from and even learn something, then I'd be both happy and grateful.
if it's for gamepad or qwertykeyboard is equally good.

CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: How to get midi working?

Post by CyberVillain »

Code: Select all

midi.C1=joystick1.Button1
Looks like Glovepie has an abstaction layer so that you easy set notes directly. We dont have that. Maybe something can be done in the future. Right now you got to hard wire it. Someting like

Code: Select all

def sendNote(note, strength):
	diagnostics.debug("note {0}", note)
	midi[0].data.status = MidiStatus.NoteOn
	midi[0].data.dataOne = note
	midi[0].data.dataTwo = strength

if starting:
	midi[0].data.channel = 0	
	
if keyboard.getPressed(Key.A):	
	sendNote(64, 127)

andersbrontosaurus
One Eyed Hopeful
Posts: 6
Joined: Thu Sep 03, 2015 4:24 pm

Re: How to get midi working?

Post by andersbrontosaurus »

Apologies for my late reply and thank you for your efforts. My wife is ill so it'll take a while before I get to look into this but when I do, I'll write back.

DrDim
One Eyed Hopeful
Posts: 23
Joined: Mon Jan 05, 2015 4:33 am

Re: How to get midi working?

Post by DrDim »

If I understand this correctly: Is (basic) midi output already in the current version but untested?

Ah! Overlooked the attached file - will test in some days (have lot's of work to do right now)
Theoretically midi output shouldn't be too different to midi input and easy to implement (yeah - it's easy to say that :P )

DrDim
One Eyed Hopeful
Posts: 23
Joined: Mon Jan 05, 2015 4:33 am

Re: How to get midi working?

Post by DrDim »

I finally found some time! Writing to MIDI would be an awesome feature - already seeing some stuff I could do with that!

So far I have no luck with your test version above. I figured out that

midi[0].data.buffer[0] and
midi[0].data.buffer[1]

now is called

midi[0].data.dataOne and
midi[0].data.dataTwo

I don't really know what to make out of "MidiStatus.NoteOn" and "MidiStatus.NoteOff". On my device midi[0].data.status is always "Control" if I watch it with diagnostics.watch()

Regardless this is the code I derived from the one posted above to test it with my device:

Code: Select all

def sendNote(bufferzero, bufferone):
   diagnostics.debug("bufferzero {0}", bufferzero)
   midi[0].data.status = MidiStatus.NoteOn
   midi[0].data.dataOne = bufferzero
   midi[0].data.dataTwo = bufferone
   diagnostics.watch(midi[0].data.dataOne)
   diagnostics.watch(midi[0].data.dataTwo)
   diagnostics.watch(midi[0].data.channel)
   diagnostics.watch(midi[0].data.status)

if starting:
   midi[0].data.channel = 0
   
if keyboard.getPressed(Key.A):   
   sendNote(20, 127)
   
if keyboard.getPressed(Key.D):   
   sendNote(20, 0)
doesn't have any effect on my device so far

CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: How to get midi working?

Post by CyberVillain »

midi[0] means port zero and you use channel 0 is that correct for your device?

CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: How to get midi working?

Post by CyberVillain »

also, please try this version, did some minor changes, might help
You do not have the required permissions to view the files attached to this post.

DrDim
One Eyed Hopeful
Posts: 23
Joined: Mon Jan 05, 2015 4:33 am

Re: How to get midi working?

Post by DrDim »

CyberVillain wrote:midi[0] means port zero and you use channel 0 is that correct for your device?
Yes. I used a version of the old diagnostics.watch script to look up my stuff:

Code: Select all

def update():
   diagnostics.watch(midi[0].data.channel)
   diagnostics.watch(midi[0].data.status)
   diagnostics.watch(midi[0].data.dataOne)
   diagnostics.watch(midi[0].data.dataTwo)
   
if starting:
   midi[0].update += update
had these results using input from my device:
Image

CyberVillain wrote:also, please try this version, did some minor changes, might help
I ditched the code I tried with the last Output because I didn't understand all of it and wrote my own script (turned out to be somewhat similar but simpler. maybe too simple?).

Code: Select all

def WriteToMidi(bufferone):
   midi[0].data.channel = 0
   midi[0].data.status = MidiStatus.Control
   midi[0].data.dataOne = 20
   midi[0].data.dataTwo = bufferone
   
if keyboard.getPressed(Key.A):   
   WriteToMidi(126)
   
if keyboard.getPressed(Key.D):   
   WriteToMidi(1)
Because the channel, status and first array in my more simple MIDI device is always the same, maybe it could be reduced like this:

Code: Select all

def WriteToMidi(bufferone):
   midi[0].data.dataTwo = bufferone

if keyboard.getPressed(Key.A):   
   WriteToMidi(126)

if keyboard.getPressed(Key.D):   
   WriteToMidi(1)
Again no response from my MIDI device unfortunately (with either the long or the short script). Please review the code above - is it even viable?

Maybe the values are just updated in FreePIE internally but not actually written to the device when assigning a value like midi[0].data.dataTwo = int ?

CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: How to get midi working?

Post by CyberVillain »

I do not own a midi device myself so cant test, i get tones from the built in midi in windows when I use your code.
Here is the API we use, maybe you can get some answers there?

https://midinet.codeplex.com/

DOCa Cola
One Eyed Hopeful
Posts: 11
Joined: Sun Apr 03, 2016 8:18 am

Re: How to get midi working?

Post by DOCa Cola »

Well, here is my script that worked for me with the custom FreePie version from this thread. The code is changed from one of the samples posted earlier.

Code: Select all

def sendCC(cc, strength):
   midi[1].data.status = MidiStatus.Control
   midi[1].data.dataOne = cc
   midi[1].data.dataTwo = strength

if starting:
   footswitchDown = False

if keyboard.getKeyDown(Key.F13) != footswitchDown:
   footswitchDown = not footswitchDown
   if footswitchDown:
      sendCC(36, 127)
   else:
      sendCC(36, 0)
Is there a way to receive the names of the midi devices? I'd like to avoid using a static device index in case windows decides to change the order.

CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: How to get midi working?

Post by CyberVillain »

Cool and your device receives the data?
I can see if the midi device supports names instead of indexes

edit: Btw, keyboard.getKeyDown(Key.F13) != footswitchDown can be replaced with keyboard.getPressed(Key.F13) (I think :D)

edit: See if you can access the device with name now (Do not forget to unblock the dll)

Code: Select all

midi["my name"]
You do not have the required permissions to view the files attached to this post.

DOCa Cola
One Eyed Hopeful
Posts: 11
Joined: Sun Apr 03, 2016 8:18 am

Re: How to get midi working?

Post by DOCa Cola »

Great, thank you.
I tried with getPressed, however it only seems to fire when the key is pressed down, but not on release. Therefore i manually implemented it to fire one time on key press and on release.

Yes. I used that code for several hours in 'production' and it worked just fine. All messages i tried to send were correctly received by the midi device.
I am not sure about the midi[0].data.channel = 0 line. It seems to generate a 'zero' note or control message (do not remember which) as well. I am not sure if it is supposed to do that. It wasn't necessary to use that command anyway. With or without that line all messages seems to be received on channel 1 of the midi device.

I will try your updated version with the name feature later today.

DOCa Cola
One Eyed Hopeful
Posts: 11
Joined: Sun Apr 03, 2016 8:18 am

Re: How to get midi working?

Post by DOCa Cola »

I have tested your updated DLL. I have no luck yet using the named assignment.
When i run the script with named assignment, in the Console the midi device name appears (some debug output?). If i enter a non existing device name in the brackets, i get an error (translated: sequence has no matching element). So obviously FreePie finds the correct midi device, but assignment isn't working for some reason.

CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: How to get midi working?

Post by CyberVillain »

ok so it finds the correct device but (debug output) but it does not work? hmm will have to check the code and report back

DOCa Cola
One Eyed Hopeful
Posts: 11
Joined: Sun Apr 03, 2016 8:18 am

Re: How to get midi working?

Post by DOCa Cola »

yes. It still works with midi[1] for me. However using the device name, no midi message is received by the device.

CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: How to get midi working?

Post by CyberVillain »

and the name you give matches up with the debug?

DOCa Cola
One Eyed Hopeful
Posts: 11
Joined: Sun Apr 03, 2016 8:18 am

Re: How to get midi working?

Post by DOCa Cola »

Yes. It matches and is the same name as in the log.
If i even try to enter a non-existing device name, the script won't run with error "sequence has no matching element" (translated)

CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: How to get midi working?

Post by CyberVillain »

Couldn't find any obvious errors with the code, added some more debugging. I do not lnow if I should use productid or index integer. Please check the debug output in conosle
You do not have the required permissions to view the files attached to this post.

CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: How to get midi working?

Post by CyberVillain »

Think I found the problem, try this version
You do not have the required permissions to view the files attached to this post.

DOCa Cola
One Eyed Hopeful
Posts: 11
Joined: Sun Apr 03, 2016 8:18 am

Re: How to get midi working?

Post by DOCa Cola »

Tried your newest one and it worked right away. Nice :)

CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: How to get midi working?

Post by CyberVillain »

Cool, please try with both index and name

DOCa Cola
One Eyed Hopeful
Posts: 11
Joined: Sun Apr 03, 2016 8:18 am

Re: How to get midi working?

Post by DOCa Cola »

I tried both with index and name. Both worked with no issues. All messages were correctly received by my MIDI device.

Also a deliberately wrong device name was correctly detected in the error log.

CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: How to get midi working?

Post by CyberVillain »

Thanks, then I can push to master

andersbrontosaurus
One Eyed Hopeful
Posts: 6
Joined: Thu Sep 03, 2015 4:24 pm

Re: How to get midi working?

Post by andersbrontosaurus »

Oh. You start a thread and turn your back to it for half a year and suddenly it works?
May I ask, can I use freepie to send midimessages to software? During my absence I've realized that I'd be happy enough if I could generate keypresses with my gamepad and send them through "vmpk -virtual midi piano keyboard". Servicing midi directly would of course be awesome since it would give possibilities for velocity too!

CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: How to get midi working?

Post by CyberVillain »

We just send output on a midi channel, I think it should work?

We use this library

https://midinet.codeplex.com/

DOCa Cola
One Eyed Hopeful
Posts: 11
Joined: Sun Apr 03, 2016 8:18 am

Re: How to get midi working?

Post by DOCa Cola »

I have successfully used midi indexing by name for about 1 1/2 years now :) However it seems that this feature didn't make it in the newest FreePie release.

DOCa Cola
One Eyed Hopeful
Posts: 11
Joined: Sun Apr 03, 2016 8:18 am

Re: How to get midi working?

Post by DOCa Cola »

It's been another two years. Still running the old version. Is there an update to this feature making it into the main branch?

Post Reply

Return to “FreePIE”