60 lines
No EOL
1.1 KiB
Python
60 lines
No EOL
1.1 KiB
Python
import math
|
|
|
|
from ..soundnode import SoundNode
|
|
from ..actions import TimedAction
|
|
|
|
class SineNode(SoundNode):
|
|
|
|
def __init__(self, freqs, room):
|
|
|
|
super().__init__("sine", room)
|
|
self.freqs = freqs
|
|
self.active = False
|
|
self.volume = 1
|
|
|
|
def calc_r_amps(self, t):
|
|
|
|
if not self.active:
|
|
self.r_amps[t] = dict()
|
|
return
|
|
|
|
tdct = dict()
|
|
|
|
for freq in self.freqs:
|
|
tdct[freq] = self.volume * math.sin(self.room.sine_multiplier * freq * t)
|
|
|
|
self.r_amps[t] = tdct
|
|
|
|
###
|
|
|
|
class PlayAction(TimedAction):
|
|
|
|
def __init__(self, start_t, duration_t, nodes, program):
|
|
|
|
super().__init__(start_t, duration_t, nodes, program)
|
|
|
|
def start(self, node):
|
|
|
|
node.active = True
|
|
|
|
def end(self, node):
|
|
|
|
node.active = False
|
|
|
|
|
|
class NoteAction(TimedAction):
|
|
|
|
def __init__(self, note, start_t, duration_t, nodes, program):
|
|
|
|
super().__init__(start_t, duration_t, nodes, program)
|
|
self.note = note
|
|
|
|
def start(self, node):
|
|
|
|
note_freq = self.program.note_to_freq(self.note)
|
|
node.freqs = [note_freq]
|
|
node.active = True
|
|
|
|
def end(self, node):
|
|
|
|
node.active = False |