Skip to content
This repository
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 175 lines (151 sloc) 4.286 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
/*

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/>.

*/

public class NanoPad
{
    MidiIn min;
    MidiMsg msg;

    // cached values
    int _lastX;
    int _lastY;

    // assign a custom int procedure to each button press
    IntProcedure button1;
    IntProcedure button2;
    IntProcedure button3;
    IntProcedure button4;
    IntProcedure button5;
    IntProcedure button6;
    IntProcedure button7;
    IntProcedure button8;
    IntProcedure button9;
    IntProcedure button10;
    IntProcedure button11;
    IntProcedure button12;
    // assign a custom int int procedure to XY pad changes
    IntIntProcedure xy;

    fun int getX()
    {
        return _lastX;
    }

    fun int getY()
    {
        return _lastY;
    }

    fun int open(int device)
    {
        min.open(device);

        while (true)
        {
            min => now;
            while (min.recv(msg))
            {
                msg.data1 => int control;
                msg.data2 => int note;
                msg.data3 => int velocity;

                // only fire on note on
                if (control == 144)
                {
                    // default notes in scene 1, see below
                    if (note == 39)
                    {
                        spork ~ button1.run(velocity);
                    }
                    if (note == 48)
                    {
                       spork ~ button2.run(velocity);
                    }
                    if (note == 45)
                    {
                        spork ~ button3.run(velocity);
                    }
                    if (note == 43)
                    {
                        spork ~ button4.run(velocity);
                    }
                    if (note == 51)
                    {
                        spork ~ button5.run(velocity);
                    }
                    if (note == 49)
                    {
                        spork ~ button6.run(velocity);
                    }
                    if (note == 36)
                    {
                        spork ~ button7.run(velocity);
                    }
                    if (note == 38)
                    {
                        spork ~ button8.run(velocity);
                    }
                    if (note == 40)
                    {
                        spork ~ button9.run(velocity);
                    }
                    if (note == 42)
                    {
                        spork ~ button10.run(velocity);
                    }
                    if (note == 44)
                    {
                        spork ~ button11.run(velocity);
                    }
                    if (note == 46)
                    {
                        spork ~ button12.run(velocity);
                    }
                }
                if (control == 224)
                {
                    if (note == velocity)
                    {
                        note => _lastX;
                        spork ~ xy.run(_lastX, _lastY);
                    }
                }
                if (control == 176)
                {
                    velocity => _lastY;
                    spork ~ xy.run(_lastX, _lastY);
                }
            }
        }
    }
}

/*

Notes:

Default, Scene 1
nanoPAD button, midi data2

1, 39
2, 48
3, 45
4, 43
5, 51
6, 49
7, 36
8, 38
9, 40
10, 42
11, 44
12, 46

Note ons are 144, ..., velocity
Note offs are 128, ..., 64

XY pad

changes in X are rec'd as
224, X, X

changes in Y are rec'd as
176, 1, Y

sometimes 224, 0, 64 is seen

*/
Something went wrong with that request. Please try again.