Add 'plot' function and remove deprecated 'percent' type
This commit is contained in:
@@ -11,6 +11,7 @@ from smnp.type.signature.matcher.type import ofTypes, ofType
|
||||
DEFAULT_BPM = 120
|
||||
DEFAULT_OVERTONES = [0.4, 0.3, 0.1, 0.1, 0.1]
|
||||
DEFAULT_DECAY = 4
|
||||
DEFAULT_ATTACK = 100
|
||||
|
||||
|
||||
def getBpm(config):
|
||||
@@ -59,15 +60,28 @@ def getDecay(config):
|
||||
return DEFAULT_DECAY
|
||||
|
||||
|
||||
def getAttack(config):
|
||||
key = Type.string("attack")
|
||||
if key in config.value:
|
||||
attack = config.value[key]
|
||||
if not attack.type in [Type.INTEGER, Type.FLOAT] or attack.value < 0:
|
||||
raise RuntimeException("The 'attack' property must be non-negative integer or float", None)
|
||||
|
||||
return attack.value
|
||||
|
||||
return DEFAULT_ATTACK
|
||||
|
||||
|
||||
class Config:
|
||||
def __init__(self, bpm, overtones, decay):
|
||||
def __init__(self, bpm, overtones, decay, attack):
|
||||
self.bpm = bpm
|
||||
self.overtones = overtones
|
||||
self.decay = decay
|
||||
self.attack = attack
|
||||
|
||||
@staticmethod
|
||||
def default():
|
||||
return Config(DEFAULT_BPM, DEFAULT_OVERTONES, DEFAULT_DECAY)
|
||||
return Config(DEFAULT_BPM, DEFAULT_OVERTONES, DEFAULT_DECAY, DEFAULT_ATTACK)
|
||||
|
||||
|
||||
_signature1 = varargSignature(listOf(Type.NOTE, Type.INTEGER))
|
||||
@@ -87,8 +101,9 @@ def _function3(env, config, notes):
|
||||
bpm = getBpm(config)
|
||||
overtones = getOvertones(config)
|
||||
decay = getDecay(config)
|
||||
attack = getAttack(config)
|
||||
|
||||
play(rawNotes, Config(bpm, overtones, decay))
|
||||
play(rawNotes, Config(bpm, overtones, decay, attack))
|
||||
|
||||
|
||||
_signature4 = varargSignature(ofTypes(Type.NOTE, Type.INTEGER), ofType(Type.MAP))
|
||||
@@ -96,8 +111,9 @@ def _function4(env, config, notes):
|
||||
bpm = getBpm(config)
|
||||
overtones = getOvertones(config)
|
||||
decay = getDecay(config)
|
||||
attack = getAttack(config)
|
||||
|
||||
play([ notes ], Config(bpm, overtones, decay))
|
||||
play([ notes ], Config(bpm, overtones, decay, attack))
|
||||
|
||||
|
||||
function = CombinedFunction(
|
||||
|
||||
Reference in New Issue
Block a user