Skip to content
Snippets Groups Projects
Verified Commit ba91539e authored by dos's avatar dos
Browse files

sim: fakes: Basic bl00mbox sampler implementation using pygame

parent c3596934
No related branches found
No related tags found
No related merge requests found
...@@ -735,9 +735,8 @@ Currently the simulator supports the display, LEDs, the buttons, accelerometer ...@@ -735,9 +735,8 @@ Currently the simulator supports the display, LEDs, the buttons, accelerometer
(in 2D) and some static input values from the gyroscope, temperature sensor and (in 2D) and some static input values from the gyroscope, temperature sensor and
pressure sensor. pressure sensor.
It does **not** support any audio API, and in fact currently doesn't even stub It does **not** support most of the audio APIs. It also does not support
out the relevant API methods, so it will crash when attempting to run any Music positional captouch APIs.
app. It also does not support positional captouch APIs.
To set the simulator up, clone the repository and prepare a Python virtual To set the simulator up, clone the repository and prepare a Python virtual
environment with the required packages: environment with the required packages:
......
class tinysynth: import pygame
def __init__(self, a): from _sim import path_replace
pass
def decay_ms(self, a):
pass
def decay(self, a): class _mock(list):
def __init__(self, *args, **kwargs):
pass pass
def waveform(self, a): def __getattr__(self, attr):
if attr in ["tone", "value"]:
return 0
if attr in ["trigger_state"]:
return lambda *args: 0
return _mock()
def __call__(self, *args, **kwargs):
return _mock()
class Channel:
def __init__(self, id):
pass pass
def tone(self, note): def new(self, a, *args, **kwargs):
return a(self, *args, **kwargs)
def clear(self):
pass pass
mixer = None
channel_num = 0
volume = 8000
class _patches(_mock):
class sampler(_mock):
class Signals(_mock):
class Trigger(_mock):
def __init__(self, sampler):
self._sampler = sampler
def start(self): def start(self):
pass self._sampler._sound.set_volume(
self._sampler._channel.volume / 32767
)
self._sampler._sound.play()
def sustain(self, a): def __init__(self, sampler):
pass self._sampler = sampler
self._trigger = patches.sampler.Signals.Trigger(sampler)
def attack_ms(self, a): @property
pass def trigger(self):
return self._trigger
def release_ms(self, a): @trigger.setter
def trigger(self, val):
pass pass
def volume(self, a): def _convert_filename(self, filename):
pass if filename.startswith("/flash/") or filename.startswith("/sd/"):
return filename
elif filename.startswith("/"):
return "/flash/" + filename
else:
return "/flash/sys/samples/" + filename
def stop(self): def __init__(self, channel, path):
pass if type(path) == int:
self._signals = _mock()
return
self._sound = pygame.mixer.Sound(path_replace(self._convert_filename(path)))
self._signals = patches.sampler.Signals(self)
self._channel = channel
@property
def signals(self):
return self._signals
class Channel:
def __init__(self, id):
pass
def clear(self): class _helpers(_mock):
pass def sct_to_note_name(self, sct):
sct = sct - 18367 + 100
octave = ((sct + 9 * 200) // 2400) + 4
tones = ["A", "Bb", "B", "C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab"]
tone = tones[(sct // 200) % 12]
return tone + str(octave)
def note_name_to_sct(self, name):
tones = ["A", "Bb", "B", "C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab"]
semitones = tones.index(name[0])
if semitones > 2:
semitones -= 12
if name[1] == "b":
octave = int(name[2:])
semitones -= 1
elif name[1] == "#":
octave = int(name[2:])
semitones += 1
else:
octave = int(name[1:])
return 18367 + (octave - 4) * 2400 + (200 * semitones)
def sct_to_freq(sct):
return 440 * 2 ** ((sct - 18367) / 2400)
plugins = _mock()
patches = _patches()
helpers = _helpers()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment