def _typeToMethodSignature(cls, node): if type(node.specifiers) == NoneNode: return signature(ofType(node.type.value)) elif node.type.value == Type.LIST: return signature(listSpecifier(node.specifiers[0])) elif node.type.value == Type.MAP: return signature( mapSpecifier(node.specifiers[0], node.specifiers[1]))
from smnp.function.model import CombinedFunction, Function from smnp.function.signature import signature from smnp.module.mic.lib.detector.noise import NoiseDetector from smnp.type.model import Type from smnp.type.signature.matcher.type import ofTypes _signature1 = signature() def _function1(env): nd = NoiseDetector() nd.waitForComplete() _signature2 = signature(ofTypes(Type.INTEGER), ofTypes(Type.INTEGER)) def _function2(env, noiseTreshold, silenceTreshold): nd = NoiseDetector(noiseTreshold.value, silenceTreshold.value) nd.waitForComplete() function = CombinedFunction('wait', Function(_signature1, _function1), Function(_signature2, _function2))
from smnp.function.model import CombinedFunction, Function from smnp.function.signature import signature from smnp.type.model import Type from smnp.type.signature.matcher.type import ofType _signature1 = signature(ofType(Type.FLOAT)) def _function1(env, value): return Type.integer(int(value.value)) _signature2 = signature(ofType(Type.STRING)) def _function2(env, value): return Type.integer(int(value.value)) _signature3 = signature(ofType(Type.INTEGER)) def _function3(env, value): return value function = CombinedFunction( 'Integer', Function(_signature1, _function1), Function(_signature2, _function2), Function(_signature3, _function3),
def check(value): return signature(*pattern).check(value.value)[0]
from smnp.function.model import Function from smnp.function.signature import signature from smnp.module.synth.lib.wave import plot from smnp.type.model import Type from smnp.type.signature.matcher.list import listOf _signature = signature(listOf(Type.FLOAT)) def _function(env, wave): rawWave = [m.value for m in wave.value] plot(rawWave) function = Function(_signature, _function, 'plot')
from smnp.function.model import Function from smnp.function.signature import signature from smnp.note.model import Note from smnp.type.model import Type from smnp.type.signature.matcher.type import ofType _signature = signature(ofType(Type.STRING), ofType(Type.INTEGER), ofType(Type.INTEGER), ofType(Type.BOOL)) def _function(env, note, octave, duration, dot): return Type.note(Note(note.value, octave.value, duration.value, dot.value)) function = Function(_signature, _function, 'Note')
from smnp.function.model import Function from smnp.function.signature import signature from smnp.type.model import Type from smnp.type.signature.matcher.type import allTypes _signature = signature(allTypes()) def _function(env, object): return Type.string(object.stringify()) function = Function(_signature, _function, 'toString')
from smnp.audio.sound import Sound from smnp.function.model import Function from smnp.function.signature import signature from smnp.type.model import Type from smnp.type.signature.matcher.type import ofType _signature = signature(ofType(Type.STRING)) def _function(env, file): return Type.sound(Sound(file.value)) function = Function(_signature, _function, 'Sound')
import sys from smnp.function.model import Function from smnp.function.signature import signature from smnp.type.model import Type from smnp.type.signature.matcher.type import ofTypes _signature = signature(ofTypes(Type.INTEGER)) def _function(env, code): sys.exit(code.value) function = Function(_signature, _function, 'exit')
ofTypes(Type.INTEGER, Type.STRING, Type.NOTE, Type.BOOL, Type.TYPE), allTypes())) def _function1(env, vararg): map = {} for entry in vararg: key, value = entry.value map[key] = value return Type.map(map) _signature2 = signature( listOfMatchers( listMatches( ofTypes(Type.INTEGER, Type.STRING, Type.NOTE, Type.BOOL, Type.TYPE), allTypes()))) def _function2(env, list): map = {} for entry in list.value: key, value = entry.value map[key] = value return Type.map(map) function = CombinedFunction('Map', Function(_signature1, _function1), Function(_signature2, _function2))
from smnp.error.runtime import RuntimeException from smnp.function.model import CombinedFunction, Function from smnp.function.signature import signature from smnp.token.tokenizers.bool import boolTokenizer from smnp.token.tokenizers.note import noteTokenizer from smnp.type.model import Type from smnp.type.signature.matcher.type import ofType _signature1 = signature() def _function1(env): value = input() return Type.string(value) _signature2 = signature(ofType(Type.STRING)) def _function2(env, prompt): print(prompt.value, end="") value = input() return Type.string(value) _signature3 = signature(ofType(Type.TYPE)) def _function3(env, type): value = input() return getValueAccordingToType(value, type)
from smnp.function.model import Function from smnp.function.signature import signature from smnp.type.model import Type from smnp.type.signature.matcher.type import ofType _signature = signature(ofType(Type.SOUND)) def _function(env, sound): sound.value.play() function = Function(_signature, _function, 'play')
import random from smnp.function.model import Function from smnp.function.signature import signature from smnp.type.model import Type from smnp.type.signature.matcher.type import ofType _signature = signature(ofType(Type.INTEGER), ofType(Type.INTEGER)) def _function(env, min, max): return Type.integer(random.randint(min.value, max.value)) function = Function(_signature, _function, 'rand')
from smnp.error.runtime import RuntimeException from smnp.function.model import CombinedFunction, Function from smnp.function.signature import signature from smnp.type.model import Type from smnp.type.signature.matcher.type import ofTypes, ofType _signature1 = signature(ofType(Type.LIST), ofType(Type.INTEGER)) def _function1(env, list, index): try: return list.value[index.value] except IndexError: raise RuntimeException(f"Attempt to access item which is outside the list", None) _signature2 = signature(ofType(Type.MAP), ofTypes(Type.INTEGER, Type.STRING, Type.NOTE, Type.BOOL, Type.TYPE)) def _function2(env, map, key): try: return map.value[key] except KeyError: raise RuntimeException(f"Attempt to access unknown key in map", None) function = CombinedFunction( 'get', Function(_signature1, _function1), Function(_signature2, _function2) )