Transform C source into PB...
Transform C source into PB...
Hi,
All is about the ALSA library.
How do I setup this : snd_rawmidi_info_t *info; in PB ?
In C it's written as :
typedef struct _snd_rawmidi_info snd_rawmidi_info_t
If I do call :
snd_rawmidi_info_sizeof()
I get a size of 268 bytes, so it should be some kind of structure instead of one variable(*info)
But, where can I find the exact fields (setup) of those structure ?
-----------------------------------------------------------------------------------------------------------------------------------
It is needed to be used in the next call :
snd_rawmidi_info_alloca(&info);
Yet, this function doesn't appear when listed all with the PB LibraryFunctionName()
Only some malloc functions are listed like the one below. So untill now I hope it can be replaced with :
snd_rawmidi_info_malloc(*info);
But I can't get there untill I have the correct structure for snd_rawmidi_info_t
More info in which this all is to find, full C-code is here :
https://ccrma.stanford.edu/~craig/artic ... portlist.c
In this code part
void list_subdevice_info(snd_ctl_t *ctl, int card, int device)
snd_rawmidi_info_t *info;
snd_rawmidi_info_alloca(&info);
Also these are still a question (but if I have one I probably can find the others) :
typedef struct _snd_rawmidi_params snd_rawmidi_params_t;
typedef struct _snd_rawmidi_status snd_rawmidi_status_t;
typedef struct _snd_rawmidi snd_rawmidi_t;
Thanks.
All is about the ALSA library.
How do I setup this : snd_rawmidi_info_t *info; in PB ?
In C it's written as :
typedef struct _snd_rawmidi_info snd_rawmidi_info_t
If I do call :
snd_rawmidi_info_sizeof()
I get a size of 268 bytes, so it should be some kind of structure instead of one variable(*info)
But, where can I find the exact fields (setup) of those structure ?
-----------------------------------------------------------------------------------------------------------------------------------
It is needed to be used in the next call :
snd_rawmidi_info_alloca(&info);
Yet, this function doesn't appear when listed all with the PB LibraryFunctionName()
Only some malloc functions are listed like the one below. So untill now I hope it can be replaced with :
snd_rawmidi_info_malloc(*info);
But I can't get there untill I have the correct structure for snd_rawmidi_info_t
More info in which this all is to find, full C-code is here :
https://ccrma.stanford.edu/~craig/artic ... portlist.c
In this code part
void list_subdevice_info(snd_ctl_t *ctl, int card, int device)
snd_rawmidi_info_t *info;
snd_rawmidi_info_alloca(&info);
Also these are still a question (but if I have one I probably can find the others) :
typedef struct _snd_rawmidi_params snd_rawmidi_params_t;
typedef struct _snd_rawmidi_status snd_rawmidi_status_t;
typedef struct _snd_rawmidi snd_rawmidi_t;
Thanks.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Re: Transform C source into PB...
If I remember correct, I gave you already the link.
Structures are normaly defined in header files:
Download
https://www.alsa-project.org/files/pub/ ... .6.tar.bz2
Look in include/sound/uapi/asound.h
You will find:
In PB
With x86 it returns 268 bytes as size
Structures are normaly defined in header files:
Download
https://www.alsa-project.org/files/pub/ ... .6.tar.bz2
Look in include/sound/uapi/asound.h
You will find:
Code: Select all
#define SNDRV_RAWMIDI_INFO_OUTPUT 0x00000001
#define SNDRV_RAWMIDI_INFO_INPUT 0x00000002
#define SNDRV_RAWMIDI_INFO_DUPLEX 0x00000004
struct snd_rawmidi_info {
unsigned int device; /* RO/WR (control): device number */
unsigned int subdevice; /* RO/WR (control): subdevice number */
int stream; /* WR: stream */
int card; /* R: card number */
unsigned int flags; /* SNDRV_RAWMIDI_INFO_XXXX */
unsigned char id[64]; /* ID (user selectable) */
unsigned char name[80]; /* name of device */
unsigned char subname[32]; /* name of active or selected subdevice */
unsigned int subdevices_count;
unsigned int subdevices_avail;
unsigned char reserved[64]; /* reserved for future use */
};
Code: Select all
#SNDRV_RAWMIDI_INFO_OUTPUT = $00000001
#SNDRV_RAWMIDI_INFO_INPUT = $00000002
#SNDRV_RAWMIDI_INFO_DUPLEX = $00000004
Structure snd_rawmidi_info Align #PB_Structure_AlignC
device.l; /* RO/WR (control): device number */
subdevice.l; /* RO/WR (control): subdevice number */
stream.l; /* WR: stream */
card.l; /* R: card number */
flags.l; /* SNDRV_RAWMIDI_INFO_XXXX */
id.a[64]; /* ID (user selectable) */
name.a[80]; /* name of device */
subname.a[32]; /* name of active or selected subdevice */
subdevices_count.l;
subdevices_avail.l;
reserved.a[64]; /* reserved for future use */
EndStructure
Debug SizeOf(snd_rawmidi_info)
Re: Transform C source into PB...
infratec,
You gave me some links before, but searching for that structure, I always arrived at the same pages circling around this base :
https://www.alsa-project.org/alsa-doc/alsa-lib/
I didn't know that I had to look inside those .h-files (header-files) to find that structure.
Now that I kbow it's in the header files, some more things become clear.
I hope to find more things explained like the 'missing' PB function snd_rawmidi_info_alloca()
At least, the help you gave me again is really great.
Thanks a thousand times.
You gave me some links before, but searching for that structure, I always arrived at the same pages circling around this base :
https://www.alsa-project.org/alsa-doc/alsa-lib/
I didn't know that I had to look inside those .h-files (header-files) to find that structure.
Now that I kbow it's in the header files, some more things become clear.
I hope to find more things explained like the 'missing' PB function snd_rawmidi_info_alloca()
At least, the help you gave me again is really great.
Thanks a thousand times.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Re: Transform C source into PB...
What is wrong in these (selfmade linux-beginners) setup ?
I'm trying to send a note, but nothing apears in my midi-monitor.
The function snd_rawmidi_write(*midiout, noteon, 3) returns always -14, which is EFAULT, but why ?
After the noteof the program exit happens to be more then 10 seconds without any clue why (to me).
The handle (*midiout) to open the midi port works correct (return = 0).
The name$ = "hw:1,0,0" should be correct, as checked with other functions. Beside a incorrect name gives an clear error.
I must have set something wrong, I suppose, but I have no idea what or where.
Please any help or correction is welcome.
Thanks.
I'm trying to send a note, but nothing apears in my midi-monitor.
The function snd_rawmidi_write(*midiout, noteon, 3) returns always -14, which is EFAULT, but why ?
After the noteof the program exit happens to be more then 10 seconds without any clue why (to me).
The handle (*midiout) to open the midi port works correct (return = 0).
The name$ = "hw:1,0,0" should be correct, as checked with other functions. Beside a incorrect name gives an clear error.
I must have set something wrong, I suppose, but I have no idea what or where.
Please any help or correction is welcome.
Thanks.
Code: Select all
PrototypeC.l Prototype_snd_rawmidi_open(*input, *output, name.p-utf8, mode.l)
PrototypeC.l Prototype_snd_rawmidi_write(*output, *buffer, size.l)
PrototypeC.l Prototype_snd_rawmidi_read(*input, *buffer, size.l)
PrototypeC.l Prototype_snd_rawmidi_drain(*output)
PrototypeC.l Prototype_snd_rawmidi_close(*output)
PrototypeC.l Prototype_snd_rawmidi_nonblock(*output, mode.l)
;****************************************************************************
Global snd_rawmidi_open.Prototype_snd_rawmidi_open
Global snd_rawmidi_write.Prototype_snd_rawmidi_write
Global snd_rawmidi_read.Prototype_snd_rawmidi_read
Global snd_rawmidi_drain.Prototype_snd_rawmidi_drain
Global snd_rawmidi_close.Prototype_snd_rawmidi_close
Global snd_rawmidi_nonblock.Prototype_snd_rawmidi_nonblock
;****************************************************************************
snd_rawmidi_open = GetFunction(AlsaLib, "snd_rawmidi_open")
snd_rawmidi_write = GetFunction(AlsaLib, "snd_rawmidi_write")
snd_rawmidi_read = GetFunction(AlsaLib, "snd_rawmidi_read")
snd_rawmidi_drain = GetFunction(AlsaLib, "snd_rawmidi_drain")
snd_rawmidi_close = GetFunction(AlsaLib, "snd_rawmidi_close")
snd_rawmidi_nonblock = GetFunction(AlsaLib, "snd_rawmidi_nonblock")
;*********************************************************************************************
Procedure Send_to_midi_port()
Protected *midiinp, *midiout, status.l
Protected name$ = "hw:1,0,0"
Protected mode.l = #SND_RAWMIDI_SYNC
Protected noteon.l = RGB(90, 60, 100)
Protected noteof.l = RGB(90, 60, 0)
mode=0
status=snd_rawmidi_open(#Null, @*midiout, name$, mode)
If status=0
snd_rawmidi_write(*midiout, noteon, 3)
Delay(25)
snd_rawmidi_write(*midiout, noteof, 3)
snd_rawmidi_drain(*midiout)
snd_rawmidi_close(*midiout)
Else
MessageRequester("No Card.", "Problem opening MIDI output: " + name$, #PB_MessageRequester_Ok)
EndIf
;http://epic-beta.kavli.tudelft.nl/share/doc/alsa-lib-devel-1.0.22/doxygen/html/group___raw_midi.html#ga2ab783051deeb7eb37eb568b76448889
; snd_rawmidi_open(NULL, @*midiout, portname, mode)
; Opens a new connection To the RawMidi Interface.
;
; Parameters:
; inputp Returned input handle (NULL If Not wanted)
; outputp Returned output handle (NULL If Not wanted)
; name ASCII identifier of the RawMidi handle
; mode Open mode
;
; Returns:
; 0 on success otherwise a negative error code
;
; Opens a new connection To the RawMidi Interface specified With an ASCII identifier And mode.
EndProcedure
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Re: Transform C source into PB...
You need a pointer to a buffer and not the value inside of the buffer
Try this:
But I don't know if your RGB() macro results in the correct byte order.
Try this:
Code: Select all
snd_rawmidi_write(*midiout, @noteon, 3)
Re: Transform C source into PB...
infratec,
Yes, that had to be an address. Thanks.
In all attempts to get it to work I had changed I removed that @-sign, no better result.
If I replace those RGB values (which are correct) by sending 3 separate bytes, the result is still no output.
The write function itself then does return the number of bytes sent (one in that case three in the RGB setup).
However, checked this now, the midi interface referenced on Windows the USB connection (orange LED), on Ubuntu only that it has power (red LED). That could be the reason that no signal goes out (strange that all ports are recognized (by name).
I'll have to find out how to get that red color change to orange, marking a USB connection. Any idea 'how to' is welcome.
Yes, that had to be an address. Thanks.
In all attempts to get it to work I had changed I removed that @-sign, no better result.
If I replace those RGB values (which are correct) by sending 3 separate bytes, the result is still no output.
The write function itself then does return the number of bytes sent (one in that case three in the RGB setup).
However, checked this now, the midi interface referenced on Windows the USB connection (orange LED), on Ubuntu only that it has power (red LED). That could be the reason that no signal goes out (strange that all ports are recognized (by name).
I'll have to find out how to get that red color change to orange, marking a USB connection. Any idea 'how to' is welcome.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Re: Transform C source into PB...
infratec,
I got my mt4 midi interface working.
After a few hours searching I found this site, which gave the solution.
https://www.spinics.net/lists/alsa-devel/msg50236.html
Now I got it working, so far that I can already use the common midi messages.
Sysex and timed messages will be the next thing.
That RGB stuff was either something like this, I used years ago :
RGBA(#CM_NOTE_ON | \channel, \noot, \velocity, 0)
Don't recomment that anymore.
I am gradually becoming self-reliant, thanks to your help.
I got my mt4 midi interface working.
After a few hours searching I found this site, which gave the solution.
https://www.spinics.net/lists/alsa-devel/msg50236.html
Now I got it working, so far that I can already use the common midi messages.
Sysex and timed messages will be the next thing.
That RGB stuff was either something like this, I used years ago :
RGBA(#CM_NOTE_ON | \channel, \noot, \velocity, 0)
Don't recomment that anymore.
I am gradually becoming self-reliant, thanks to your help.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Re: Transform C source into PB...
Good to hear.
Have you looked at
http://www.potm.org/software/Unitor/mididata/
There is also the manual for the MT 4
Here in the forum is some code to access sysex messages.
Have you looked at
http://www.potm.org/software/Unitor/mididata/
There is also the manual for the MT 4
Here in the forum is some code to access sysex messages.
Re: Transform C source into PB...
Downloaded that manual already. Thanks.
I that sysex source is ment to be used on Linux (Raspbian here to) I hope I'll find the link.
I that sysex source is ment to be used on Linux (Raspbian here to) I hope I'll find the link.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Re: Transform C source into PB...
infratec that's all about windows API's, using things like this : midiOutShortMsg_(.....)
Also the other sources here on the forum.
Those are clear to me. Now I'll need it to do the ALSA way.
Thanks.
Also the other sources here on the forum.
Those are clear to me. Now I'll need it to do the ALSA way.
Thanks.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Re: Transform C source into PB...
You have to 'abstract ' a bit.
You don't know what this does?
It does what the name says: it sends a short midi message to the device.
Like your long value.
It does what the name says: it sends a long midi message to the device.
Which means it sends a buffer of the length size to the device.
So both of these functions can simply replaced by your versions.
Where is the problem?
Code: Select all
midiOutShortMsg_()
It does what the name says: it sends a short midi message to the device.
Like your long value.
Code: Select all
midiOutLongMsg_()
Which means it sends a buffer of the length size to the device.
So both of these functions can simply replaced by your versions.
Where is the problem?
Re: Transform C source into PB...
midiOutShortMsg_() is a windows API. Also midiOutLongMsg_().
I'm working on linux now (Ubuntu) and Raspbian PI OS.
There I need to use the ALSA library.
So espêcialy for those APIs are equivalents needed.
To me it looks like this snd_rawmidi_write(...) can handle both long and short messages. I need to test that still.
While on windows midiOutLongMsg_() is used for bigger sysex blocks. On windows there is a need to register the size of bytes recieved (and send) to setup a following sysex-block transmission. On linux I don't know yet if that is needed too. And if so how.
I'm working on linux now (Ubuntu) and Raspbian PI OS.
There I need to use the ALSA library.
So espêcialy for those APIs are equivalents needed.
To me it looks like this snd_rawmidi_write(...) can handle both long and short messages. I need to test that still.
While on windows midiOutLongMsg_() is used for bigger sysex blocks. On windows there is a need to register the size of bytes recieved (and send) to setup a following sysex-block transmission. On linux I don't know yet if that is needed too. And if so how.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Re: Transform C source into PB...
midiOutLongMsg_() has nothing to with sysex.
It simply sends a buffer of bytes.
Both functions can be replaced by snd_rawmidi_write(...) .
It simply sends a buffer of bytes.
Both functions can be replaced by snd_rawmidi_write(...) .