forked from LividInstruments/Livid-Online-Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquerytest.html
275 lines (241 loc) · 7.29 KB
/
querytest.html
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
273
274
275
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Select MIDI Out</title>
<style type="text/css">
.hidden {
visibility: hidden;
width: 0px;
height: 0px;
margin: 0px;
padding: 0px;
border-style: none;
border-width: 0px;
max-width: 0px;
max-height: 0px;
}
</style>
<script type="text/javascript" charset="utf-8">
var inquiry = [240,126,127,6,1,247]; //generic inquiry sysex message
var pid = 7; //product id. using OhmRGB
var head = [240, 0, 1, 97, pid]; //sysex header for Livid products
var eom = 247; //end of message byte for sysex
var requests = []; //container for the request commands
requests[4]=[4,8,11,12,13,15,16,17,22,23,26,30,31,32,35,36,37,38,39,50,54]; //all the settings requests we need for the code v2
requests[7]=[4,8,10,11,12,13,15,22,23,26,33,34,35,36,37,54]; //some settings requests we need for tests
var sysexbuffer = new Array(); //buffer for sysex data, in midiProc
var issysex = false;
var settings = new Array(); //used to store sysex settings data when received from the controller
function log(s){
console.log(s);
}
//print info to the browser window
function blog(s) {
var d = document.getElementById("console");
d.innerHTML = d.innerHTML+s+"<br />";
}
//open the MIDI port selected by the menu
function midioutports(){
Jazz.MidiOutOpen(outports.options[outports.selectedIndex].value);
}
//generic function that I re-write as needed for testing!
function testfcn(v){
if(Jazz.isJazz){
if(v==0){
counter=0;
Jazz.MidiOutLong(inquiry);
log("send inquiry");
}
}
}
var tnote=0;
function testnote(){
if(Jazz.isJazz){
var note = tnote%64;
Jazz.MidiOut(144,note-1,2);
Jazz.MidiOut(144,note,64);
tnote++;
}
}
function testsx(){
if(Jazz.isJazz){
Jazz.MidiOutLong([240,0,1,97,12,7,4,247]);
tnote++;
}
}
//send the inquiry sysex message to each port on successive clicks of the the "inquiry" button
var counter=0;
function testloop(){
log("begin test "+inlist.length);
//for(var i=0;i<list.length;i++){
log("send inquiry to port "+counter+" "+inlist[counter]);
//Jazz.MidiInOpen(inlist[counter],function(t,a){ midiProc(a);});
Jazz.MidiOutOpen(inlist[counter]);
Jazz.MidiOutLong(inquiry);
//}
counter++;
}
//sets the MIDI input port when selected with menu.
function midiinports(){
//Jazz.MidiInOpen(inports.options[inports.selectedIndex].value,function(t,a){ midiProc(a);});
Jazz.MidiInOpen(inports.options[inports.selectedIndex].value);
}
function midiProc(){
var arg = Array.prototype.slice.call(arguments, 0);
var lasti = (arg[0].length-1);
//log( "in "+arg[0] );
//working around a bug in the MIDI plug in where it breaks up long sysex strings: we detect start and end of sysex, and gather it into a buffer.
if(issysex){
sysexbuffer = sysexbuffer.concat(arg[0]);
}
if(arg[0][0]==240){
sysexbuffer = new Array();
sysexbuffer = sysexbuffer.concat(arg[0]);
issysex = true;
}
if(arg[0][lasti]==247){
issysex = false;
if(requesting){
settings[cmdno]=sysexbuffer.slice(0); //clone the buffer into the settings container.
cmdno++;
if(cmdno<requests[pid].length){ //if we still have items left in the "requests" array
var req=requests[pid][cmdno]; //get the request ID
log(">next REQ "+req+" ("+cmdno+" of "+requests[pid].length+")");
cmdout(req); //send the request
//var output = setTimeout(function(){ cmdout(req) },60); //schedule the next one
}else{
blog("REQ DONE");
}
}
}else if(!issysex){
log( "midi "+arg[0] );
}
}
function mout(){
var arg = Array.prototype.slice.call(arguments, 0);
log("midiout "+arg[0]+" len: "+arg[0].length );
//Jazz.MidiOutLong([240,0,1,97,12,7,4,247]);
Jazz.MidiOutLong(arg[0]);
//testnote();
}
function printsx(){
if(settings.length){
for(i in settings){
log("settings: "+settings[i]);
}
}else{
log("----nothing stored in settings array----");
}
}
var sysexb={};
var qproc = '';
function queryd(){
qproc=setInterval(function(){ // start the polling cycle
var arr;
while(arr=Jazz.QueryMidiIn()){ // while the queue is not empty
var ts=arr[0]; // the first element is the time stamp
var msg=arr.slice(1,arr.length); // the rest is the message
if(sysexb[ts]){
sysexb[ts]=sysexb[ts].concat(msg);
}else{
sysexb[ts]=msg;
}
log("time "+ts+" sx "+msg);
}
},0);
}
function qdone(){
log("done");
log(".");
log(".");
clearInterval(qproc);
clearInterval(qreq);
//printout:
for(t in sysexb){
log("sx "+t+" msg "+sysexb[t]);
}
//fix any sysex messages that split up over 2 timestamps
for(t in sysexb){
var last = sysexb[t].length-1;
if(sysexb[t][last]!=247){
sysexb[t]=sysexb[t].concat(sysexb[Number(t)+1]); //merge with the next one
delete sysexb[Number(t)+1]; //delete it
}
}
//printout:
for(t in sysexb){
log("sx "+t+" msg "+sysexb[t]);
}
//close the port so we can...
Jazz.MidiInClose();
//...open up the port with callback function
Jazz.MidiInOpen(inports.options[inports.selectedIndex].value,function(t,a){ midiProc(a);});
}
var qreq = '';
function spill(){
log("BEGIN SPILL ROUTINE");
//requesting = 1;
queryd();
var reqi=0;
var sched=5;
qreq=setInterval(function(){ // start the polling cycle
var req=requests[pid][reqi];
reqi++;
if(req){
log("->REQ "+req);
var midiout = [];
midiout = midiout.concat(head,7,req,eom);
mout(midiout);
}
},sched);
var delay = sched*(requests[pid].length+1);
log("delay "+delay);
setTimeout(function(){qdone()},delay);
}
</script>
</head>
<body>
<h3>TEST MIDI</h3>
<div id=midiio class="hidden">
MIDI Out: <select id=outports onchange='midioutports();'></select><br/>
MIDI In: <select id=inports onchange='midiinports();'></select>
</div>
<!--<p><button onmousedown='testloop();'> test</button></p>
<p><button onmousedown='testfcn(0);'> inquiry</button></p>
<p><button onmousedown='printsx();'> print the sysex settings that have been stored</button></p>-->
<p><button onmousedown='testnote();'> note</button></p>
<p><button onmousedown='testsx();'> sx</button></p>
<p><button onmousedown='request();'> request settings</button></p>
<p><button onmousedown='spill();'> spill</button></p>
<div id="console"></div>
<object id="Jazz1" classid="CLSID:1ACE1618-1C7D-4561-AEE1-34842AA85E90" class="hidden">
<object id="Jazz2" type="audio/x-jazz" class="hidden">
<p style="visibility:visible;">This page requires <a href=http://jazz-soft.net>Jazz-Plugin</a> ...</p>
</object>
</object>
<script><!--
var Jazz = document.getElementById("Jazz1"); if(!Jazz || !Jazz.isJazz) Jazz = document.getElementById("Jazz2");
var outports=document.getElementById('outports');
try{
var list=Jazz.MidiOutList();
for(var i in list){
outports[i]=new Option(list[i],list[i],i==0,i==0);
}
log("outs "+list);
document.getElementById('midiio').className=''; //change class to nothing so it's visible
}
catch(err){}
var inports=document.getElementById('inports');
var inlist=[];
try{
inlist=Jazz.MidiInList();
for(var i in list){
inports[i]=new Option(list[i],list[i],i==0,i==0);
}
log("ins "+list);
document.getElementById('midiio').className=''; //change class to nothing so it's visible
}
catch(err){}
--></script>
</body>
</html>