|
MIDI keyboard
About Truespace Archives
These pages are a copy of the official truespace forums prior to their removal somewhere around 2011.
They are retained here for archive purposes only.
MIDI keyboard // Scriptorium
Post by Wigand // Jan 28, 2007, 2:31pm
Wigand
Total Posts: 462
|
I do not use WMP. So is it possible that WMP is the source for all the trouble? |
Post by trueBlue // Jan 28, 2007, 3:45pm
trueBlue
Total Posts: 1761
|
I have no idea Wigand. Emma has discovered a workaround but it is not to say there is another solution. Could be how it is registered at the moment. May need some additional information with your dll. Here is a truePlay version same applies as mentioned earlier with WMP. |
Post by trueBlue // Jan 30, 2007, 8:12pm
trueBlue
Total Posts: 1761
|
Hey Wigand, I just wanted to let you know that it looks like your installation is not needed after all. I have uninstalled and deleted the registration. I then registered your dll from system32 as Emma has pointed out. But the same holds true with having to open a midi file first and then stopping but not closing Medai Player before your keyboard will work. I did create a script that automates opening a midi file when your scene loads but have not been able to find the right combination shortcut switch to make it less apparent. I tried changing the one of sixteen different channels as you pointed out but that does not seem to work. Still a great project and thank you for sharing. |
Post by Wigand // Jan 31, 2007, 4:38am
Wigand
Total Posts: 462
|
Hey Wigand, I just wanted to let you know that it looks like your installation is not needed after all. I have uninstalled and deleted the registration. I then registered your dll from system32 as Emma has pointed out. But the same holds true with having to open a midi file first and then stopping but not closing Medai Player before your keyboard will work. I did create a script that automates opening a midi file when your scene loads but have not been able to find the right combination shortcut switch to make it less apparent. I tried changing the one of sixteen different channels as you pointed out but that does not seem to work. Still a great project and thank you for sharing.
Thank you too, for the time you invest in trying and scripting. :)
Maybe it is possible for you, to write your own DLL. Then it could be
easier to manage the problems. On my PC I had problems without
installing (by only registering). And on other PCs I can not know which
VB-library already is installed. |
Post by Norm // Jan 31, 2007, 6:20am
Norm
Total Posts: 862
|
At one time I was checking midi out and came across this site:
http://www.midiox.com/ where these guys were working midi and vbscripting and jscript I believe. It could be possible if you checked it out they might have some info or script ideas that may prove helpful.
WMP is just one method of accessing sound capabilities of machine. |
Post by Wigand // Sep 30, 2007, 9:40am
Wigand
Total Posts: 462
|
I want to reload this thread. Now more people are here and more ideas.:)
First I have to say, until we cannot use callback functions it would be difficult
to implement MIDI-In. I wrote some tests in VB and PureBasic but they are all
instable. ( After 10min good working they crash)
MIDI-Out is possible, because it is much easier. You could install the
MIDI-dll and try the keyboard scene. It is still a test version.
I put the relevant functions into a function-set and so it works ok.
Still there is a question how to manage the mouseclicks.
The best way would be that the note should stay as long as the mouse
button is hold. Like a mousedown, mouseup event.
How this could be managed in LE? |
Post by notejam // Dec 26, 2007, 6:49am
notejam
Total Posts: 191
|
According to Glatt, midi input is possible without callback. Do a google search for "Glatt midi" to pick off his midi tutorials in the c language.
If you just want to play notes, you might use the windows winmm.dll Its in windows 98, and 98se, might still be in other versions of windows. It can handle short midi messages such as note on and off, also has some other features. Advantage is you do not have to play any midi file first.
Here is a Dark Basic code for a midi windchime to call the dll.
Perhaps you can translate the calls to your script language of choice.
REM WINDCHIME BY NOTEJAM
Load Dll "WINMM.DLL",1
HANDLE = Make Memory(4)
PORT=1:REM CHANGE TO PORT YOU DESIRE -1=MIDIMAPPER, 1 TO ? = YOURS
CALL DLL 1,"midiOutOpen",HANDLE,PORT,0,0,0
rem to get the handle of the Midi Out port:
HMO As DWORD
HMO = *HANDLE
HERE:
note=rnd(72)+20:REM PICK A RANDOM NOTR
event = 192
INSTRUMENT=12:REM VIBES
lo = (INSTRUMENT*256)+event
Message=lo+hi
Call Dll 1, "midiOutShortMsg", HMO, Message
note=rnd(72)+30
event = 144
lo = (note*256)+event
vel = 127
hi=vel*65536
Message=lo+hi
rem put it out
Call Dll 1, "midiOutShortMsg", HMO, Message
WAIT 120
EVENT=144
VEL=0
LO=(NOTE*256)+EVENT
HI=VEL*256
Message=lo+hi
CALL DLL 1,"midiOutShortMsg",hmo,Message
GOTO HERE
REM HAVE Q KEY PRESS CAUSE JUMP TO EXIT: TO QUIT PROGRAM
EXIT:
DELETE MEMORY HANDLE
DELETE DLL 1
END |
Post by notejam // Dec 26, 2007, 7:03am
notejam
Total Posts: 191
|
Think I will add Glatt's web site as it will be very helpfull for many wanting to do midi. His web site with tutorials on how to program midi in c language for windows is at http://www.borg.com/~jglatt/tech/miditech.htm
I am sorry but I can not explain the details on the dark basic program as another person helped me with the midi code in it, and its been a long time and I forget his explantions of the code.
If you need to, you might ask at the dark basic forum. Dark basic is a 3d programming language for windows. |
Post by Emma // Dec 26, 2007, 7:39am
Emma
Total Posts: 344
|
Thank's for that info :) ,including the link, it's quiite interesting. As far as I could see at first glance the WINMM.DLL is the key. |
Post by Wigand // Dec 29, 2007, 11:09am
Wigand
Total Posts: 462
|
Thank you notejam for the link :)
I will see what is useful :)
Some months ago, I wrote test programs in VB and PureBasic
to manage the MIDI In. I let them read the messages and all
seams well, but after half an hour, the programs crashed.
Unfortunately I am not a C developer. All the examples
I have and found are C programs. |
Post by notejam // Jan 24, 2008, 8:58pm
notejam
Total Posts: 191
|
Here is how to make the calls to winmm.dll from liberty basic and it uses calls that are like visual basic for dll calls:
The dll calls use a string, and its important you spell it exactly with caps in the right locations. Numbers are in decimal.
Rem ====== Open midi dll so it can be used.=====
struct m, a$ As ptr
calldll #winmm, "midiOutOpen",_
m as struct,_
-1 As long,_ rem -1 is midi mapper, better to use 0,1,2 etc, for midi port I think port 1 is 0, port 2 is 1, etc.
0 as long,_
0 as long,_
0 as long,_
ret as long
hMidiOut = m.a$.struct
rem ==== Set Instrument Voice Used ====
voice=12
event = 192 'Rem command to set voice on channel 1
velocity = 127
low = (voice * 256) + event
hi = velocity * 256 * 256
dwMsg = low + hi
rem we need to get each byte of code into the correct position of hi, low, and dwMsg. Thats why we multiply by 256, to shift the byte into the correct position.
calldll #winmm, "midiOutShortMsg",_
hMidiOut as ulong,_
dwMsg as ulong,_
ret as ulong
Rem ==== to play the Note =====
Rem === Midi play note on channel 1 code in Decimal for Channel 1 =====
Rem ==== 144,60,127 is note 60 middle c played on channel 1 with velocity of 127====
Rem ==== 144,60,0 play the same note with velocity 0 turns off note ====
Rem ===Function Keynote plays a note on channel 1 =====
event = 144 'rem midi channel 1
low = (note * 256) + event
hiZero = 0
dwMsg = low + hiZero
calldll #winmm, "midiOutShortMsg",_
hMidiOut as ulong,_
dwMsg as ulong,_
ret as ulong
Rem note will continue to play until you turn it off. Use same code as to play the note, but change velocity to zero, will turn off a note. There is a special command to turn off a note, but about half the midi programs around do it this way, set the velocity to zero and replay note to turn it off.
rem === when you want to quit, do a midioutclose ====
rem === this dis connects your program from the dll ====
calldll #winmm, "midiOutClose", hMidiOut As ulong, ret As ulong
If it didnt work, you most likely have your midi on some other port number than the one you opened the dll . Try incrimenting the port/midimapper code, and do a play note command, with velocity set to 127 and midi device, volume loud enough to hear. Also check windows or other mixer settings for possible midi set to mute, or wave set to mute, must have both unmuted for midi to work. |
Post by notejam // Jan 26, 2008, 6:17pm
notejam
Total Posts: 191
|
The Liberty basic example of a winmm.dll call does not set up what ports are port 0,1, 2, and so forth. Instead, it just makes use of what ever has been set as those ports by the last program that set midi ports.
So if you have problems, one more thing to try is run a midi program first, setup ports, and then run your program to make the dll call. I think windows remembers the midi port settings, or maybe its the midi program that keeps them set, as I have only had to setup 1 time, and from then on I was able to use lib basic with no need of setting up ports first, other than the normal setup of the dll call. |
Post by notejam // Jan 26, 2008, 7:32pm
notejam
Total Posts: 191
|
Here is a link to a visual basic program that can do midi control. I think that will be good enough, just find out how it sends its midi code, and change the code to note on/note off messages Its at http://support.microsoft.com/default.aspx?scid=kb;en-us;181360&Product=vbb
Download the file and run it, and it will autoextract 4 files, two of them being visual basic program. |
Post by notejam // Jan 27, 2008, 5:36am
notejam
Total Posts: 191
|
Wigand, here is another example of playing midi notes from visual basic, this time visual basic net 5.
http://www.programmefund.com/visual-basic-archive/49/46-36-497397.shtm
I hope at least one of these vb examples is one you have not tried already, and sure hope you can get it workig and then figure out how to get it to work from truespace. |
Post by Wigand // Jan 30, 2008, 5:45am
Wigand
Total Posts: 462
|
Thank you notejam for researching this kind of stuff. :)
MIDI-Send is not really the great problem, because you can send
the data when you want. Much more difficult is the MIDI -In
because you always have to look for new data. If there would be an interupt
or callback function in TS-Script, it could be much easier.
Nevertheless I will take a look at your links. |
Post by notejam // Jan 31, 2008, 10:05pm
notejam
Total Posts: 191
|
Here is an article about someone having a situation like we have of midi input required call back, and the program they wanted midi input did not allow callback. Maybe it will be helpfull, at least it shows call back can be bypassed. http://zone.ni.com/devzone/cda/tut/p/id/6223
Maybe as worse case, we could have a second midi program run, that has midi input, and it puts about 3 to 6 bytes in a file that could be accessed by scripts in truespace. Sort of a pass through of midi codes. Use one of those usb micro drives that use a memory chip for the file, so there is no wait time for a drive head to get into correct position. Also, I did a search on ram drives, and there are now programs that take a portion of windows memory, and lets users make use of it as a disk drive.
Might be a way to get streaming of data to work too, by having another program run the streaming, and pass data to it.
Ask Glatt, as I asked him a long time ago, and he said midi input can also be done with low level midi functions, without call back, and it just makes the timming a bit rougher, but most likely would be satisfactory for playing music live, or triggering of scripts, etc. , but would lack the time stamping for midi files. He believed it would be satisfactory for the program I wanted to get midi input working on, that did not allow call backs because of how the dll calls were done. |
Post by Wigand // Feb 11, 2008, 1:47am
Wigand
Total Posts: 462
|
This is a short example for a MIDI-input-function in PureBasic
using Callback.
Sorry for the strange format, it is because of the TABs in the code.
There is no comment in the code, I think it is short enough to understand
what I had done.
It uses the first possible MIDI device and opens it.
Global hMidiIn.l
Global MyInstance.l
Global miflags.l
Global offen.b
Global done.b
Global errortext.s
Global Mhandle.l
Global wert.l
Global anzahl.l
Global handle.l
Global HB.l
Global MB.l
Global LB.l
Global Dim noten.s(12)
noten(0)= "C"
noten(1)= "C#"
noten(2)= "D"
noten(3)= "D#"
noten(4)= "E"
noten(5)= "F"
noten(6)= "F#"
noten(7)= "G"
noten(8)= "G#"
noten(9)= "A"
noten(10)= "A#"
noten(11)= "H"
Global Dim action.s(1)
action(0)="NoteOff"
action(1)="NoteOn"
errortext="__________________________________________________"
mnum.l=0
Mhandle.l=0
MyInstance.l = 0
miflags.l = #CALLBACK_FUNCTION + #MIDI_IO_STATUS
Global NewList daten1.l()
Global NewList daten2.l()
Declare midizu(handle)
Declare aufteilen(wert)
Declare verwerten(hMidiIn.l , wMsg.l,wert.l, dwParam1.l, dwParam2.l)
Procedure Midi_auf(MIDnummer.l)
If MIDnummer >= 0
adresse.l=@verwerten()
If midiInOpen_(@Mhandle, MIDnummer, adresse, MyInstance, miflags) = 0
If midiInStart_(Mhandle) = 0
offen = 1
Repeat
KeyPressed$ = Inkey()
Delay(200)
While CountList(daten1())>0
SelectElement(daten1(), 0)
aufteilen(daten1())
PrintN(action(HB/88 ) + " " + noten(MB % 12) + Str(Int(MB/12)) + " " + Str(LB) )
DeleteElement(daten1(),0)
DeleteElement(daten2(),0)
anzahl=anzahl+1
Delay(30)
Wend
Until KeyPressed$=Chr(27) ;Or RawKey()
midizu(Mhandle)
Else
MessageRequester("Error","Error while calling for a handle")
EndIf
Else
MessageRequester("Error","Error while opening a device")
EndIf
Else
MessageRequester("Error","Not a possible device number")
EndIf
EndProcedure
Procedure verwerten(hMidiIn.l , wMsg.l,wert.l, dwParam1.l, dwParam2.l)
; Active sensing und time ausblenden
If dwParam1 <> 248 And dwParam1 <> 254
If AddElement(Daten1()) <>0
Daten1() = dwParam1
Else
MessageRequester("Error","Error while storing value")
EndIf
If AddElement(Daten2())<>0
Daten2() = dwParam2
Else
MessageRequester("Error","Error while storing value")
EndIf
EndIf
EndProcedure
Procedure midizu(handle)
If handle >= 0
If Not (done)
If offen=1
If midiInReset_(handle) = 0
If midiInStop_(handle) = 0
If midiInClose_(handle) = 0
offen = 0
done = 1
ClearList(daten1())
ClearList(daten2())
Delay(500)
CloseConsole()
MessageRequester("INFO","MIDI is closed")
End
handle = -1
Else
MessageRequester("Error","Error while closing MIDI")
EndIf
Else
MessageRequester("Error","Error while calling for a handle")
EndIf
Else
MessageRequester("Error","Error while reseting MIDI")
EndIf
Else
MessageRequester("Error","MIDI while closing MIDI")
EndIf
Else
EndIf
Else
EndIf
EndProcedure
Procedure aufteilen(wert )
HB= wert >> 16
MB= ( wert & 65280) >> 8
LB= wert & 255
EndProcedure
OpenConsole()
EnableGraphicalConsole(1)
ConsoleColor(0, 14)
ClearConsole()
Midi_auf(0) |
Post by notejam // Feb 12, 2008, 8:30am
notejam
Total Posts: 191
|
This might just turn out to be usefull for our purposes. Its a midi input library that stores the midi input that one can access as they decide. Also sorce code is available, so maybe the buffer could be written to a ram file, and accessed by code running on truespace.
http://www.csh.rit.edu/~jon/projects/midilib/
I also ran across an old post on getting midi input with a program called keykit, and sending its output to python, which then could do scripting.
Can python pass varibles to java script?
Keykit is available here http://nosuch.com/keykit/
And the post regarding the keykit to python hookup is located here http://groups.google.com/group/alt.slack/browse_thread/thread/fa00bf41c53c137f/1235e3742e12a56b?hl=en&lnk=st&q=midi+python+keykit#1235e3742e12a56b
Truespace 6 had python scripting, so I think its still present in 7.5. Can someone let us know if its still available in 7.5? |
Post by Wigand // Feb 12, 2008, 9:11am
Wigand
Total Posts: 462
|
I never used Python, but here you find the editor. |
Post by TomG // Feb 12, 2008, 9:14am
TomG
Total Posts: 3397
|
Python isnt available on the workspace side. The new scripting languages there are jscript and vbscript.
Python is still accessible in the Model side (perhaps easiest found using the Icon Finder, you can find the Python Script Editor, Play, Stop etc). Of course there has been no demand for that feature for a while - Python scripting is in the old architecture, so it will does have access to the new functions and data structures found in the new architecture, such as bones, etc.
Naturally the new scripting languages do have full access to the new data structures and functions and blocks, making them much more powerful than Python was in the old architecture :)
HTH!
Tom |
|