Skip to content

Instantly share code, notes, and snippets.

@MitchRatquest
Last active December 13, 2017 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MitchRatquest/0f226b87fb4cf0559cceb2fbcabb0c6e to your computer and use it in GitHub Desktop.
Save MitchRatquest/0f226b87fb4cf0559cceb2fbcabb0c6e to your computer and use it in GitHub Desktop.
curses python puredata osc communication for console drawing
#############################################################
___ ____ ____ ____ _ _ ____ ____ _____ ____
/ _ \/ ___| / ___| / ___| | | | _ \/ ___|| ____/ ___|
| | | \___ \| | _____| | | | | | |_) \___ \| _| \___ \
| |_| |___) | |__|_____| |___| |_| | _ < ___) | |___ ___) |
\___/|____/ \____| \____|\___/|_| \_\____/|_____|____/
#############################################################
This is an implementation of puredata controlling python controlling a terminal using curses. The OSC messages are generated firstly by an interface using an STM32F103C microcontroller over a serial port. These are sent to puredata through the [comport] object, and parsed with [mrpeach/slipdec] to decode the SLIP encoded messages, and finally through [mrpeach/unpackOSC], to return the messages as standard ASCII. We can then use these to create subsequent OSC messages as described below.
The communication between puredata and python is via [mrpeach/udpsend] and python's socket module. It is through the loopback interface on port 9999 (chosen arbitrarily). The messages are threaded in python, with simple handlers to do the work when the packets arrive.
/addpanel STRING
creates a curses panel and window with name STRING. Immediately changes window focus to this window when created.
/focuspanel STRING
brings window/panel to screen immediately
/addstring STRING Y X COLOR PANEL
writes string STRING to Y,X on screen using COLOR as text color on panel PANEL. Since puredata sees spaces in a message as a delimiter, you can draw spaces by formatting your string like_this_to_add_spaces_between_words. an example of this message would be
[/addstring hello_world 10 0 white reverb(
|
[mrpeach/packOSC]
|
[mrpeach/udpsend]
which will write the string "hello world" to the screen 11 rows below the top-left corner on the panel created with the string "reverb"
A more useful implementation would be
[/addstring wet/dry_mix_$1 10 0 reverb(
which will accept a number input, assemble the message, and send it to the screen. Imagine the number stream is generated from a microcontroller sampling a potentiometer.
Available colors are: white, black, red, green, yellow, blue, purple, cyan
/deletestring LENGTH Y X PANEL
same idea as /addstring, but instead overwrites any string in the screen with a space. using curses's delch element didn't work, so it amounts to a hack using addstr().
/pixelterminal 1/0
This is by far the goofiest thing that shouldn't work but does. Message "/pixelterminal 1" will call "setfont /usr/share/consolefonts/1pix-1x1.psfu" via a subprocess.call() python command. This font was generated using NAFE (not another font editor) to create a 1x1 pixel terminal font. the string "B" is a pixel, other strings are no pixels.
The curses terminal is now, for all intents and purposes, able to be drawn pixel by pixel. The resolution gets set to 320 columns by 240 rows. This is intended to be a boilerplate for further, more complicated work.
The message "/pixelterminal 0" runs "setfont /usr/share/consolefonts/Mik_8x16.gz" and sets the terminal back to 40 columns by 15 rows.
#N canvas 1696 58 1313 927 10;
#X obj 113 114 mrpeach/packOSC;
#X obj 106 138 mrpeach/udpsend;
#X obj 113 93 r sending;
#X obj 106 160 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1
1;
#X obj 66 768 s sending;
#X msg 66 706 /addpanel reverb;
#X obj 292 121 pack f f;
#X floatatom 701 90 5 0 0 0 - - -, f 5;
#X obj 701 126 pack f f;
#X obj 71 512 list prepend;
#X obj 71 534 list trim;
#X obj 71 578 s sending;
#X msg 152 491 /deletestring;
#X obj 71 467 pack f f f s;
#X floatatom 71 395 5 0 30 0 - - -, f 5;
#X floatatom 98 412 5 0 15 0 - - -, f 5;
#X floatatom 125 429 5 0 15 0 - - -, f 5;
#X obj 71 371 t b b b b b;
#X obj 71 350 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X msg 152 446 symbol reverb;
#X obj 71 556 print;
#X msg 366 108 0;
#X msg 66 732 /addpanel cham;
#X msg 198 708 /focuspanel reverb;
#X msg 198 734 /focuspanel cham;
#X msg 754 104 0;
#X floatatom 752 47 5 0 0 0 - - -, f 5;
#X obj 699 49 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#N canvas 2759 329 450 300 until 0;
#X obj 90 64 inlet;
#X obj 90 86 until;
#X obj 90 108 f;
#X obj 90 191 outlet;
#X obj 137 109 + 1;
#X obj 137 131 % \$1;
#X obj 178 134 sel 0;
#X obj 162 66 inlet;
#X connect 0 0 1 0;
#X connect 1 0 2 0;
#X connect 2 0 3 0;
#X connect 2 0 4 0;
#X connect 4 0 5 0;
#X connect 5 0 2 1;
#X connect 5 0 6 0;
#X connect 6 0 1 1;
#X connect 7 0 5 1;
#X restore 699 70 pd until;
#X floatatom 345 73 5 0 0 0 - - -, f 5;
#X obj 292 66 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#N canvas 2757 325 450 300 until 0;
#X obj 90 64 inlet;
#X obj 90 86 until;
#X obj 90 108 f;
#X obj 90 191 outlet;
#X obj 137 109 + 1;
#X obj 137 131 % \$1;
#X obj 178 134 sel 0;
#X obj 162 66 inlet;
#X connect 0 0 1 0;
#X connect 1 0 2 0;
#X connect 2 0 3 0;
#X connect 2 0 4 0;
#X connect 4 0 5 0;
#X connect 5 0 2 1;
#X connect 5 0 6 0;
#X connect 6 0 1 1;
#X connect 7 0 5 1;
#X restore 292 91 pd until;
#X obj 701 166 s sending;
#X obj 243 186 s sending;
#X obj 198 768 s sending;
#X text 420 97 add strings;
#X text 811 96 delete strings;
#X text 222 687 change focus;
#X text 34 688 create panels by name;
#X text 159 371 <-alternate way of assembling OSC packet;
#X text 524 487 VU meter keep y the same change height of column;
#X obj 415 490 / 10;
#X obj 418 456 hsl 128 15 0 127 0 0 empty empty empty -2 -8 0 10 -262144
-1 -1 0 1;
#X obj 413 557 - 10;
#X obj 415 517 int;
#X obj 413 579 * -1;
#X floatatom 413 601 5 0 10 0 - - -, f 5;
#N canvas 2757 325 450 300 until 0;
#X obj 90 64 inlet;
#X obj 90 86 until;
#X obj 90 108 f;
#X obj 90 191 outlet;
#X obj 137 109 + 1;
#X obj 137 131 % \$1;
#X obj 178 134 sel 0;
#X obj 162 66 inlet;
#X connect 0 0 1 0;
#X connect 1 0 2 0;
#X connect 2 0 3 0;
#X connect 2 0 4 0;
#X connect 4 0 5 0;
#X connect 5 0 2 1;
#X connect 5 0 6 0;
#X connect 6 0 1 1;
#X connect 7 0 5 1;
#X restore 562 579 pd until;
#X floatatom 615 560 5 0 0 0 - - -, f 5;
#X floatatom 562 601 5 0 0 0 - - -, f 5;
#X obj 562 533 t b;
#X obj 562 686 s sending;
#X obj 562 620 * -1;
#X obj 562 642 + 10;
#N canvas 2759 329 450 300 until 0;
#X obj 90 64 inlet;
#X obj 90 86 until;
#X obj 90 108 f;
#X obj 90 191 outlet;
#X obj 137 109 + 1;
#X obj 137 131 % \$1;
#X obj 178 134 sel 0;
#X obj 162 66 inlet;
#X connect 0 0 1 0;
#X connect 1 0 2 0;
#X connect 2 0 3 0;
#X connect 2 0 4 0;
#X connect 4 0 5 0;
#X connect 5 0 2 1;
#X connect 5 0 6 0;
#X connect 6 0 1 1;
#X connect 7 0 5 1;
#X restore 413 660 pd until;
#X obj 413 624 t b;
#X floatatom 413 682 5 0 0 0 - - -, f 5;
#X obj 413 838 s sending;
#X msg 264 252 /pixelterminal 1, f 24;
#X msg 445 252 /pixelterminal 0;
#X obj 417 315 s sending;
#X msg 701 146 /deletestring 40 \$1 \$2 reverb;
#X floatatom 656 122 5 0 0 0 - - -, f 5;
#X obj 452 11 loadbang;
#X msg 450 32 15;
#X obj 1033 78 comport/comport;
#X msg 1032 40 devicename /dev/ttyUSB0;
#X msg 1154 65 baud 115200;
#X obj 1033 100 mrpeach/slipdec;
#X obj 1033 122 mrpeach/unpackOSC;
#X obj 1033 153 route /interface;
#X obj 1033 177 route 62;
#X msg 105 67 connect localhost 9999;
#X obj 862 524 pack f f f;
#X floatatom 862 471 5 0 0 0 - - -, f 5;
#X floatatom 895 494 5 0 0 0 - - -, f 5;
#X floatatom 929 474 5 0 0 0 - - -, f 5;
#X obj 862 581 s sending;
#X msg 509 311 /addstring BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
\$1 \$2 yellow cham;
#X msg 562 664 /addstring # \$1 20 white reverb;
#X msg 413 816 /deletestring 1 \$1 20 reverb;
#X obj 1032 207 * 100;
#X msg 74 296 /addstring hello_word 10 0 white reverb;
#X obj 74 318 s sending;
#X obj 889 424 hsl 128 15 0 127 0 0 empty empty empty -2 -8 0 10 -262144
-1 -1 3500 1;
#X msg 292 203 /addstring BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
\$1 \$2 blue cham;
#X obj 869 672 == 7;
#X msg 711 777 /addstring #;
#X obj 814 728 pack f f;
#X obj 869 698 t b;
#X floatatom 813 686 5 0 0 0 - - -, f 5;
#X msg 257 156 /addstring OLIVES_IN_IT \$1 \$2 green reverb;
#X msg 862 556 /addstring wet/dry_\$1__ \$2 \$3 cyan reverb;
#N canvas 1935 76 913 769 reverbpanel 0;
#X obj 270 97 s sending;
#X msg 270 75 /addstring REVERB____ 0 16 cyan reverb;
#X obj 63 288 s sending;
#X obj 60 419 s sending;
#X obj 47 552 s sending;
#X obj 468 278 s sending;
#X obj 465 426 s sending;
#X obj 465 546 s sending;
#X msg 239 620 /addstring HELLO_IM_A_BIG_DUMB_BABY 12 8 black reverb
;
#X obj 239 642 s sending;
#X obj 465 475 r knob6;
#X msg 501 498 88;
#X obj 530 476 r initreverb;
#X obj 469 328 r knob5;
#X msg 497 379 50;
#X obj 497 355 r initreverb;
#X msg 465 524 /addstring width__\$1__ 8 22 white reverb;
#X msg 469 403 /addstring roomsize_\$1__ 6 22 green reverb;
#X obj 468 185 r knob4;
#X obj 510 208 r initreverb;
#X msg 468 256 /addstring freeze__[\$1]__ 4 22 purple reverb;
#X obj 707 39 inlet;
#X obj 615 130 s initreverb;
#X msg 510 230 1;
#X obj 270 41 r initreverb;
#X obj 63 199 r knob1;
#X obj 93 353 r initreverb;
#X msg 93 375 1;
#X obj 78 485 r initreverb;
#X msg 78 507 1;
#X obj 118 218 r initreverb;
#X msg 117 241 40;
#X msg 63 265 /addstring wet/dry_\$1%__ 4 2 yellow reverb;
#X obj 61 327 r knob2;
#X obj 47 459 r knob3;
#X msg 61 398 /addstring damping__\$1%__ 6 2 red reverb;
#X msg 47 530 /addstring combfilter__\$1%__ 8 2 blue reverb;
#X msg 732 99 /addpanel reverb;
#X obj 732 121 s sending;
#X obj 615 110 del 5;
#X text 740 71 first init panel;
#X text 616 168 then update with default values;
#X connect 1 0 0 0;
#X connect 8 0 9 0;
#X connect 10 0 16 0;
#X connect 11 0 16 0;
#X connect 12 0 11 0;
#X connect 13 0 17 0;
#X connect 14 0 17 0;
#X connect 15 0 14 0;
#X connect 16 0 7 0;
#X connect 17 0 6 0;
#X connect 18 0 20 0;
#X connect 19 0 23 0;
#X connect 20 0 5 0;
#X connect 21 0 39 0;
#X connect 21 0 37 0;
#X connect 23 0 20 0;
#X connect 24 0 1 0;
#X connect 25 0 32 0;
#X connect 26 0 27 0;
#X connect 27 0 35 0;
#X connect 28 0 29 0;
#X connect 29 0 36 0;
#X connect 30 0 31 0;
#X connect 31 0 32 0;
#X connect 32 0 2 0;
#X connect 33 0 35 0;
#X connect 34 0 36 0;
#X connect 35 0 3 0;
#X connect 36 0 4 0;
#X connect 37 0 38 0;
#X connect 39 0 22 0;
#X restore 1116 402 pd reverbpanel;
#X obj 1116 382 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
-1 -1;
#N canvas 3080 426 474 270 clearscreen 0;
#X floatatom 115 149 5 0 0 0 - - -, f 5;
#X msg 168 163 0;
#X obj 113 108 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
-1 -1;
#N canvas 2759 329 450 300 until 0;
#X obj 90 64 inlet;
#X obj 90 86 until;
#X obj 90 108 f;
#X obj 90 191 outlet;
#X obj 137 109 + 1;
#X obj 137 131 % \$1;
#X obj 178 134 sel 0;
#X obj 162 66 inlet;
#X connect 0 0 1 0;
#X connect 1 0 2 0;
#X connect 2 0 3 0;
#X connect 2 0 4 0;
#X connect 4 0 5 0;
#X connect 5 0 2 1;
#X connect 5 0 6 0;
#X connect 6 0 1 1;
#X connect 7 0 5 1;
#X restore 113 129 pd until;
#X obj 115 225 s sending;
#X msg 163 103 15;
#X obj 145 57 inlet;
#X obj 226 57 inlet;
#X obj 115 185 pack f f s;
#X text 231 38 name of panel to clear;
#X text 147 36 bang;
#X obj 226 133 list;
#X msg 114 205 /deletestring 40 \$1 \$2 \$3;
#X connect 0 0 1 0;
#X connect 0 0 8 0;
#X connect 1 0 8 1;
#X connect 2 0 3 0;
#X connect 3 0 0 0;
#X connect 5 0 3 1;
#X connect 6 0 5 0;
#X connect 6 0 2 0;
#X connect 7 0 11 0;
#X connect 8 0 12 0;
#X connect 11 0 8 2;
#X connect 12 0 4 0;
#X restore 1115 354 pd clearscreen;
#X obj 1115 335 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
-1 -1;
#N canvas 2591 298 761 461 comportInit 1;
#X obj 143 118 comport/comport;
#X msg 143 60 devicename /dev/ttyUSB0;
#X msg 270 94 baud 115200;
#X obj 143 140 mrpeach/slipdec;
#X obj 143 162 mrpeach/unpackOSC;
#X obj 66 266 route /interface;
#X obj 66 290 route 62;
#X obj 66 317 * 100;
#X obj 358 8 loadbang;
#X obj 358 32 del 500;
#X obj 209 268 route /rotary;
#X obj 445 271 route /rotarybutton;
#X obj 328 269 route /knob;
#X text 363 62 open microcontroller serial port;
#X connect 0 0 3 0;
#X connect 1 0 0 0;
#X connect 2 0 0 0;
#X connect 3 0 4 0;
#X connect 4 0 5 0;
#X connect 4 0 10 0;
#X connect 4 0 12 0;
#X connect 4 0 11 0;
#X connect 5 0 6 0;
#X connect 6 0 7 0;
#X connect 8 0 9 0;
#X connect 9 0 1 0;
#X connect 9 0 2 0;
#X restore 1114 296 pd comportInit;
#N canvas 2011 63 785 952 demo 0;
#X obj 119 209 mrpeach/udpsend;
#X msg 119 127 connect localhost 9999;
#X obj 166 181 mrpeach/packOSC;
#X obj 119 83 inlet;
#X obj 175 85 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X text 290 129 connect to port 9999 on your machine;
#X text 286 178 receives all messages and formats them;
#X text 282 211 sends to python script running curses;
#X obj 66 266 del 5;
#X msg 153 296 /addpanel reverb;
#X text 295 297 creates a panel named reverb;
#X msg 131 351 /addstring HELLO_WORLD 0 14 cyan reverb;
#X obj 66 319 del 1;
#X text 440 352 puts a string at Y 0 and X 14 on panel reverb;
#X obj 66 397 del 500;
#X msg 125 436 /addstring HELLO_WORLD 0 14 purple reverb;
#X text 437 436 same string but the color purple instead;
#X floatatom 146 583 5 0 0 0 - - -, f 5;
#X obj 146 560 int;
#X obj 147 495 osc~ 0.1;
#X obj 146 538 * 100;
#X msg 146 629 /addstring some_variable__\$1__ 5 12 white reverb;
#X text 506 631 add a number into a string;
#X obj 150 606 spigot;
#X obj 66 510 del 200;
#X obj 188 584 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
1;
#X obj 66 677 del 1000;
#X msg 110 721 /deletestring 15 0 14 reverb;
#X obj 146 517 iemlib/unsig~ 50;
#X text 345 720 delete a 15 characters at Y of 0 and X of 14;
#N canvas 2801 68 720 977 continue 0;
#X obj 41 44 inlet;
#X msg 79 131 /addpanel mixer;
#X text 217 130 creates panel and snaps focus;
#X msg 91 222 /addstring TESTING 5 5 blue mixer;
#X text 347 221 update string like normal;
#X msg 86 344 /focuspanel reverb;
#X text 247 354 change focus to reverb again;
#X msg 94 463 /focuspanel mixer;
#X msg 86 574 /focuspanel reverb;
#X obj 79 153 s sendDemo;
#X obj 91 246 s sendDemo;
#X obj 87 369 s sendDemo;
#X obj 94 485 s sendDemo;
#X obj 87 599 s sendDemo;
#X obj 87 729 s sendDemo;
#X msg 86 704 /focuspanel mixer;
#X obj 41 188 del 100;
#X obj 114 914 s sendDemo;
#X obj 114 867 pack f f;
#X msg 181 850 0;
#X obj 113 798 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
-1 -1;
#N canvas 2757 325 450 300 until 0;
#X obj 90 64 inlet;
#X obj 90 86 until;
#X obj 90 108 f;
#X obj 90 191 outlet;
#X obj 137 109 + 1;
#X obj 137 131 % \$1;
#X obj 178 134 sel 0;
#X obj 162 66 inlet;
#X connect 0 0 1 0;
#X connect 1 0 2 0;
#X connect 2 0 3 0;
#X connect 2 0 4 0;
#X connect 4 0 5 0;
#X connect 5 0 2 1;
#X connect 5 0 6 0;
#X connect 6 0 1 1;
#X connect 7 0 5 1;
#X restore 113 833 pd until;
#X msg 114 892 /addstring THANKS_FOR_LOOKING \$1 \$2 white mixer;
#X msg 164 813 15;
#X text 239 815 add a bunch of the same line;
#X obj 41 298 del 500;
#X obj 41 210 t b;
#X msg 41 428 del 500;
#X obj 32 162 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X obj 43 533 del 500;
#X obj 44 663 del 500;
#X obj 43 773 del 500;
#X obj 41 81 del 500;
#X connect 0 0 32 0;
#X connect 1 0 9 0;
#X connect 3 0 10 0;
#X connect 5 0 11 0;
#X connect 7 0 12 0;
#X connect 8 0 13 0;
#X connect 15 0 14 0;
#X connect 16 0 3 0;
#X connect 16 0 26 0;
#X connect 18 0 22 0;
#X connect 19 0 18 1;
#X connect 20 0 21 0;
#X connect 20 0 23 0;
#X connect 21 0 19 0;
#X connect 21 0 18 0;
#X connect 22 0 17 0;
#X connect 23 0 21 1;
#X connect 25 0 5 0;
#X connect 25 0 27 0;
#X connect 26 0 25 0;
#X connect 27 0 7 0;
#X connect 27 0 29 0;
#X connect 28 0 16 0;
#X connect 29 0 8 0;
#X connect 29 0 30 0;
#X connect 30 0 15 0;
#X connect 30 0 31 0;
#X connect 31 0 20 0;
#X connect 32 0 1 0;
#X connect 32 0 16 0;
#X restore 66 795 pd continue;
#X text 158 797 <<<< more information;
#X obj 168 153 r sendDemo;
#X obj 153 318 s sendDemo;
#X obj 131 373 s sendDemo;
#X obj 125 458 s sendDemo;
#X obj 146 651 s sendDemo;
#X msg 74 567 \; pd dsp 1 \;;
#X obj 110 743 s sendDemo;
#X text 328 92 FIRST run python script provided;
#X msg 183 245 disconnect;
#X connect 1 0 0 0;
#X connect 2 0 0 0;
#X connect 3 0 1 0;
#X connect 3 0 8 0;
#X connect 4 0 1 0;
#X connect 4 0 8 0;
#X connect 8 0 9 0;
#X connect 8 0 12 0;
#X connect 9 0 33 0;
#X connect 11 0 34 0;
#X connect 12 0 11 0;
#X connect 12 0 14 0;
#X connect 14 0 15 0;
#X connect 14 0 24 0;
#X connect 15 0 35 0;
#X connect 17 0 23 0;
#X connect 18 0 17 0;
#X connect 19 0 28 0;
#X connect 20 0 18 0;
#X connect 21 0 36 0;
#X connect 23 0 21 0;
#X connect 24 0 25 0;
#X connect 24 0 26 0;
#X connect 24 0 37 0;
#X connect 25 0 23 1;
#X connect 26 0 27 0;
#X connect 26 0 30 0;
#X connect 27 0 38 0;
#X connect 28 0 20 0;
#X connect 32 0 2 0;
#X connect 40 0 0 0;
#X restore 1116 465 pd demo;
#X obj 1116 446 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
-1 -1;
#X msg 1209 330 reverb;
#X msg 1271 330 cham;
#X connect 0 0 1 0;
#X connect 1 0 3 0;
#X connect 2 0 0 0;
#X connect 5 0 4 0;
#X connect 6 0 91 0;
#X connect 6 0 85 0;
#X connect 7 0 8 0;
#X connect 7 0 25 0;
#X connect 7 0 62 0;
#X connect 8 0 61 0;
#X connect 9 0 10 0;
#X connect 10 0 11 0;
#X connect 10 0 20 0;
#X connect 12 0 9 1;
#X connect 13 0 9 0;
#X connect 14 0 13 0;
#X connect 15 0 13 1;
#X connect 16 0 13 2;
#X connect 17 0 14 0;
#X connect 17 1 15 0;
#X connect 17 2 16 0;
#X connect 17 3 19 0;
#X connect 17 4 12 0;
#X connect 18 0 17 0;
#X connect 19 0 13 3;
#X connect 21 0 6 1;
#X connect 22 0 4 0;
#X connect 23 0 34 0;
#X connect 24 0 34 0;
#X connect 25 0 8 1;
#X connect 26 0 28 1;
#X connect 27 0 28 0;
#X connect 28 0 7 0;
#X connect 29 0 31 1;
#X connect 30 0 31 0;
#X connect 31 0 21 0;
#X connect 31 0 6 0;
#X connect 41 0 44 0;
#X connect 42 0 41 0;
#X connect 43 0 45 0;
#X connect 44 0 50 0;
#X connect 44 0 48 0;
#X connect 44 0 43 0;
#X connect 45 0 46 0;
#X connect 46 0 55 0;
#X connect 46 0 54 1;
#X connect 47 0 49 0;
#X connect 48 0 47 1;
#X connect 49 0 52 0;
#X connect 50 0 47 0;
#X connect 52 0 53 0;
#X connect 53 0 79 0;
#X connect 54 0 56 0;
#X connect 55 0 54 0;
#X connect 56 0 80 0;
#X connect 58 0 60 0;
#X connect 59 0 60 0;
#X connect 61 0 32 0;
#X connect 63 0 64 0;
#X connect 64 0 29 0;
#X connect 64 0 26 0;
#X connect 65 0 68 0;
#X connect 66 0 65 0;
#X connect 67 0 65 0;
#X connect 68 0 69 0;
#X connect 69 0 70 0;
#X connect 70 0 71 0;
#X connect 71 0 81 0;
#X connect 72 0 1 0;
#X connect 73 0 92 0;
#X connect 74 0 73 0;
#X connect 75 0 73 1;
#X connect 76 0 73 2;
#X connect 78 0 60 0;
#X connect 79 0 51 0;
#X connect 80 0 57 0;
#X connect 81 0 42 0;
#X connect 82 0 83 0;
#X connect 84 0 74 0;
#X connect 85 0 33 0;
#X connect 86 0 89 0;
#X connect 88 0 87 0;
#X connect 89 0 90 0;
#X connect 89 0 88 1;
#X connect 90 0 88 0;
#X connect 91 0 33 0;
#X connect 92 0 77 0;
#X connect 94 0 93 0;
#X connect 96 0 95 0;
#X connect 99 0 98 0;
#X connect 100 0 95 1;
#X connect 101 0 95 1;
#!/usr/bin/python
import socket, OSC, threading, time, re, subprocess
from time import sleep
import curses, curses.panel
flag =0
receive_address = '127.0.0.1',9999
send_address = receive_address[0]
send_port = 9998
def initOSCClient(ip, port) :
global client
client = OSC.OSCClient()
client.connect( (ip,port) )
def printing_handler(addr, tags, data, source):
print "---"
print "with addr : %s" % addr
print "typetags :%s" % tags
print "the actual data is : %s" % data
print "---"
def sendOSCMsg( address='/print', data=[] ) :
m = OSC.OSCMessage()
m.setAddress(address)
for d in data :
m.append(d)
client.send(m)
s = OSC.ThreadingOSCServer(receive_address)
initOSCClient(send_address, send_port)
s.addMsgHandler("/test", printing_handler) # adding our function, first parameter corresponds to the OSC address you want to listen to
#-------------------------------------
def echo_handler(addr, tags, data, source):
sendOSCMsg("/echo",data)
s.addMsgHandler("/echo", echo_handler)
#-------------------------------------
def display_handler(addr, tags, data, source):
print "got %s" % data
print "i received this many items: %d" % len(data)
for i in range(0,len(data)):
print data[i]
s.addMsgHandler("/displayelement", display_handler)
#--------shit gets weird below here
def addstring(addr, tags, data, source):
#string, y, x, color, panel
index = -1
for x in range(0,len(panelNames)):
if data[4] == panelNames[x][0]:
index = x
break
if index == -1: #there is no panel named data[4]
return
currentwindow = panelNames[index][1] #should be window
currentpanel = panelNames[index][2]
data[0] = str(data[0]).replace("_"," ") #turn underscores to spaces
color = 0
for x in range(0,8):
if data[3] == colors[x]:
color=x
break
try:
currentwindow.addstr(data[1],data[2],str(data[0]),curses.A_BOLD | curses.color_pair(color))
except:
pass
flag = 1
curses.panel.update_panels()
s.addMsgHandler("/addstring", addstring)
panelNames=[] #nested array of [name, window, panel],[name, window, panel]
def addpanel(addr, tags, data, source):
#panel, create panel
index = -1
for x in range(0,len(panelNames)):
if data[0] == panelNames[x][0]:
index = x
break
if index >= 0: #there is already a panel with this name
return
newwindow = curses.newwin(HEIGHT, WIDTH,0,0)
newwindow.erase()
newpanel = curses.panel.new_panel(newwindow)
panelArray=[data[0], newwindow, newpanel]
panelNames.append(panelArray)
newpanel.top()
curses.panel.update_panels()
s.addMsgHandler("/addpanel", addpanel)
def deletestring(addr, tags, data, source):
#length, x, y, panel
length = data[0]
index = 0
try:
for k in range(0,len(panelNames)):
if data[3] == panelNames[k][0]:
index = k
break
except:
return
currentwindow = panelNames[index][1] #should be window
blankstring=''
for x in range(0,length):
blankstring += ' '
try:
currentwindow.addstr(data[1],data[2],str(blankstring)) #works way better than delch
except:
pass
curses.panel.update_panels()
flag =1
s.addMsgHandler("/deletestring", deletestring)
def focuspanel(addr, tags, data, source):
#panel
for k in range(0,len(panelNames)):
if data[0] == panelNames[k][0]:
index = k
break
panelNames[index][2].top()
s.addMsgHandler("/focuspanel", focuspanel)
########GOOFY SHIT WRT NCURSES
def pixelterminal(addr, tags, data, source):
if(data[0]) == 1: #you turn that tty into a piece of crap
command = "setsid sh -c 'setfont /usr/share/consolefonts/1pix-1x1.psfu <> /dev/tty1 >&0 2>&1'"
subprocess.call(command, shell=True)
COLUMNS=320
WIDTH=320
ROWS=240
HEIGHT=240
if(data[0]) == 0: #save that tty from hell
command = "setsid sh -c 'setfont /usr/share/consolefonts/Mik_8x16.gz <> /dev/tty1 >&0 2>&1'"
subprocess.call(command, shell=True)
COLUMNS=40
WIDTH=40
ROWS=15
HEIGHT=15
s.addMsgHandler("/pixelterminal", pixelterminal)
COLUMNS=40
WIDTH=40
ROWS=15
HEIGHT=15
side = 60 # <
top = 126 # ~
bottom = 95 # _
colors=['white','black','red','green','yellow','blue','purple','cyan']
#######
print "Registered Callback-functions are :"
for addr in s.getOSCAddressSpace():
print addr
################
st = threading.Thread( target = s.serve_forever )
st.start()
#CURSES
def make_panel(h,l, y,x, str):
win = curses.newwin(h,l, y,x)
win.erase()
win.border(side, side, top, bottom, side, side, side, side)
# win.box(curses.ACS_RARROW,curses.ACS_BULLET)
win.addstr(2, 2, str)
panel = curses.panel.new_panel(win)
return win, panel
def test(stdscr):
command = "setsid sh -c 'setfont /usr/share/consolefonts/Mik_8x16.gz <> /dev/tty1 >&0 2>&1'"
subprocess.call(command, shell=True)
try:
curses.curs_set(0)
except:
pass
curses.start_color()
curses.use_default_colors()
for i in range(0, curses.COLORS):
curses.init_pair(i+1, i, 0)
string = "panels forever"
stdscr.bkgd(' ', curses.A_BOLD | curses.color_pair(0 ) )
for x in range(0, curses.COLORS):
stdscr.addstr(x, (COLUMNS/2-(len(string)/2)), string,curses.color_pair(x))
stdscr.addstr(9, (COLUMNS/2-(len(str(curses.COLORS)))), str(curses.COLORS) )
stdscr.addstr(12, 0, str(curses.color_pair(4)),curses.color_pair(1)|curses.color_pair(2))
stdscr.hline(10,0,'-',40)
curses.panel.update_panels()
stdscr.refresh()
sleep(1)
flag = 0
try:
while True:
if flag==0:
curses.panel.update_panels()
stdscr.refresh()
flag = 0
sleep(.1)
except KeyboardInterrupt :
print "\nClosing OSCServer."
s.close()
print "Waiting for Server-thread to finish"
st.join() ##!!!
print "Done"
quit()
if __name__ == '__main__':
global test
curses.wrapper(test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment