Skip to content
This repository
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 144 lines (125 sloc) 4.182 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
/*

LiCK Library for ChucK.
Copyright (c) 2007-2014 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
{
    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())
            {
                // todo: should this also be sporked?
                handle(event);
            }
        }
    }

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


class Pattern extends Control
{
    "iiii" => values;
    IntProcedure noteProcedure;
    IntProcedure channelProcedure;
    IntProcedure pitchProcedure;
    IntProcedure velocityProcedure;
    IntIntProcedure noteOnPitchVelocityProcedure;
    IntIntProcedure noteOffPitchVelocityProcedure;
    IntIntIntProcedure noteOnProcedure;
    IntIntIntProcedure noteOffProcedure;
    IntIntIntIntProcedure procedure;

    fun void handle(OscEvent event)
    {
        event.getInt() => int note;
        event.getInt() => int channel;
        event.getInt() => int pitch;
        event.getInt() => int velocity;
        noteProcedure.run(note);
        channelProcedure.run(channel);
        pitchProcedure.run(pitch);
        velocityProcedure.run(velocity);
        if (note)
        {
            noteOnPitchVelocityProcedure.run(pitch, velocity);
            noteOnProcedure.run(channel, pitch, velocity);
        }
        else
        {
            noteOffPitchVelocityProcedure.run(pitch, velocity);
            noteOffProcedure.run(channel, pitch, velocity);
        }
        procedure.run(note, channel, pitch, velocity);
    }
}

public class EuclidOsc
{
    OscSend client;
    OscRecv server;
    9000 => int port;

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

    fun void addPattern(string address, IntIntIntIntProcedure procedure)
    {
        Pattern pattern;
        address => pattern.address;
        server @=> pattern.server;
        procedure @=> pattern.procedure;
        pattern.connect();
    }

    fun void addPattern(string address, IntIntIntProcedure noteOnProcedure, IntIntIntProcedure noteOffProcedure)
    {
        Pattern pattern;
        address => pattern.address;
        server @=> pattern.server;
        noteOnProcedure @=> pattern.noteOnProcedure;
        noteOffProcedure @=> pattern.noteOffProcedure;
        pattern.connect();
    }

    fun void addPattern(string address, IntIntProcedure noteOnPitchVelocityProcedure, IntIntProcedure noteOffPitchVelocityProcedure)
    {
        Pattern pattern;
        address => pattern.address;
        server @=> pattern.server;
        noteOnPitchVelocityProcedure @=> pattern.noteOnPitchVelocityProcedure;
        noteOffPitchVelocityProcedure @=> pattern.noteOffPitchVelocityProcedure;
        pattern.connect();
    }

    fun void addPattern(string address, IntProcedure noteProcedure, IntProcedure channelProcedure, IntProcedure pitchProcedure, IntProcedure velocityProcedure)
    {
        Pattern pattern;
        address => pattern.address;
        server @=> pattern.server;
        noteProcedure @=> pattern.noteProcedure;
        channelProcedure @=> pattern.channelProcedure;
        pitchProcedure @=> pattern.pitchProcedure;
        velocityProcedure @=> pattern.velocityProcedure;
        pattern.connect();
    }
}
Something went wrong with that request. Please try again.