import os
import math
import sounddevice as sd
+import logging
class Config:
pass
default="config.yml",
required=False,
help="Config file to load")
+ parser.add_argument("-d", "--debug",
+ nargs=0,
+ action=DebugModeAction,
+ help="Print messages in console")
parser.add_argument("-m", "--builtin-mixing",
action="store_true",
help="Make the mixing of sounds manually (do it if the system cannot handle it correctly)")
parser.add_argument('--',
dest="args",
help="Kivy arguments. All arguments after this are interpreted by Kivy. Pass \"-- --help\" to get Kivy's usage.")
+
+ from kivy.logger import Logger
+ Logger.setLevel(logging.ERROR)
+
args = parser.parse_args(argv)
Config.yml_file = args.config
+
Config.latency = args.latency
Config.blocksize = args.blocksize
Config.frame_rate = args.frame_rate
Config.sample_width = args.sample_width
Config.builtin_mixing = args.builtin_mixing
+class DebugModeAction(argparse.Action):
+ def __call__(self, parser, namespace, values, option_string=None):
+ from kivy.logger import Logger
+ Logger.setLevel(logging.DEBUG)
+
class SelectDeviceAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
sd.default.device = values
else:
return [20 * math.log10(max(volume, 0.1) / max(old_volume, 0.1)), max(volume, 0)]
+def debug_print(message):
+ from kivy.logger import Logger
+ Logger.debug('MusicSampler: ' + message)
+
+def error_print(message):
+ from kivy.logger import Logger
+ Logger.error('MusicSampler: ' + message)
import threading
import time
+from . import debug_print
+
class Action:
action_types = [
'command',
return True
def run(self):
- print(self.description())
+ debug_print(self.description())
getattr(self, self.action)(**self.arguments)
def description(self):
from kivy.uix.behaviors import ButtonBehavior
from .action import *
+from . import debug_print
import time
class Key(ButtonBehavior, Widget):
return None
self.parent.parent.ids['KeyList'].append(self.key_sym)
- print("running actions for {}".format(self.key_sym))
+ debug_print("running actions for {}".format(self.key_sym))
start_time = time.time()
self.parent.start_running(self, start_time)
action_number = 0
import threading
+from . import debug_print
+
class Lock:
def __init__(self, lock_type):
self.type = lock_type
self.release(*args, **kwargs)
def acquire(self, *args, **kwargs):
- #print("acquiring lock for {}".format(self.type))
+ #debug_print("acquiring lock for {}".format(self.type))
self.lock.acquire(*args, **kwargs)
def release(self, *args, **kwargs):
- #print("releasing lock for {}".format(self.type))
+ #debug_print("releasing lock for {}".format(self.type))
self.lock.release(*args, **kwargs)
import os.path
from .lock import Lock
-from . import Config, gain
+from . import Config, gain, debug_print, error_print
from .mixer import Mixer
file_lock = Lock("file")
Machine.__init__(self, states=states, transitions=transitions, initial='initial')
- # FIXME: catch error here
- self.mixer = mapping.mixer or Mixer()
self.volume = 100
self.mapping = mapping
self.filename = filename
def on_enter_loading(self):
with file_lock:
try:
- print("Loading « {} »".format(self.name))
+ debug_print("Loading « {} »".format(self.name))
+ self.mixer = self.mapping.mixer or Mixer()
db_gain = gain(self.volume_factor * 100)
self.audio_segment = pydub.AudioSegment.from_file(self.filename).set_frame_rate(Config.frame_rate).set_channels(Config.channels).set_sample_width(Config.sample_width).apply_gain(db_gain)
self.audio_segment_frame_width = self.audio_segment.frame_width
self.sound_duration = self.audio_segment.duration_seconds
except Exception as e:
- print("failed to load « {} »: {}".format(self.name, e))
+ error_print("failed to load « {} »: {}".format(self.name, e))
self.loading_error = e
self.fail()
else:
self.success()
- print("Loaded « {} »".format(self.name))
+ debug_print("Loaded « {} »".format(self.name))
def check_is_loaded(self):
return self.state.startswith('loaded_')