aboutsummaryrefslogtreecommitdiffhomepage
path: root/desktop/core/library/d.js
blob: df81c1a1c08e21e8aceb1ccd3e4551f81b434e52 (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
'use strict'

const Operator = require('../operator')

function OperatorD (orca, x, y, passive) {
  Operator.call(this, orca, x, y, 'd', passive)

  this.name = 'delay'
  this.info = 'Bangs on a fraction of the runtime frame.'

  this.ports.haste.rate = { x: -1, y: 0 }
  this.ports.input.offset = { x: 1, y: 0 }
  this.ports.output = { x: 0, y: 1 }

  this.run = function () {
    const offset = this.listen(this.ports.input.offset, true)
    const rate = clamp(this.listen(this.ports.haste.rate, true), 2, 36)
    const res = (orca.f + offset) % rate === 0 ? '*' : '.'
    this.output(`${res}`)
  }

  function clamp (v, min, max) { return v < min ? min : v > max ? max : v }
}

module.exports = OperatorD