summaryrefslogtreecommitdiff
path: root/midi/RHMixxx-scripts.js
blob: 0d7114f0e46cf5ca702d652b75bd57241e6ac38b (plain)
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
//***********************************************************
//**      Radio Helsinki RHMixxx control script            **
//**    CopyLeft 2014, Josef Schauer / Christian Pointner  **
//***********************************************************

// *********** Preamble  ***********

function RHMixxx() {}

RHMixxx.groupNotes = {
    "[Channel1]": { play: 0x01, stop: 0x00 },
    "[Channel2]": { play: 0x03, stop: 0x02 },
    "[Sampler1]": 0x04,
    "[Sampler2]": 0x05,
    "[Sampler3]": 0x06,
    "[Sampler4]": 0x07,
    "[Sampler5]": 0x08,
    "[Sampler6]": 0x09,
    "[Sampler7]": 0x0A,
    "[Sampler8]": 0x0B,
    "[Sampler9]": 0x0C,
    "[Sampler10]": 0x0D,
    "[Sampler11]": 0x0E,
    "[Sampler12]": 0x0F
}

// *********** Init/De-Init  ***********

RHMixxx.init = function (id, debug) {
    var num_decks = engine.getValue("[Master]", "num_decks");
    var num_sampler = engine.getValue("[Master]", "num_samplers");

    if(debug)
        print("RHMixxx initializing for controller '" + id +
              "' (" + num_decks + " Decks, " + num_sampler + " Sampler)");

    var i;
    for (i = 1; i <= num_decks; i++)
        RHMixxx.initDeck(i, debug);
    for (i = 1; i <= num_sampler; i++)
        RHMixxx.initSampler(i, debug);

    midi.sendShortMsg(0x80, 0x1F, 0x00);
}

RHMixxx.shutdown = function () {
}


RHMixxx.initDeck = function (c, debug) {
    var group = "[Channel" + c + "]";

    engine.setValue(group, "volume", 0);
    engine.connectControl(group, "play", "RHMixxx.DeckPlaying");
    engine.trigger(group, "play");
    engine.connectControl(group, "track_samples", "RHMixxx.DeckSamples");
    engine.trigger(group, "track_samples");

    if(debug)
        print("RHMixxx: " + group + " initilized!");
}

RHMixxx.initSampler = function (s, debug) {
    var group = "[Sampler" + s + "]";

    engine.setValue(group, "volume", 1.0);
    engine.connectControl(group, "play", "RHMixxx.SamplerPlaying");
    engine.trigger(group, "play");
    engine.connectControl(group, "track_samples", "RHMixxx.SamplerSamples");
    engine.trigger(group, "track_samples");

    if(debug)
        print("RHMixxx: " + group + " initilized!");
}

// *********** Actions  ***********

RHMixxx.StopDeck = function (channel, control, value, status, group) {
    engine.setValue(group, "start_stop", value);
}

RHMixxx.ToggleSampler = function (channel, control, value, status, group) {
    print("RHMixxx: ToggleSampler called for " + group);

    if(!engine.getValue(group, "play")) {
        if(value)
            engine.setValue(group, "play", 1);
    }
    else {
        engine.setValue(group, "start_stop", value);
    }
}


// *********** Status updates  ***********

RHMixxx.DeckPlaying = function (value, group, control) {
    if (!value) {
        if(engine.getValue(group, "track_samples") != 0) {
           midi.sendShortMsg(0x90, RHMixxx.groupNotes[group].stop, 0x00);
           midi.sendShortMsg(0x90, RHMixxx.groupNotes[group].play, 0x00);
        } else {
           midi.sendShortMsg(0x80, RHMixxx.groupNotes[group].stop, 0x00);
           midi.sendShortMsg(0x80, RHMixxx.groupNotes[group].play, 0x00);
        }
    } else {
        midi.sendShortMsg(0x90, RHMixxx.groupNotes[group].stop, 0x00);
        midi.sendShortMsg(0x90, RHMixxx.groupNotes[group].play, 0x10);
    }
}

RHMixxx.DeckSamples = function (value, group, control) {
    if(!value) {
        midi.sendShortMsg(0x80, RHMixxx.groupNotes[group].stop, 0x00);
        midi.sendShortMsg(0x80, RHMixxx.groupNotes[group].play, 0x00);
    } else {
        if(engine.getValue(group, "play") == 0) {
            midi.sendShortMsg(0x90, RHMixxx.groupNotes[group].stop, 0x00);
            midi.sendShortMsg(0x90, RHMixxx.groupNotes[group].play, 0x00);
        }
    }
}

RHMixxx.SamplerPlaying = function (value, group, control) {
    if (!value) {
        if(engine.getValue(group, "track_samples") != 0) {
            midi.sendShortMsg(0x90, RHMixxx.groupNotes[group], 0x00);
            engine.setValue(group, "start_stop", 1);
            engine.setValue(group, "start_stop", 0);
        } else {
            midi.sendShortMsg(0x80, RHMixxx.groupNotes[group], 0x00);
        }
    }
    else {
        midi.sendShortMsg(0x90, RHMixxx.groupNotes[group], 0x10);
    }
}

RHMixxx.SamplerSamples = function (value, group, control) {
    if(!value) {
        midi.sendShortMsg(0x80, RHMixxx.groupNotes[group], 0x00);
    } else {
        if(engine.getValue(group, "play") == 0)
            midi.sendShortMsg(0x90, RHMixxx.groupNotes[group], 0x00);
    }
}