Liberty BASIC Community Forum
« using liberty basic to read sysex midi data »

Welcome Guest. Please Login or Register.
May 29th, 2017, 08:15am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: using liberty basic to read sysex midi data  (Read 131 times)
studioman
New Member
Image


member is offline

Avatar




PM


Posts: 12
xx using liberty basic to read sysex midi data
« Thread started on: May 12th, 2017, 9:18pm »

Ok, I love LB. I have been using it for a few years and I'm new to this forum, so please excuse me if I don't know the right questions to ask.

I am trying to read system exclusive midi data using LB. I want to be able to acquire the MTC coming from an XP comupter into my Win7 computer. I have downloaded and used a program written by Chung and also tried a program that was presented by Stephan Pendl and David speck that I found on Yahoo Groups for Liberty Basic. Those programs seem to work but I cannot figure out if they are reading the parameters that I want. I have the midi cards connected and I receive midi data in my Win7 computer using LB, but I cannot figure out which parameter I need to access to get MTC. I assume it would be done with and API, but I am still pretty new to this. Could someone please help me?
User IP Logged

CarlGundel
Administrator
ImageImageImageImageImage


member is offline

Avatar

author of Liberty BASIC


Homepage PM


Posts: 2792
xx Re: using liberty basic to read sysex midi data
« Reply #1 on: May 13th, 2017, 09:39am »

Hi, and welcome!

Perhaps links to the programs you are using would be a help. What is MTC? Are these computers connected using RS232, or over a network connection?

-Carl
User IP Logged

author of Liberty BASIC
http://www.libertybasic.com
studioman
New Member
Image


member is offline

Avatar




PM


Posts: 12
xx Re: using liberty basic to read sysex midi data
« Reply #2 on: May 13th, 2017, 11:21am »

Thanks for responding. I am trying to get one computer to "know" where the cursor position is in another computer that is playing a song. I have 2 computers connected via usb to MIDI adapters. The computer playing the song is sending MTC to the other computer. MTC stands for Midi Time Code. MTC is sent using 'System exclusive messages' (SyEx) so the 2 computers can sink themselves to the same time in a song. This is done by sending the hour, minute, second and frame position from the computer playing to song to the computer that is trying to 'sync' to the song. A SyEx message consists of a beginning byte of F0 and an ending byte of F7, with the time information in between. The XP computer is sending the data to the Win7 computer.

I can use a program called MiOx to read the raw midi-in data onto the Win7 computer being send from the XP computer. It shows me that the data is being received by the Win7 computer. I am just trying to find a way for Liberty Basic to read it.

The following program was taken from a Yahoo group thread. When I run this program on my Win7 computer, it will read incoming midi data such as start, stop, etc, but what I am looking to read is the Midi Time Code data.



'---code start
titlebar "Get MIDI Info"

' Count midi in devices
calldll #winmm, "midiInGetNumDevs",_
devCount as ulong
print
print "Number of MIDI input devices = "; devCount

' the next line is only for testing, since I have no midi in device
'If not(devCount) then devCount = 1

if devCount then
struct lpMidiInCaps,_
wMid as word,_
wPid as word,_
vDriverVersion as ushort,_
szPname$ as char[32],_
dwSupport as ulong

cbMidiInCaps = len(lpMidiInCaps.struct)

for uDeviceID = 0 to devCount - 1
' get information about every device
calldll #winmm, "midiInGetDevCapsA",_
uDeviceID as ulong,_
lpMidiInCaps as struct,_
cbMidiInCaps as ulong,_
result as ulong

if not(CheckResult(result, "midiInGetDevCapsA")) then
'manufacturer and product ID available in mmreg.h
print
print "Device ID ......... "; uDeviceID
print "Manufacturer ID ... "; lpMidiInCaps.wMid.struct
print "Product ID ........ "; lpMidiInCaps.wPid.struct
print "Driver Version .... ";
SplitShort$(lpMidiInCaps.vDriverVersion.struct)
print "Product Name ...... "; lpMidiInCaps.szPname$.struct
end if
next

struct lphMidiIn, value as ulong

CALLBACK.FUNCTION = hexdec("30000")

dwFlags = CALLBACK.FUNCTION
uDeviceID = uDeviceID - 1

callback dwCallback, MidiInProc(ulong, ulong, ulong, ulong, ulong),
void

' open last midi in device, using a callback to check the connection
calldll #winmm, "midiInOpen",_
lphMidiIn as struct,_
uDeviceID as ulong,_
dwCallback as ulong,_
dwCallbackInstance as ulong,_
dwFlags as ulong,_
result as ulong

if not(CheckResult(result, "midiInOpen")) then
hMidiIn = lphMidiIn.value.struct

