SO... CONFUSED...

Pixilang programming language
Post Reply
ball2000
Posts: 11
Joined: Tue Nov 19, 2013 9:23 pm

SO... CONFUSED...

Post by ball2000 »

so... confused...
trying to show you the negative numbers I'm getting in midi notes...
I don't understand your dollar signs, your new() command, your fn() scope
SO... CONFUSED...

Code: Select all

include "midi_selector.pixi"
midi_dev = -1
midi_port = 0

test=1
client=1
noteNumber="0"// also tried =0, new(1,INT8), new(1,INT16)
noteVelocity="0"

if(client){
	mc = midi_open_client( "Pixi MIDI Client" )
	midi_selector( mc, MIDI_PORT_READ | MIDI_PORT_WRITE )
	clear(RED)
//	frame(1000)

dt("midi_dev",midi_dev)

	midi_open_port ( mc, midi_port, midi_dev, MIDI_PORT_READ ) 
	frame(1000)

	sleep(100)
}//if client

if(test){
//clear(BLUE)

//frame(1000)
while(1){
midinotesonly()

    while( get_event() )
    {
	if EVT[ EVT_TYPE ] == EVT_QUIT {
		midi_close_client( mc )
		sleep(10)
	 	halt }//if EVT_QUIT
	}//while( get_event())
frame()
}//while(1)


}//if test
fn midinotesonly(){
evt_size = midi_get_event( mc, midi_port, midi_event )
if(evt_size > 0){


i=0
me=midi_event[i]
if((me & 0b11100000)==0b10000000){//it's a note

noteOn=(me & 0b00010000)
runningStatus:

i+1
noteNumber=midi_event[i]
i+1
noteVelocity=midi_event[i]


if(i<(evt_size-1)){
goto runningStatus
}//if i
/*
*/

dt("note number",noteNumber)

}//note event

}//if evt_size
midi_next_event( mc, midi_port )
}//midinotesonly




fn dt($txt,$tvar){
//berg="lkjahsdflkjhasdlkfhj"
$berg=""
$berg=$txt
//copy($berg,$txt)
$msg2=""
sprintf($msg2,":    %u",$tvar)
strcat($berg,$msg2)
clear(BLUE)
    	print( $berg, 0, -100, BLACK, RIGHT | TOP )
    	print( $berg, -1, -102, BLACK, RIGHT | TOP )
    	print( $berg, -0, -101, YELLOW, RIGHT | TOP )
//WHY IS IT SCROLLING LEFTWARD!?!?!?!?
frame(200)
$berg=""
$msg2=""
remove($berg)
remove($msg2)
//why can't I clear these fricken vars
clean($berg)
clean($msg2)
}
User avatar
NightRadio
Site Admin
Posts: 3941
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: SO... CONFUSED...

Post by NightRadio »

1) About the MIDI:
  • You forgot to create the midi_event container. If you will check the log of Pixilang during launching your app, you will see this error: "Variable midi_event is not initialized. Default value = 0.".
  • midi_event is the container with numbers; so the midi_event[ i ] is a number. And when you write noteNumber=midi_event, noteNumber is just a variable with some number, it is not a container. So your code noteNumber="0" does not make sense, because "0" is a container. You should write something like: noteNumber=0


2) Dollar sign is the prefix of the local variable.
A - global variable; available in any place of your program.
$A - local variable; available only within a function.
For example you have a function:

Code: Select all

fn my_function( $parameter1, $parameter2 )
{
  $A = 3
}
$A is not accessible here
3) What is your question about fn() scope?

4) WHY IS IT SCROLLING LEFTWARD!?!?!?!?
Because you use strcat() which is add your text to the $berg every time.
When you write dt("note number",noteNumber), "note number" is the container which is created once during the Pixilang program compilation.
strcat() adds to selected container.
sprintf() clears and the adds.
You should write something like this:

Code: Select all

fn dt( $txt, $tvar ) 
{
    $msg = ""
    sprintf( $msg, "%s:    %u", $txt, $tvar )
    clear( BLUE )
    print( $msg, 0, -100, BLACK, RIGHT | TOP )
    print( $msg, -1, -102, BLACK, RIGHT | TOP )
    print( $msg, -0, -101, YELLOW, RIGHT | TOP )
    frame( 200 )
}
5)
remove() is for total removing the container.
clean() - for filling with zeroes.
ball2000
Posts: 11
Joined: Tue Nov 19, 2013 9:23 pm

Re: SO... CONFUSED...

Post by ball2000 »

Excellent, my bads, sorry I did panic. Sorry about the attitude!
with midi_event=new(1,1,INT8) properly declared/initialized I can't even get the weird values I was trying to show... working well now... uh...

I'm still unclear on why $berg wasn't an empty string with each call, however.
$berg = "" does what? is there a way to say $berg= "new empty string and I mean it?"

Also, and here's my problem probably: " If you will check the log of Pixilang "
How do I do that on OSX?
On pc I notice you have a pixilang_console.exe, is there a way to get compile-time error feedback on OSX? I tried running "terminal" alongside but nope.
Or is there a way to set pixilang to "Stop on every little discrepancy" aka "verbose?"

on my fn() scope question, I guess I was confused: declared variables are indeed passed by value, I thought I was getting "passed by reference" behavior with certain containers or something... I'll let you know when I figure out what I was talking about... Oh, I'm terrible at programming

Thanks nightradio!
User avatar
NightRadio
Site Admin
Posts: 3941
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: SO... CONFUSED...

Post by NightRadio »

I'm still unclear on why $berg wasn't an empty string with each call, however.
$berg = "" does what? is there a way to say $berg= "new empty string and I mean it?"
This is quote from Pixilang manual:
str = "Hello" //"Hello" is the string container with five 8-bit characters (UTF-8 encoding).
//This container (with string) will be created only once, during the bytecode generation.
So this string is unique for the whole program. If you will change it - it will be changed forever.

$berg = "" - is not creating the new empty string. This string is already created for you during bytecode generation stage. Here is the process of compilation and running of your program:
  • you select your *.pixi file with code;
  • compilation process:
    • generating bytecode;
    • creating the containers for your strings; for example, container 1 for the string "some string", and container 2 for the string "";
  • running;
  • and now this code $berg="" is equivalent to this $berg=2, and this code $str="some string" is equivalent to this $str=1; so your strings are just constants.
If you want a new empty string, just write this: $str = new( 1, 1, INT8 ) $str[ 0 ]
Also, and here's my problem probably: " If you will check the log of Pixilang "
How do I do that on OSX?
Ah, yes... Good question :) I'm Linux user...
You can find this log somewhere on your disk. Just search for the "pixilang_log.txt" file.
Of course it is not the best solution. I will try to improve this in the next updates.
ball2000
Posts: 11
Joined: Tue Nov 19, 2013 9:23 pm

Re: SO... CONFUSED...

Post by ball2000 »

run-time substitution, that explains everything -- no not run-time substitution... generating byte code... so it goes through and allocates containers, like registers for every container the source says it will ever need... hmm...

Read the manual? But that's cheating!! :crazy:


I didn't find pixilang_log.txt :Search:
maybe I'll switch to a PC laptop for pixilang :)
Post Reply