Move 'note' module

This commit is contained in:
Bartłomiej Pluta
2019-07-09 22:09:10 +02:00
parent b91cc46d44
commit ef99c4d6e2
9 changed files with 12 additions and 2 deletions

View File

View File

@@ -0,0 +1,11 @@
from smnp.library.model import Function
from smnp.library.signature import signature, ofType
from smnp.type.model import Type
_signature = signature(ofType(Type.NOTE), ofType(Type.INTEGER))
def _function(env, note, duration):
return Type.note(note.value.withDuration(duration.value))
function = Function(_signature, _function, 'withDuration')

View File

@@ -0,0 +1,11 @@
from smnp.library.model import Function
from smnp.library.signature import signature, ofType
from smnp.type.model import Type
_signature = signature(ofType(Type.NOTE), ofType(Type.INTEGER))
def _function(env, note, octave):
return Type.note(note.value.withOctave(octave.value))
function = Function(_signature, _function, 'withOctave')

View File

@@ -0,0 +1,13 @@
from smnp.library.model import Function
from smnp.library.signature import signature, ofTypes
from smnp.synth import player
from smnp.type.model import Type
_signature = signature(ofTypes(Type.INTEGER))
def _function(env, value):
bpm = env.findVariable('bpm')
player.pause(value.value, bpm.value)
function = Function(_signature, _function, 'pause')

View File

@@ -0,0 +1,24 @@
from smnp.library.model import Function, CombinedFunction
from smnp.library.signature import varargSignature, ofTypes, listOf
from smnp.note.model import Note
from smnp.type.model import Type
_signature1 = varargSignature(ofTypes(Type.NOTE, Type.INTEGER))
def _function1(env, vararg):
withoutPauses = [note.value for note in vararg if note.type == Type.NOTE]
if len(withoutPauses) < 2:
return Type.list([])
return Type.list([Type.integer(Note.checkInterval(withoutPauses[i-1], withoutPauses[i])) for i in range(1, len(withoutPauses))]).decompose()
_signature2 = varargSignature(listOf(Type.NOTE, Type.INTEGER))
def _function2(env, vararg):
return Type.list([_function1(env, arg.value) for arg in vararg]).decompose()
function = CombinedFunction(
"semitones",
Function(_signature1, _function1),
Function(_signature2, _function2),
)

View File

@@ -0,0 +1,21 @@
from smnp.library.model import CombinedFunction, Function
from smnp.library.signature import varargSignature, ofTypes, listOf
from smnp.type.model import Type
_signature1 = varargSignature(ofTypes(Type.INTEGER, Type.NOTE), ofTypes(Type.INTEGER))
def _function1(env, value, vararg):
transposed = [Type.note(arg.value.transpose(value.value)) if arg.type == Type.NOTE else arg for arg in vararg]
return Type.list(transposed).decompose()
_signature2 = varargSignature(listOf(Type.INTEGER, Type.NOTE), ofTypes(Type.INTEGER))
def _function2(env, value, vararg):
return Type.list([_function1(env, value, arg.value) for arg in vararg]).decompose()
function = CombinedFunction(
'transpose',
Function(_signature1, _function1),
Function(_signature2, _function2)
)

View File

@@ -0,0 +1,22 @@
from smnp.library.model import CombinedFunction, Function
from smnp.library.signature import signature, listOf, ofTypes, varargSignature
from smnp.type.model import Type
_signature1 = varargSignature(ofTypes(Type.NOTE), ofTypes(Type.INTEGER), ofTypes(Type.INTEGER))
def _function1(env, n, m, vararg):
t = [Type.note(arg.value.withDuration(int(arg.value.duration * n.value / m.value))) for arg in vararg]
return Type.list(t).decompose()
_signature2 = signature(ofTypes(Type.INTEGER), ofTypes(Type.INTEGER), listOf(Type.NOTE))
def _function2(env, n, m, notes):
return _function1(env, n, m, notes.value)
function = CombinedFunction(
'tuplet',
Function(_signature1, _function1),
Function(_signature2, _function2)
)