Move 'note' module
This commit is contained in:
0
smnp/module/note/function/__init__.py
Normal file
0
smnp/module/note/function/__init__.py
Normal file
11
smnp/module/note/function/duration.py
Normal file
11
smnp/module/note/function/duration.py
Normal 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')
|
||||
11
smnp/module/note/function/octave.py
Normal file
11
smnp/module/note/function/octave.py
Normal 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')
|
||||
13
smnp/module/note/function/pause.py
Normal file
13
smnp/module/note/function/pause.py
Normal 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')
|
||||
24
smnp/module/note/function/semitones.py
Normal file
24
smnp/module/note/function/semitones.py
Normal 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),
|
||||
)
|
||||
21
smnp/module/note/function/transpose.py
Normal file
21
smnp/module/note/function/transpose.py
Normal 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)
|
||||
)
|
||||
22
smnp/module/note/function/tuplet.py
Normal file
22
smnp/module/note/function/tuplet.py
Normal 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)
|
||||
)
|
||||
Reference in New Issue
Block a user