midi_in_test.pixi example problem [solved]

Pixilang programming language
Post Reply
rototom
Posts: 24
Joined: Mon Mar 14, 2022 4:12 pm

midi_in_test.pixi example problem [solved]

Post by rototom »

hi, i try to get midi ctl msg into pixilang/android from my faderfox lv3 midi controller.
i succeeded to the point that i get the last data byte printed on the screen, but i also want the status byte and the first data byte. like: Bn 00 00 for further processing.
what do i have to change in the midi_in_test.pixi example to achieve this?

greetings
Last edited by rototom on Mon Apr 18, 2022 5:04 pm, edited 1 time in total.
User avatar
NightRadio
Site Admin
Posts: 3941
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: midi_in_test.pixi example

Post by NightRadio »

status byte and the first data byte. like: Bn 00 00 for further processing.
Hm... This is exactly what i see in my log.
Can you show your console output?
rototom
Posts: 24
Joined: Mon Mar 14, 2022 4:12 pm

Re: midi_in_test.pixi example

Post by rototom »

the midi_in_test example refuses to run here on android.
so i stripped everything down to find out why.
think it's because of fputs?
anyway i replaced fputs with print(), to see what's going on.
this is the code



set_pixel_size( WINDOW_XSIZE / 480 )
resize( get_screen(), WINDOW_XSIZE, WINDOW_YSIZE )
start_timer(0)
MIDI_IN_DEVICE = "Faderfox Faderfox LV3 src0"
ts = ""
mc = midi_open_client( "Pixi MIDI Client" )
p = midi_open_port( mc, "My IN port", MIDI_IN_DEVICE, MIDI_PORT_READ )
midi_event = new(1,1,INT8 )
$break = 0
while( $break == 0 )
{
evt_size = midi_get_event( mc, p, midi_event )
i = 0
while( i < evt_size )
{
clear()
sprintf( ts, "%04x ", midi_event[ i ] & 255 )
print( ts,0,80 )
i + 1
}
midi_next_event( mc, p )
frame()
while( get_event() ) { if EVT[ EVT_TYPE ] == EVT_QUIT { $break = 1 } }
}
midi_close_port( mc, p )
midi_close_client( mc )
rototom
Posts: 24
Joined: Mon Mar 14, 2022 4:12 pm

Re: midi_in_test.pixi example

Post by rototom »

Ok, got it working now:)
For anyone interested, here's the code.

set_pixel_size( WINDOW_XSIZE / 480 )
resize( get_screen(), WINDOW_XSIZE, WINDOW_YSIZE )
start_timer(0)
MIDI_IN_DEVICE = "Faderfox Faderfox LV3 src0" //
ts = ""
mc = midi_open_client( "Pixi MIDI Client" )
p = midi_open_port( mc, "My IN port", MIDI_IN_DEVICE, MIDI_PORT_READ )
midi_event = new(1,1,INT8 )
$break = 0
while( $break == 0 )
{
evt_size = midi_get_event( mc, p, midi_event )
if evt_size > 0
{
print(ts,0,0)
i = 0 while( i < evt_size)
{
clear()
sprintf( ts, "%02x %02x %02x", midi_event[ 0 ] &255,midi_event[1] &255,midi_event[2]&255)
print( ts,0,80)
i + 1
}
midi_next_event( mc, p )
}
else
{
sleep(50)
}
frame()
while( get_event() ) { if EVT[ EVT_TYPE ] == EVT_QUIT { $break = 1 } }
}
midi_close_port( mc, p )
midi_close_client( mc )
rototom
Posts: 24
Joined: Mon Mar 14, 2022 4:12 pm

Re: midi_in_test.pixi example

Post by rototom »

this seems to be the absolute neccessary, to get midi ctl messages from a hardware controller to pixilang android.
Because pixilang android seems not to have a console, the incoming midi bytes are printed to the screen. print()
i couldn't test for note input, because the faderfox lv3 doesn't output any notes

Code: Select all

set_pixel_size( WINDOW_XSIZE / 480 )
resize( get_screen(), WINDOW_XSIZE, WINDOW_YSIZE )

MIDI_IN_DEVICE = "Faderfox Faderfox LV3 src0"
ts = ""
mc = midi_open_client( "Pixi MIDI Client" )
p = midi_open_port( mc, "My IN port", MIDI_IN_DEVICE, MIDI_PORT_READ )
midi_event = new(1,1,INT8 )
brk = 0
while( brk == 0 )
	   {	    
	     midi_get_event( mc, p, midi_event )                 
	     clear()
		    sprintf( ts, "%02x %02x %02x", midi_event[0]&255, midi_event[1]&255, midi_event[2]&255)
		    print( ts,0,80)
		    midi_next_event( mc, p )		    
	     frame()
	     while( get_event() ) { if EVT[ EVT_TYPE ] == EVT_QUIT { brk = 1 } }
    }
midi_close_port( mc, p )   
midi_close_client( mc )
maks
Posts: 43
Joined: Sat Mar 26, 2022 4:28 am

Re: midi_in_test.pixi example problem [solved]

Post by maks »

Great job for figuring out midi input on android.

On the subject of "printing to the console" on android, by default standard out does *not* go to androids ADB logcat.

Instead you would need to use the same mechanism as C/C++ NDK code would as essentially pixilang is compiled as a NDK application on andriod.

Its been a long time since I've done any NDK work, but a quick search finds this from stackoverflow: https://stackoverflow.com/a/21904153/85472
But I'm not sure if it will be possible to call something like:

Code: Select all

__android_log_print(ANDROID_LOG_INFO, "foo", "Error: %s", foobar);
using Pixllangs FFI for C libs, in which case maybe @NightRadio in a future pixilang release could add the bit of C code linked in the SO answer and also explained here: https://codelab.wordpress.com/2014/11/0 ... roid-apps/

to get "builtin" print working on Android?
rototom
Posts: 24
Joined: Mon Mar 14, 2022 4:12 pm

Re: midi_in_test.pixi example problem [solved]

Post by rototom »

Great job for figuring out midi input on android.
thanks @maks
User avatar
NightRadio
Site Admin
Posts: 3941
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: midi_in_test.pixi example problem [solved]

Post by NightRadio »

On the subject of "printing to the console" on android, by default standard out does *not* go to androids ADB logcat.
In Pixilang you can use logf() for output to the Android console
https://warmplace.ru/soft/pixilang/manual.php#logf
Post Reply