This repository has been archived on 2017-07-22. You can view files and clone it, but cannot push or open issues/pull-requests.
jlsampler/scripts/keyboard.py

97 lines
2.3 KiB
Python
Executable File

#!/usr/bin/env python3
import sys
import configparser
from glob import glob
class Config:
def __init__(self, config_path):
cp = configparser.ConfigParser()
cp.read(config_path)
# Print non-keyboard keys.
for key in cp.keys():
if key in ('KEYBOARD', 'DEFAULT'):
continue
print('[' + key + ']')
conf = cp[key]
for k in conf.keys():
print('{0} = {1}'.format(k, conf[k]))
conf = cp['KEYBOARD']
self.midi_min = conf.getint('midi_min', 21)
self.midi_max = conf.getint('midi_max', 109)
self.amp_low = conf.getfloat('amp_low', 0.24)
self.amp_high = conf.getfloat('amp_high', 0.04)
self.rms_time_low = conf.getfloat('rms_time_low', 500)
self.rms_time_high = conf.getfloat('rms_time_high', 50)
class Tuning:
def __init__(self, path):
self.cp = configparser.ConfigParser()
self.cp.read(path)
self.conf = self.cp['TUNING']
def get_freq(self, note):
# TODO!
return None
class Note:
def __init__(self, idx, conf):
self.conf = conf
self.idx = idx
self.path = "samples/*{0:03}-*-*.flac".format(idx)
def name(self):
return "note-{0:03}".format(self.idx)
def _linear(self, low, high):
m = (high - low) / 87.0
return low + m * (self.idx - 21)
def amp(self):
return self._linear(conf.amp_low, conf.amp_high)
def rms_time(self):
return self._linear(conf.rms_time_low, conf.rms_time_high)
def conf_path(self):
return 'path = ' + self.path
def conf_fx(self):
return 'fx = divide_rms({0}) amp({1})'.format(
self.rms_time(), self.amp())
def noteFromFile(fn):
base = os.path.splitext(fn)[0]
return int(base.split('-')[-3])
if __name__ == '__main__':
conf = Config(sys.argv[1])
# Create the notes.
notes = []
for idx in range(conf.midi_min, conf.midi_max + 1):
notes.append(Note(idx, conf))
# Print triggers.
print('\n[TRIGGERS]')
for note in notes:
print('{0} = {1}'.format(note.idx, note.name()))
print('\n[GLOBAL]')
print('tau_off = 100')
# Print notes.
for note in notes:
print('')
print('[{0}]'.format(note.name()))
print(note.conf_path())
print(note.conf_fx())