<commit_before>{.this:self.}

import dom
import jsconsole
import ajax
import html5_canvas
import math

import common
import nico.controller
import json

import webaudio
var ctx: CanvasRenderingContext2d
var swCanvas32: ImageData
var canvas: Canvas
var interval: ref TInterval
var audioContext: AudioContext

type Channel = object
  kind: ChannelKind
  source: AudioNode
  callback: proc(samples: seq[float32])
  musicId: int

  arp: uint16
  arpSpeed: uint8

  loop: int
  phase: float # or position
  freq: float # or speed
  basefreq: float
  targetFreq: float
  width: float
  pan: float
  shape: SynthShape
  gain: GainNode

  init: range[0..15]
  env: range[-7..7]
  envValue: float32
  envPhase: int
  length: range[0..255]
  vibspeed: range[1..15]
  vibamount: range[0..15]
  glide: range[0..15]

  pchange: range[-127..127]

  trigger: bool
  lfsr: int
  lfsr2: int
  nextClick: int
  outvalue: float32

  priority: float

  wavData: array[32, uint8]

var audioChannels: array[nAudioChannels, Channel]

var tickFunc: proc() = nil


var currentBpm: Natural = 128
var currentTpb: Natural = 4

var sfxData: array[64,AudioBuffer]
var musicData: array[64,AudioBuffer]
var currentMusic: AudioBufferSourceNode = nil

var sfxGain, musicGain, masterGain: GainNode

keymap = [
  @[37, 65], # left
  @[39, 68], # right
  @[38, 87], # up
  @[40, 83], # down
  @[90, 89], # A, Y
  @[88], # B
  @[16], # X
  @[67], # Y
  @[70], # L1
  @[71], # L2
  @[86], # R1
  @[66], # R2
  @[13], # Start
  @[27, 8], # Back
]

export convertToConsoleLoggable

template debug*(args: varargs[untyped]) =
  console.log(args)

proc setKeyMap*(newmap: string) =
  discard

proc present*() =
  # copy swCanvas to canvas
  for i,v in swCanvas.data:
    swCanvas32.data[i*4] = colors[v][0]
    swCanvas32.data[i*4+1] = colors[v][1]<commit_msg>updates<commit_after>{.this:self.}

import dom
import jsconsole
import ajax
import html5_canvas
import math

import common
import nico.controller
import json

import webaudio
var ctx: CanvasRenderingContext2d
var swCanvas32: ImageData
var canvas: Canvas
var interval: ref TInterval
var audioContext: AudioContext

type Channel = object
  kind: ChannelKind
  source: AudioNode
  callback: proc(samples: seq[float32])
  musicId: int

  arp: uint16
  arpSpeed: uint8

  loop: int
  phase: float # or position
  freq: float # or speed
  basefreq: float
  targetFreq: float
  width: float
  pan: float
  shape: SynthShape
  gain: GainNode

  init: range[0..15]
  env: range[-7..7]
  envValue: float32
  envPhase: int
  length: range[0..255]
  vibspeed: range[1..15]
  vibamount: range[0..15]
  glide: range[0..15]

  pchange: range[-127..127]

  trigger: bool
  lfsr: int
  lfsr2: int
  nextClick: int
  outvalue: float32

  priority: float

  wavData: array[32, uint8]

var audioChannels: array[nAudioChannels, Channel]

var tickFunc: proc() = nil


var currentBpm: Natural = 128
var currentTpb: Natural = 4

var sfxData: array[64,AudioBuffer]
var musicData: array[64,AudioBuffer]
var currentMusic: AudioBufferSourceNode = nil

var sfxGain, musicGain, masterGain: GainNode

keymap = [
  @[37, 65], # left = arrow, a
  @[39, 68], # right = arrow, d
  @[38, 87], # up = arrow, w
  @[40, 83], # down = arrow, s

  @[90, 89, 72], # A = z, y, h
  @[88, 85, 74], # B = x, u, j
  @[67, 79, 75], # X = c, o, k
  @[86, 80, 76], # Y = v, p, l

  @[66], # L1

  @[71], # L2
  @[72], # R1
  @[78], # R2
  @[13, 32], # Start
  @[27, 8], # Back
]

export convertToConsoleLoggable

template debug*(args: varargs[untyped]) =
  console.log(args)

proc setKeyMap*(newmap: string) =
  discard

proc present*() =
  # copy swCanvas to canvas
  for i,v in swCanvas.data:
    swCanvas32.data[i*4] = colors[v][0]
    swCanvas32.data[i*4+1] = colors[v][1]
{'fraction_non_alphanumeric': 0.13174772848743987, 'fraction_numerical': 0.058257616247995726, 'mean_word_length': 3.720050441361917, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1638163', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1442, 'n_words': 420}