def test_delete_reorders_presets(client): p1 = Preset.create(name='p1') Preset.create(name='p2') p3 = Preset.create(name='p3') rv = client.delete('/api/presets/2') assert rv.status_code == 204 assert Preset.select().count() == 2 assert Preset.get(Preset.id == p1.id).number == 1 assert Preset.get(Preset.id == p3.id).number == 2
def test_order_presets(client): Preset.create(name='p1') Preset.create(name='p2') Preset.create(name='p3') order = [3, 1, 2] rv = client.post('/api/presets/order', data=json.dumps({'order': order}), content_type='application/json') assert rv.status_code == 200 assert rjson(rv) == {'order': order} assert Preset.get(Preset.id == 3).number == 1 assert Preset.get(Preset.id == 1).number == 2 assert Preset.get(Preset.id == 2).number == 3
def load_preset(self, evt): preset_number = int(evt.value) try: preset = Preset.get(Preset.number == preset_number) except Preset.DoesNotExist: return with self.menu.lock_state(f'Loading preset {preset.number}...'): self.state.load_preset(preset.id)
def load_prev_preset(self, evt, wrap=False): number = self.state.last_preset_number - 1 try: preset = Preset.get(Preset.number == number) except Preset.DoesNotExist: if not wrap: return try: preset = Preset.select().order_by(Preset.number.desc()).get() except Preset.DoesNotExist: return with self.menu.lock_state(f'Loading preset {preset.number}...'): self.state.load_preset(preset.id)
def load_preset(self, preset_id, preload=False): try: preset = Preset.get(Preset.id == int(preset_id)) except Preset.DoesNotExist: log.error('Preset {} not found!'.format(preset_id)) return with self.lock(): with signals.suppress(): self.from_preset_dict(preset.get_data()) self.preset.id = preset_id if preload: signals.emit('active:preset:preload') signals.emit('active:preset:changed') self.last_preset_number = preset.number
def save_preset(self, name=None, preset_id=None): if preset_id is not None: try: preset = Preset.get(Preset.id == int(preset_id)) except Preset.DoesNotExist: log.error('Preset {} not found!'.format(preset_id)) return if name is not None: preset.name = name else: preset = Preset() preset.name = name or 'Unnamed' preset.set_data(self.to_preset_dict()) preset.save() signals.emit('preset:changed', {'id': preset.id})
def test_save_and_load_state_as_preset(db, menu): assert Preset.select().count() == 0 menu.state.clear() menu.state.preset.melody[0].soundfont_id = 'mg.sf2' menu.state.preset.melody[0].bank = 1 menu.state.preset.melody[0].prog = 2 menu.state.save_preset() assert Preset.select().count() == 1 preset = Preset.get() assert preset.name == 'Unnamed' assert preset.number == 1 menu.state.clear() menu.state.load_preset(preset.id) assert menu.state.preset.melody[0].soundfont_id == 'mg.sf2' assert menu.state.preset.melody[0].bank == 1 assert menu.state.preset.melody[0].prog == 2