aboutsummaryrefslogtreecommitdiffhomepage
path: root/desktop/sources/scripts/qqq.js
blob: 3eb2bc5778b228ab16f2973a61073f34fd7bf2f6 (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
'use strict'

function QQQ (terminal) {
  this.terminal = terminal
  this.volume = 1
  this.midi = false
  this.outputs = []

  this.start = function () {
    this.midiSetup()
  }

  this.midiSetup = function () {
    if (!navigator.requestMIDIAccess) { return }

    navigator.requestMIDIAccess({ sysex: false }).then(this.midiActive, this.midiInactive)
  }

  this.midiActive = function (midiAccess) {
    const iter = midiAccess.outputs.values()
    for (let i = iter.next(); i && !i.done; i = iter.next()) {
      console.log(terminal.qqq)
      terminal.qqq.outputs.push(i.value)
    }
  }

  this.midiInactive = function (err) {
    console.warn('No Midi')
  }

  this.play = function () {
    this.ch1()
    this.ch3()
  }

  this.ch1 = function () {
    terminal.qqq.outputs[0].send([0x90, 60, 127])
    terminal.qqq.outputs[0].send([0x80, 60, 127], window.performance.now() + 250.0)
  }

  this.ch3 = function () {
    terminal.qqq.outputs[0].send([0x92, 60, 127])
    terminal.qqq.outputs[0].send([0x82, 60, 127], window.performance.now() + 250.0)
  }

  this.setVolume = function (value) {
    this.terminal.log(`Changed volume to ${value}.`)
    this.volume = parseInt(value) / 100.0
  }
}

module.exports = QQQ