How to implement this (terminal) command ?

Linux specific forum
Joris
Addict
Addict
Posts: 890
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

How to implement this (terminal) command ?

Post by Joris »

Hi,

How to create the PB-code which does the same as this alsa-command amidi -p hw:1,0,0 -r /dev/null -t 1
I need to send it to initialize my interface, the command does it's work from the terminal.
But I would like to send it with PB code. I have anything else ready in PB code, to select the port hw:1,0,0.
This, without having the need of the terminal.

Thanks.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Bitblazer
Enthusiast
Enthusiast
Posts: 766
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: How to implement this (terminal) command ?

Post by Bitblazer »

infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: How to implement this (terminal) command ?

Post by infratec »

You have to look in the source code of amidi.
I don't know what amidi does internally.

https://github.com/bear24rw/alsa-utils/ ... di/amidi.c

Code: Select all

snd_rawmidi_open(inputp, outputp, port_name, SND_RAWMIDI_NONBLOCK)
Now you have to look for snd_rawmidi_open

It's located in rawmidi.c
https://github.com/michaelwu/alsa-lib/b ... /rawmidi.c

But I think in the end something in /dev/snd/ ... is opened in nonblocking mode.
The default midi device can be /dev/midi, which should be a symbloic link to the device itself.

https://ccrma.stanford.edu/~craig/articles/linuxmidi/
Joris
Addict
Addict
Posts: 890
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: How to implement this (terminal) command ?

Post by Joris »

infratec, Bitblazer

I can do a snd_rawmidi_write(hnd, @buffer, len) or snd_rawmidi_read(hnd, @buffer, len) with sysex strings upto several kBytes. But that specific string is absolutely no midi data -p hw:1,0,0 -r /dev/null -t 1

Besides, this part hw:1,0,0 is formed by the specific midi port, which I also can determine and select.
But how to handle the rest, -p and -r /dev/null -t 1, how to send that complete thing via midi ?

Maybe Bitblazer's way can be of help, if I can get it figured out like should (didn't succeed with many try outs).
But as I can handle all types of midi data, I prefer doing it that way.

Code: Select all

Compiler = RunProgram("/usr/bin/xterm", "", "", #PB_Program_Open | #PB_Program_Read) ; |#PB_Program_Write|#PB_Program_Connect)
  Output$ = "amidi -p hw:1,0,0 -r /dev/null -t 1"
  If Compiler
    While ProgramRunning(Compiler)
      If AvailableProgramOutput(Compiler)
        WriteProgramString(Compiler, Output$, #PB_UTF8)
        ;Output$ + ReadProgramString(Compiler) + Chr(13)
      EndIf
    Wend
    Output$ + Chr(13) + Chr(13)
    Output$ + "Exitcode: " + Str(ProgramExitCode(Compiler))
    
    CloseProgram(Compiler) ; Close the connection to the program
  EndIf
  
  MessageRequester("Output", Output$)  
Usage: amidi options
-h, --help this help
-V, --version print current version
-l, --list-devices list all hardware ports
-L, --list-rawmidis list all RawMIDI definitions
-p, --port=name select port by name **************
-s, --send=file send the contents of a (.syx) file
-r, --receive=file write received data into a file **************
-S, --send-hex="..." send hexadecimal bytes
-d, --dump print received data as hexadecimal bytes
-t, --timeout=seconds exits when no data has been received
for the specified duration **************
-a, --active-sensing include active sensing bytes
-c, --clock include clock bytes
-i, --sysex-interval=mseconds delay in between each SysEx message
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
User avatar
idle
Always Here
Always Here
Posts: 6023
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: How to implement this (terminal) command ?

Post by idle »

maybe this works for you

Code: Select all

OpenConsole()
command.s = "-p hw:1,0,0 -r /dev/null -t 1"
dir.s = GetCurrentDirectory()
Compiler = RunProgram("amidi",command, dir, #PB_Program_Open | #PB_Program_Read) 
Output$ = "amidi -p hw:1,0,0 -r /dev/null -t 1"
If Compiler
  While ProgramRunning(Compiler)
    If AvailableProgramOutput(Compiler)
      PrintN(ReadProgramString(Compiler))
    EndIf
  Wend
  PrintN("Exitcode: " + Str(ProgramExitCode(Compiler)))
  CloseProgram(Compiler)
EndIf
PrintN("Hit any key to exit") 
Input() 
CloseConsole()
Joris
Addict
Addict
Posts: 890
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: How to implement this (terminal) command ?

Post by Joris »

idle,

Thank you very much.
That does the job excellently.

A strange thing about that command is, that when proceeded in the termina,l it returns '12 bytes received'.
Why I don't know, but your solution is good.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Post Reply