Skip to content
This repository
tree: b27f5017ca
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 272 lines (238 sloc) 7.951 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
/*

LiCK Library for ChucK.
Copyright (c) 2007-2012 held jointly by the individual authors.

This file is part of LiCK.

LiCK is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

LiCK is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with LiCK. If not, see <http://www.gnu.org/licenses/>.

*/

class Control
{
    float id;
    string address;
    string values;
    OscRecv @ server;

    fun void connect()
    {
        server.event(address + ", " + values) @=> OscEvent event;
        spork ~ _waitForEvent(event);
    }

    fun void _waitForEvent(OscEvent event)
    {
        while (true)
        {
            event => now;
            while (event.nextMsg())
            {
                event.getFloat() => float eventId;
                if (Std.fabs(id - eventId) < 1.0)
                {
                    handle(event); // todo: should this also be sporked?
                }
            }
        }
    }

    fun void handle(OscEvent event)
    {
        // empty
    }
}

class Cursor extends Control
{
    "/cursor" => address;
    FloatProcedure floatProcedure;
    FloatFloatProcedure floatFloatProcedure;
    FloatFloatFloatProcedure floatFloatFloatProcedure;
    FloatFloatFloatFloatProcedure floatFloatFloatFloatProcedure;

    fun void handle(OscEvent event)
    {
        event.getFloat() => float value0;
        event.getFloat() => float value1;
        event.getFloat() => float value2;
        event.getFloat() => float value3;

        floatProcedure.run(value0);
        floatFloatProcedure.run(value0, value1);
        floatFloatFloatProcedure.run(value0, value1, value2);
        floatFloatFloatFloatProcedure.run(value0, value1, value2, value3);
    }
}

class Trigger extends Control
{
    "/trigger" => address;
    Procedure triggerOn;
    Procedure triggerOff;
    FloatProcedure floatTriggerOn;
    FloatProcedure floatTriggerOff;
    FloatFloatProcedure floatFloatTriggerOn;
    FloatFloatProcedure floatFloatTriggerOff;

    fun void handle(OscEvent event)
    {
        event.getFloat() => float triggerValue;
        event.getFloat() => float value0;
        event.getFloat() => float value1;
        if (triggerValue)
        {
            triggerOn.run();
            floatTriggerOn.run(value0);
            floatFloatTriggerOn.run(value0, value1);
        }
        else
        {
            triggerOff.run();
            floatTriggerOff.run(value0);
            floatFloatTriggerOff.run(value0, value1);
        }
    }
}

public class IanniXOsc
{
    OscSend client;
    OscRecv server;
    57120 => int port;
    1234 => int clientPort;
    "localhost" => string clientHost;
    "/iannix" => string address;

    fun void connect()
    {
        port => server.port;
        server.listen();
    }

    fun void _send(string _clientHost, int _clientPort, string _address, string _f)
    {
        client.setHost(_clientHost, _clientPort);
        client.startMsg(_address + _f, "");
    }

    fun void _send(string _clientHost, int _clientPort, string _address, string _f, string argument)
    {
        client.setHost(_clientHost, _clientPort);
        client.startMsg(_address + _f, "s");
        argument => client.addString;
    }

    fun void _send(string _clientHost, int _clientPort, string _address, string _f, float argument)
    {
        client.setHost(_clientHost, _clientPort);
        client.startMsg(_address + _f, "f");
        argument => client.addFloat;
    }

    fun void _send(string _clientHost, int _clientPort, string _address, string _f, string argument0, string argument1)
    {
        client.setHost(_clientHost, _clientPort);
        client.startMsg(_address + _f, "ss");
        argument0 => client.addString;
        argument1 => client.addString;
    }

    fun void _send(string _clientHost, int _clientPort, string _address, string _f, string argument0, float argument1)
    {
        client.setHost(_clientHost, _clientPort);
        client.startMsg(_address + _f, "sf");
        argument0 => client.addString;
        argument1 => client.addFloat;
    }

    fun void _send(string _clientHost, int _clientPort, string _address, string _f, float argument0, float argument1)
    {
        client.setHost(_clientHost, _clientPort);
        client.startMsg(_address + _f, "ff");
        argument0 => client.addFloat;
        argument1 => client.addFloat;
    }

    // /iannix/add trigger auto
    fun void add(string object)
    {
        _send(clientHost, clientPort, address, "/add", object, "auto");
    }

    // /iannix/add trigger 1
    fun void add(string object, float id)
    {
        _send(clientHost, clientPort, address, "/add", object, id);
    }

    // /iannix/fastrewind
    fun void fastrewind()
    {
        _send(clientHost, clientPort, address, "/fastrewind");
    }

    // /iannix/play
    fun void play()
    {
        _send(clientHost, clientPort, address, "/play");
    }

    // /cursor cursor_id cursor_xPos
    fun void addCursor(float cursorId, FloatProcedure procedure)
    {
        Cursor cursor;
        cursorId => cursor.id;
        "ff" => cursor.values;
        server @=> cursor.server;
        procedure @=> cursor.floatProcedure;
        cursor.connect();
    }

    // /cursor cursor_id cursor_xPos cursor_yPos
    fun void addCursor(float cursorId, FloatFloatProcedure procedure)
    {
        Cursor cursor;
        cursorId => cursor.id;
        "fff" => cursor.values;
        server @=> cursor.server;
        procedure @=> cursor.floatFloatProcedure;
        cursor.connect();
    }

    // /cursor cursor_id cursor_xPos cursor_yPos cursor_angle
    fun void addCursor(float cursorId, FloatFloatFloatProcedure procedure)
    {
        Cursor cursor;
        cursorId => cursor.id;
        "ffff" => cursor.values;
        server @=> cursor.server;
        procedure @=> cursor.floatFloatFloatProcedure;
        cursor.connect();
    }

    // /cursor cursor_id cursor_xPos cursor_yPos cursor_value_x cursor_value_y
    fun void addCursor(float cursorId, FloatFloatFloatFloatProcedure procedure)
    {
        Cursor cursor;
        cursorId => cursor.id;
        "fffff" => cursor.values;
        server @=> cursor.server;
        procedure @=> cursor.floatFloatFloatFloatProcedure;
        cursor.connect();
    }

    // /trigger trigger_id trigger_value
    fun void addTrigger(float triggerId, Procedure triggerOn, Procedure triggerOff)
    {
        Trigger trigger;
        triggerId => trigger.id;
        "ff" => trigger.values;
        server @=> trigger.server;
        triggerOn @=> trigger.triggerOn;
        triggerOff @=> trigger.triggerOff;
        trigger.connect();
    }

    // /trigger trigger_id trigger_value trigger_xPos
    fun void addTrigger(float triggerId, FloatProcedure triggerOn, FloatProcedure triggerOff)
    {
        Trigger trigger;
        triggerId => trigger.id;
        "fff" => trigger.values;
        server @=> trigger.server;
        triggerOn @=> trigger.floatTriggerOn;
        triggerOff @=> trigger.floatTriggerOff;
        trigger.connect();
    }

    // /trigger trigger_id trigger_value trigger_xPos trigger_yPos
    fun void addTrigger(float triggerId, FloatFloatProcedure triggerOn, FloatFloatProcedure triggerOff)
    {
        Trigger trigger;
        triggerId => trigger.id;
        "ffff" => trigger.values;
        server @=> trigger.server;
        triggerOn @=> trigger.floatFloatTriggerOn;
        triggerOff @=> trigger.floatFloatTriggerOff;
        trigger.connect();
    }
}
Something went wrong with that request. Please try again.