-
Notifications
You must be signed in to change notification settings - Fork 0
/
index4.html
353 lines (315 loc) · 10.3 KB
/
index4.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<!DOCTYPE html>
<html lang="en">
<head>
<title>FP30 playground webmidi</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://code.jquery.com/ui/1.12.1/themes/dark-hive/jquery-ui.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>
<style>
body{
font-family:verdana,sans-serif;
font-size:12pt;
background-color:#333
}
h2{
color:#ccc;
margin-left:4px;
}
fieldset{
font-size:11pt;
margin:0px;
border-color:#777;
border-radius: 8px;
}
select{
height:30px;
font-size:12pt;
font-weight:bold;
border-radius: 4px;
background:#444;
color:#ddd;
}
input[type=checkbox]{
-ms-transform: scale(1.5); /* IE */
-moz-transform: scale(1.5); /* FF */
-webkit-transform: scale(1.5); /* Safari and Chrome */
-o-transform: scale(1.5); /* Opera */
transform: scale(1.5);
padding:0px;
margin:0px;
}
button{
height:30px;
font-size:11pt;
border-radius: 4px;
background-color:#555;
color:#ddd;
}
div{
margin-left:12px;
margin-right:12px;
margin-top:20px;
margin-bottom:20px;
}
label{
color:#ccc;
margin:3px;
}
.labslide{
font-size:10pt;
color:#ccc;
margin:3px;
}
.slider {
-webkit-appearance: none;
width: 60%;
height: 20px;
border-radius: 5px;
background: #888;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 30px;
height: 30px;
border-color:#000;
border-width:1px;
border-radius: 30%;
background: #6ad;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 30px;
height: 30px;
border-color:#000;
border-width:1px;
border-radius: 30%;
background: #6ad;
cursor: pointer;
}
</style>
<script type="text/javascript">
var midi = null; // global MIDIAccess object
var midiinput = null;
var midioutput = null;
var midiIn = [];
var midiOut = [];
var sounds=null;
var part=0;
var midiloopback = false;
var midilocal = true;
var midisustain = false;
function reset(){
if (midioutput)
midioutput.send([0xb0,0x79,0x00]) //#Reset all
}
function setvolumen(value=127){
$("#vol").text(value);
if (midioutput)
midioutput.send([0xb0+part,0x07,value]);
}
function setexpression(value=127){
if (midioutput)
midioutput.send([0xb0+part,0x11,value]);
}
function setreverb(value=0){
$("#rev").text(value);
if (midioutput)
midioutput.send([0xb0+part,91,value]);
}
function setchorus(value=0){
$("#cho").text(value);
if (midioutput)
midioutput.send([0xb0+part,93,value]);
}
function setattack(value=64){
$("#att").text(value);
if (midioutput)
midioutput.send([0xb0+part,73,value]);
}
function setrelease(value=64){
$("#rel").text(value);
if (midioutput)
midioutput.send([0xb0+part,72,value]);
}
function setcutoff(value=64){
$("#cut").text(value);
if (midioutput)
midioutput.send([0xb0+part,74,value]);
}
function setdecay(value=64){
$("#dec").text(value);
if (midioutput)
midioutput.send([0xb0+part,75,value]);
}
function changepart(value){
//alert(value);
part = value;
}
function selectedSound(){
var select = $("#selectSound")[0];
//alert(select.selectedIndex);
var pc = sounds["voice"][select.selectedIndex]["PC"];
var msb = sounds["voice"][select.selectedIndex]["MSB"];
var lsb = sounds["voice"][select.selectedIndex]["LSB"];
//alert (select.selectedIndex+" "+pc+" "+msb+" "+lsb);
if (midioutput){
midioutput.send([0xb0+part,0x00,msb]); // bank msb
midioutput.send([0xb0+part,0x20,lsb]); // bank lsb
midioutput.send([0xc0+part,pc-1]); // program change
}
//$(':focus').blur();
}
function selectmidilocal(cb){
midilocal=cb.checked;
// Send midi loopback command
if (midilocal)
data = [0xb0,0x7A,0x7F];
else
data = [0xb0,0x7A,0x00];
if (midioutput)
midioutput.send(data);
}
function selectloopback(cb){
midiloopback=cb.checked;
midisustain=cb.checked;
$("#midisustain")[0].checked = cb.checked;
}
function selectmidisustain(cb){
midisustain=cb.checked;
}
function echoMIDIMessage( event ) {
//console.log(event.data)
if (midiloopback && midioutput) {
midioutput.send( event.data, event.timestamp );
}
}
function initDevices(midi) {
// MIDI devices that send you data.
const inputs = midi.inputs.values();
for (let input = inputs.next(); input && !input.done; input = inputs.next()) {
midiIn.push(input.value);
}
// MIDI devices that you send data to.
const outputs = midi.outputs.values();
for (let output = outputs.next(); output && !output.done; output = outputs.next()) {
midiOut.push(output.value);
}
var select = document.getElementById("selectInterface");
var options = midiIn;
for(var i = 0; i < options.length; i++) {
var opt = options[i].name;
var el = document.createElement("option");
el.textContent = opt;
el.value = opt;
select.appendChild(el);
}
//displayDevices();
//startListening();
}
function selectedInterface(){
var selectint = document.getElementById("selectInterface");
//alert(selectint.options[selectint.selectedIndex].index);
var interfacename = midiIn[selectint.options[selectint.selectedIndex].index-1].name
//alert(interfacename);
// Search this name on midi outputs
for (var i=0;i<midiOut.length;i++)
if (midiOut[i].name == interfacename){
// Connect midioutput
midioutput = midiOut[i]
//alert("Connected to: "+midioutput.name)
$("#con").text("Connected!");
$("#con").css("color","#008000");
break;
}
midiinput = midiIn[selectint.options[selectint.selectedIndex].index-1]
midiinput.onmidimessage = echoMIDIMessage;
//alert(midiinput.name);
// Reset
reset();
setvolumen(127);
setexpression(127);
setreverb(0x0e);
setchorus(0);
setattack(64);
setrelease(64);
setcutoff(64);
setdecay(64);
}
function onMIDISuccess( midiAccess ) {
console.log( "MIDI sucess!" );
midi = midiAccess
initDevices(midi);
//if (!midiinput || !midioutput)
// console.log("Uh oh! Couldn't get i/o ports.");
}
function onMIDIFailure(msg) {
console.log( "Failed to get MIDI access - " + msg );
alert("Failed to get MIDI access - " + msg)
}
function setup(){
navigator.requestMIDIAccess({sysex:false}).then( onMIDISuccess, onMIDIFailure );
$.getJSON( "https://jjulio.github.io/FP30test/sounds2.json", function(data) {
console.log( "sounds load success" );
sounds = data["voices"]
var select = $("#selectSound")[0];
//var select = document.getElementById("selectSound");
for(var i = 0; i < sounds["voice"].length; i++) {
var opt = sounds["voice"][i]["Set"]+"-"+sounds["voice"][i]["Category"]+"-"+sounds["voice"][i]["content"];
var el = document.createElement("option");
el.textContent = opt;
el.value = opt;
select.appendChild(el);
}
$("#selectSound").selectmenu("refresh");
});
}
</script>
</head>
<body onload="setup();">
<div><h2>FP30 Playground</h2></div>
<div><select id="selectInterface">
<option>Choose Midi interface</option>
</select>
<button onclick="selectedInterface()">Connect</button>
<label id="con" style="color:#777;font-size:11pt;"> Not connected</label>
</div>
<fieldset>
<div style="margin-top:10px;">
<input type="checkbox" id="cbox1" checked=true onchange="selectmidilocal(this);"> <label>Main keyboard (Midi local)</label>
</div>
<div style="margin-bottom:5px;">
<input type="checkbox" id="cbox2" onchange="selectloopback(this);"> <label>New sounds (Midi loopback) </label>
<input type="checkbox" id="midisustain" onchange="selectmidisustain(this);"> <label>Sustain(CC)</label>
</div>
</fieldset>
<div id="radioset" style="padding:4px;margin:0px;font-size:10pt;">
<input type="radio" id="part1" name="radio" onchange="changepart(0);" checked="checked"><label for="part1">Part 1(main)</label>
<input type="radio" id="part3" name="radio" onchange="changepart(2);"><label for="part3">Part 3(split)</label>
<input type="radio" id="part5" name="radio" onchange="changepart(4);"><label for="part5">Part 5(dual)</label>
</div>
<div style="padding:6px;margin:0px;">
<label for="selectSound" style="font-weight:bold;">SOUND:</label>
<select id="selectSound" name="selectSound"></select>
</div>
<div><input type="range" min="0" max="127" value="127" class="slider" id="volumen" oninput="setvolumen(this.value);"><label class="labslide">Volume</label><label class="labslide" id="vol">127</label></div>
<div><input type="range" min="0" max="127" value="0" class="slider" id="reverb" oninput="setreverb(this.value);"><label class="labslide">Reverb</label><label class="labslide" id="rev">0</label></div>
<div><input type="range" min="0" max="127" value="0" class="slider" id="chorus" oninput="setchorus(this.value);"><label class="labslide">Chorus</label><label class="labslide" id="cho">0</label></div>
<div><input type="range" min="0" max="127" value="64" class="slider" id="attack" oninput="setattack(this.value);"><label class="labslide">Attack</label><label class="labslide" id="att">64</label></div>
<div><input type="range" min="0" max="127" value="64" class="slider" id="release" oninput="setrelease(this.value);"><label class="labslide">Release</label><label class="labslide" id="rel">64</label></div>
<div><input type="range" min="0" max="127" value="64" class="slider" id="cutoff" oninput="setcutoff(this.value);"><label class="labslide">Cutoff</label><label class="labslide" id="cut">64</label></div>
<div><input type="range" min="0" max="127" value="64" class="slider" id="decay" oninput="setdecay(this.value);"><label class="labslide">Decay</label><label class="labslide" id="dec">64</label></div>
<script>
//$("#selectInterface").selectmenu({change: function(event,data){selectedInterface();}});
$("#selectSound").selectmenu({ width : 'auto',change: function(event,data){selectedSound();}});
$( "#radioset" ).buttonset();
</script>
</body>
</html>