' start receiving commands
calldll #winmm, "midiInStart",_
hMidiIn as ulong,_
result as ulong

if not(CheckResult(result, "midiInStart")) then
'wait for 3 seconds
timer 3000, [continue]
wait
[continue]
timer 0

' stop receiving commands
calldll #winmm, "midiInStop",_
hMidiIn as ulong,_
result as ulong

dummy = CheckResult(result, "midiInStop")
end if
' reset midi connection
' clear all buffers to ensure closing succeeds!
calldll #winmm, "midiInReset",_
hMidiIn as ulong,_
result as ulong

dummy = CheckResult(result, "midiInReset")
' close midi in connection
calldll #winmm, "midiInClose",_
hMidiIn as ulong,_
result as ulong

dummy = CheckResult(result, "midiInClose")
end if
end if

' exit function for running as tkn
print
input "Hit ENTER to EXIT ..."; dummy
end

' functions and subs
function MidiInProc(hMidiIn, wMsg, dwInstance, dwParam1, dwParam2)
' callback function to display received commands
print hMidiIn, wMsg, dwInstance, dwParam1, dwParam2
end function

function SplitShort$(number)
' extract major and minor version number
hexstring$ = right$("0000"; dechex$(number), 4)
major = hexdec(left$(hexstring$, 2))
minor = hexdec(right$(hexstring$, 2))
SplitShort$ = major; "."; minor
end function

function CheckResult(CheckResult, FunctionName$)
' check midi in functions for errors
' zero indicates no error
if CheckResult then
cchText = 256
Message$ = space$(cchText)

calldll #winmm, "midiInGetErrorTextA", _
CheckResult as ulong,_
Message$ as ptr,_
cchText as ulong,_
result as ulong

dummy = CheckResult(result, "midiInGetErrorTextA")
print
print "Error #"; CheckResult; " in "; FunctionName$; ":"
print trim$(Message$)
end if
end function
'---code end

---
Stefan Pendl


-----------
What I want to be able to so is actually read the RAW (unfiltered or interpreted) bytes coming in so I can parse of the f0 and f7 bytes so I can aquire the Midi Time Code information. Clear as mud, right? I have inserted print lines in the above program so I could see what data the program is accessing, but none of it seemed to be raw midi data that I could translate myself.

Any thoughts would be appreciated. Thank you.









« Last Edit: May 13th, 2017, 11:52am by studioman » User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5292
xx Re: using liberty basic to read sysex midi data
« Reply #3 on: May 13th, 2017, 1:34pm »

A midi stream is a quite a fast stream. The MTC is spread throughout the data stream in eight blocks so it will be quite an effort to parse that stream and read the time and frame data.

What will you do with that data if you can read it?

It might be possible to read the stream and parse out the data but to process that data and manage another midi out stream in sync in real time might be a step too far.

Tell us a little more about the overall project goal. Also consider contacting Chung directly.
User IP Logged

studioman
New Member
Image


member is offline

Avatar




PM


Posts: 12
xx Re: using liberty basic to read sysex midi data
« Reply #4 on: May 13th, 2017, 2:31pm »

For years I have been automating my recording studio by writing software to do volume changes, effects changes and transport control of analog machines, etc. Once commercial software came along to do this, I still wanted to keep track of the time location or the cursor in my song to use that data to send commands to my audio software to automatically punch in and re-record an audio track.

Until now, I was using a DOS machine with QB.45 software, and it worked great. I am currently moving my studio and I would like to 'retire' the old dos computer and do the same thing with Liberty Basic on a Windows 7 machine.

I don't know if there is a particular API needed to access the raw data coming in thru the midi port or not? None of the variables received in the code in my previous post seem to be reading the raw bytes coming in. I just don't know enough about the API call used to get midi data from the midi port. I am new to API's and I am really hoping someone can help to 'turn on the light' for me. I am currently in the dark.
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5292
xx Re: using liberty basic to read sysex midi data
« Reply #5 on: May 15th, 2017, 01:15am »

Do you have access to the QBasic code? That might give us a starting point.
User IP Logged

studioman
New Member
Image


member is offline

Avatar




PM


Posts: 12
xx Re: using liberty basic to read sysex midi data
« Reply #6 on: May 15th, 2017, 11:38am »

I MIGHT be able to acquire the Qbasic code, but a slim change.

I know what I need to do to extrapolate the Midi Time Code data once I can read the incoming midi information appearing at the midi in port. I am trying to find out what command can I use in Liberty Basic to read the incoming midi data on the midi port. I am confused about that and have a very little understanding of API's. Is there a certain API that is used to read the midi data?

I have searched for quite a while and most of what I find is either midi players or people using the millisecond computer time function to keep track of time.

Thanks in advance for any help.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls