Exemplo n.º 1
0
function playnotes($mn, $ip)
{
    // this is a total hack way of sending data to max
    //
    // since i couldn't write anything in php which would receive udp data, this uses the nc (netcat) command inside the
    // doalarm command which provides timeout capability - unfortunately, none of the php stream timeout methods worked on nc either
    //
    // error_reporting(E_ALL);
    // timeout is set to 10 seconds
    $fp = popen('./doalarm 10 nc -l -u 7401 2>&1', "r");
    // note that command is opened with redirection of stderr
    if (!$fp) {
        exit("error: unable to run netcat");
    }
    //  now send data to max
    $c = new OSCClient();
    // should check for error here too
    $c->set_destination($ip, 7400);
    // eventually, this data will be sent as JSON
    // This is probably not necessary here - but send a stop message to stop any currently playing sequence
    $maxdata = "/stop";
    $c->send(new OSCMessage($maxdata));
    $maxdata = "/begin";
    // header - begin
    $c->send(new OSCMessage($maxdata));
    for ($i = 0; $i < count($mn); $i++) {
        $maxdata = "/play " . " " . $mn[$i]->eventtime . " " . $mn[$i]->note . " " . $mn[$i]->velocity . " " . $mn[$i]->duration . " " . $mn[$i]->channel . " " . $mn[$i]->delay;
        $c->send(new OSCMessage($maxdata));
    }
    $maxdata = "/end";
    // header - end
    $c->send(new OSCMessage($maxdata));
    // get response from max
    sleep(1);
    $res = fread($fp, 2000);
    pclose($fp);
    // here we could actually check for elapsed time of 4 seconds to confirm timeout error
    if ($res == NULL) {
        echo "error -  no response from max/msp server";
    } else {
        echo "max returned: " . $res;
    }
    echo "<br>";
}
Exemplo n.º 2
0
<?php

include 'OSC.php';
include 'settings.php';
$c = new OSCClient();
$c->set_destination($RFserver, $RFport);
$c->send(new OSCMessage("/rf", array(0, 0, 0)));
echo "\$";
echo $_GET["v"];
Exemplo n.º 3
0
    //list
    $q = (string) $q;
    //$q = preg_split('/ /', $q);
} else {
    if (preg_match('/[a-z]/i', $q)) {
        //string
        $q = (string) $q;
    } else {
        if (preg_match('/[0-9]/i', $q)) {
            //number
            $q = (double) $q;
            $q = floatval($q);
        }
    }
}
$osc_name = $_POST["oscName"];
/* Get osc name to use as the osc message */
$osc_ip = $_POST["oscIp"];
/* If an osc_ip is posted as well, use that ip, otherwise, default to localhost */
if (is_null($osc_ip)) {
    $osc_ip = '127.0.0.1';
}
/* Relay the OSC message */
$c = new OSCClient();
$c->set_destination($osc_ip, 7475);
$queue = array($q);
array_unshift($queue, $_SERVER["REMOTE_ADDR"]);
$c->send(new OSCMessage($osc_name, $queue));
//$c->send(new OSCMessage($osc_name, $q));
echo "Got it";
/* If you want to send something back to the browser that sent the AJAX request. */
Exemplo n.º 4
0
<?php

error_reporting(E_WARNING);
require_once "OSC.php";
echo "hello example\n";
$c = new OSCClient();
$c->set_destination("127.0.0.1", 10000);
$m1 = new OSCMessage("/test", array("aStringParameter"));
$m1->add_arg(31337.31337, "f");
$c->send($m1);
Exemplo n.º 5
0
    //sleep($sleep_length);
    //$c->send(new OSCMessage("/servo/0/position", array(intval($stop_0))));
    //$c->send(new OSCMessage("/servo/1/position", array(intval($stop_1))));
    //$c->send(new OSCMessage("/appled/1/active", array(0)));
    $c->send(new OSCMessage("/appled/1/state", array(0)));
    return;
}
////////////////////////////
////MAIN
////////////////////////////
$config = hdf_read_file("control.hdf");
$last_command_epoch = time();
$last_action = "stop";
while (1) {
    `touch /tmp/SparkyController.lock; chmod a+rw /tmp/SparkyController.lock`;
    $c = new OSCClient();
    $c->set_destination("192.168.0.200", 10000);
    $action = "";
    $mystat = 0;
    $mystat = stat("/tmp/SparkyController.lock");
    $in_action = fopen("/tmp/SparkyController.lock", "r");
    if ($in_action) {
        $action = ltrim(rtrim(fgets($in_action)));
        $last_command_epoch = fgets($in_action);
        echo "READ last_command_epoch: {$last_command_epoch}\n";
        if (!strlen($last_command_epoch)) {
            $last_command_epoch = 0;
        }
        fclose($in_action);
        if ($last_action != $action) {
            //echo "setting last_command_epoch".time();
Exemplo n.º 6
0
 /** Pack data into $this->bin as 4-byte aligned, network-byte order.
  */
 function pack_data($data, $type_hint)
 {
     $bin = "";
     switch ($type_hint) {
         case "T":
         case "F":
         case "N":
         case "I":
             return;
             // These types have no allocated space
         // These types have no allocated space
         case "A":
             foreach ($data as $arg) {
                 $this->pack_data($arg[0], $arg[1]);
             }
             break;
         case "s":
             $data .= "";
             // The builtin \0 terminator is ignored... we must explicitly request one.
             $bin = pack("a*" . $this->get_strpad($data), $data);
             break;
         case "b":
             $this->pack_data(strlen($data->bin), "i");
             $bin = pack("a*" . $this->get_strpad($data->bin), $data->bin);
             break;
         case "i":
             $bin = OSCClient::host_to_network_order(pack("i", $data));
             // Machine-independent size (4-bytes)
             break;
         case "f":
             $bin = OSCClient::host_to_network_order(pack("f", $data));
             // Machine-dependent size
             if (strlen($bin) != 4) {
                 $this->error("Sorry, your machine uses an unsupported single-precision floating point size.");
             }
             break;
         case "d":
             $bin = OSCClient::host_to_network_order(pack("d", $data));
             // Machine-dependent size
             if (strlen($bin) != 8) {
                 $this->error("Sorry, your machine uses an unsupported double-precision floating point size.");
             }
             break;
         case "t":
             if (is_null($data)) {
                 $data = new Timetag();
             }
             $bin = OSCClient::host_to_network_order(pack("L", $data->sec)) . OSCClient::host_to_network_order(pack("L", $data->frac_sec));
             break;
     }
     if (strlen($bin) % 4 != 0) {
         $this->error("{$data} failed to align properly, size is " . strlen($bin) . " bytes.");
     }
     $this->bin .= $bin;
 }
Exemplo n.º 7
0
<?php

include 'OSC.php';
include 'settings.php';
$c = new OSCClient();
$c->set_destination($RFserver, $RFport);
$c->send(new OSCMessage("/rf", array((int) $_GET["v"], 0, 0)));
$c->destroy();
echo "\$";
echo $_GET["v"];
Exemplo n.º 8
0
<?php

include 'OSC.php';
include 'settings.php';
$c = new OSCClient();
$c->set_destination($IRserver, $IRport);
$c->send(new OSCMessage("/ir", array((int) $_GET["v"], 0, 0)));
$c->destroy();
echo "\$";
echo $_GET["v"];
//	$t->login('consumer_key', 'consumer secret', 'access token', 'access secret');
//
//	$t->start(array('facebook', 'fbook', 'fb'))
//
/////////////////////////////////////////////////////////////////
// here's all the max stuff which uses osc
include 'udp.php';
// udp data sending stuff
$DESTINATION = 'localhost';
$SENDPORT = '7400';
$RECVPORT = '7401';
// these variables are defined as global so they can be used inside the write callback function
global $osc;
global $kount;
// initialize OSC
$osc = new OSCClient();
// OSC object
$osc->set_destination($DESTINATION, $SENDPORT);
// This amazing program uses curl to access the Twitter streaming API and breaks the data
// into individual tweets which can be saved in a database, sent out via OSC, or whatever
//
// functions to convert lat lon to x y, etc from http://wiki.openstreetmap.org/wiki/Mercator
// not used in this version
function lon2x($lon)
{
    return deg2rad($lon) * 6378137.0;
}
function lat2y($lat)
{
    return log(tan(M_PI_4 + deg2rad($lat) / 2.0)) * 6378137.0;
}
Exemplo n.º 10
0
/** Run some tests to make sure the library behaves in a sane way.
 */
function test_osc_lib()
{
    $c = new OSCClient();
    $c->set_destination("192.168.1.5", 3980);
    $m1 = new OSCMessage("/test", array(new Timetag(3294967295.0, 5), new Infinitum(), new Blob("aoeuaoeu!")));
    $m1->add_arg(28658.93, "d");
    $m2 = new OSCMessage("/bar", array(1, 2, array(1, 2, 3)));
    $b = new OSCBundle();
    $b->add_datagram($m1);
    $b->add_datagram($m2);
    $b2 = new OSCBundle(array($m1, $b));
    echo $b2->get_human_readable();
    //echo $m1->get_human_readable();
    $c->send($m1);
}
Exemplo n.º 11
0
<?php

include 'OSC.php';
include 'settings.php';
$c = new OSCClient();
$c->set_destination($IRserver, $IRport);
$c->send(new OSCMessage("/ir", array(0)));
echo "\$";
echo $_GET["v"];
Exemplo n.º 12
0
 * @category   PoscHP
 * @package    Osc
 * @subpackage Test
 * @author     Lucas S. Bickel <*****@*****.**>
 * @copyright  2011 Lucas S. Bickel 2011 - Alle Rechte vorbehalten
 * @license    http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
 * @link       http://osc.purplehaze.ch
 */
/**
 * load andy schmeders osc client
 */
require_once 'lib/OSC.php';
/**
 * setup OSCClient
 */
$client = new OSCClient();
$client->set_destination("localhost", 10000);
/**
 * send a osc message with nested array data 
 */
$m = new OSCMessage("/container/method", array(1, 12, array(array("channel", 1, "state", false), false, true)));
$client->send($m);
/**
 * send osc bundle with multiple messages
 */
$b = new OSCBundle();
$b->add_datagram(new OSCMessage("/foo", array(100, "like a boss")));
$b->add_datagram(new OSCMessage("/bar", array(new Timetag(), true, 255)));
$client->send($b);
/**
 * send last osc bundle nested in a osc bundle
Exemplo n.º 13
0
<?php

include 'OSC.php';
include 'settings.php';
$c = new OSCClient();
$c->set_destination($RGBserver, $RGBport);
//Original OSCMessage format for old code - now all channels are seperate:
//$c->send(new OSCMessage("/rgb", array((int)$_GET["r"],(int)$_GET["g"],(int)$_GET["b"])));
$c->send(new OSCMessage("/r", array((int) $_GET["r"] / 255)));
$c->send(new OSCMessage("/g", array((int) $_GET["g"] / 255)));
$c->send(new OSCMessage("/b", array((int) $_GET["b"] / 255)));
$c->destroy();
echo "\$";
echo $_GET["r"];
echo "\$";
echo $_GET["g"];
echo "\$";
echo $_GET["b"];
Exemplo n.º 14
0
/* Receive data parameter as a post */
if (preg_match('/ /', $q)) {
    //list
    $q = (string) $q;
    //$q = preg_split('/ /', $q);
} else {
    if (preg_match('/[a-z]/i', $q)) {
        //string
        $q = (string) $q;
    } else {
        if (preg_match('/[0-9]/i', $q)) {
            //number
            $q = (double) $q;
            $q = floatval($q);
        }
    }
}
$osc_name = $_POST["oscName"];
/* Get osc name to use as the osc message */
$osc_ip = $_POST["oscIp"];
/* If an osc_ip is posted as well, use that ip, otherwise, default to localhost */
if (is_null($osc_ip)) {
    $osc_ip = '127.0.0.1';
}
/* Relay the OSC message */
$c = new OSCClient();
$c->set_destination($osc_ip, 7475);
$c->send(new OSCMessage($osc_name, array($q)));
//$c->send(new OSCMessage($osc_name, $q));
echo "Got it";
/* If you want to send something back to the browser that sent the AJAX request. */