Beispiel #1
0
def test_delete_preset(client):
    Preset.create(name='p1')

    assert Preset.select().count() == 1

    rv = client.delete('/api/presets/1')

    assert rv.status_code == 204
    assert Preset.select().count() == 0
Beispiel #2
0
def test_create_preset(client):
    assert len(Preset.select()) == 0

    data = {
        'name': 'p1',
        'voices': {
            'melody': [{
                'soundfont': 'test',
                'bank': 0,
                'program': 0,
                'note': 60,
                'polyphonic': False,
                'muted': False,
                'capo': 1,
                'volume': 2,
                'panning': 0,
                'mode': 'midigurdy',
                'finetune': 0,
                'chien_threshold': 50,
            }, {
                'soundfont': 'test',
                'bank': 0,
                'program': 1,
                'note': 61,
                'polyphonic': False,
                'muted': False,
                'capo': 2,
                'volume': 3,
                'panning': 100,
                'mode': 'keyboard',
                'finetune': 0,
                'chien_threshold': 50,
            }],
            'drone': [],
            'trompette': [],
        },
    }

    rv = client.post('/api/presets',
                     data=json.dumps(data),
                     content_type='application/json')

    expected = dict(data)
    expected['id'] = 1
    expected['number'] = 1

    assert rv.status_code == 201
    assert rjson(rv) == expected
    assert len(Preset.select(Preset.id == 1)) == 1
Beispiel #3
0
 def load_presets(self):
     presets = list(Preset.select())
     cursor = None
     for idx, preset in enumerate(presets):
         if preset.id == self.preset.id:
             cursor = idx
     self.set_items(presets)
     self.cursor = cursor
     self.highlight = cursor
     self.update_window()
Beispiel #4
0
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
Beispiel #5
0
 def preload_presets(self):
     mgcore.halt_outputs()
     try:
         current_id = self.preset.id
         for preset in Preset.select().order_by(Preset.number):
             self.load_preset(preset.id, preload=True)
         self.load_preset(current_id)
         self.presets_preloaded = True
     except RuntimeError:
         raise
     finally:
         mgcore.resume_outputs()
Beispiel #6
0
 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)
Beispiel #7
0
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
Beispiel #8
0
def test_create_preset_checks_max_voice_len(client):
    voice = {
        'soundfont': 'test.sf2',
        'bank': 0,
        'program': 1,
        'note': 60,
        'polyphonic': False,
        'muted': False,
        'capo': 1,
        'volume': 2,
        'panning': 0,
        'finetune': 0,
        'chien_threshold': 50,
    }
    data = {
        'name': 'p1',
        'voices': {
            'melody': [voice, voice, voice, voice],
            'drone': [voice, voice, voice, voice],
            'trompette': [voice, voice, voice, voice],
        },
    }

    rv = client.post('/api/presets',
                     data=json.dumps(data),
                     content_type='application/json')

    expected = {
        'errors': {
            'voices': {
                'trompette': ['Longer than maximum length 3.'],
                'drone': ['Longer than maximum length 3.'],
                'melody': ['Longer than maximum length 3.']
            }
        }
    }

    assert rv.status_code == 400
    assert rjson(rv) == expected
    assert Preset.select().count() == 0
Beispiel #9
0
 def load_presets(self):
     presets = list(Preset.select())
     presets.append(Preset(name='New Preset' + chr(127)))  # placeholder for 'new preset'
     self.set_items(presets)
Beispiel #10
0
def test_update_preset(client):
    p = Preset(name='p1')
    p.set_data({
        'voices': {
            'melody': [{
                'soundfont': 'test',
            }],
            'drone': [{
                'soundfont': 'test',
                'program': 1,
                'note': 61,
            }],
        }
    })
    p.save()

    assert Preset.select().count() == 1

    data = {
        'id': 1,
        'name': 'p1-updated',
        'voices': {
            'melody': [{
                'soundfont': 'test',
                'bank': 1,
                'program': 0,
                'note': 12,
                'polyphonic': True,
                'muted': True,
                'capo': 12,
                'volume': 20,
                'panning': 0,
                'mode': 'midigurdy',
                'finetune': 0,
                'chien_threshold': 50,
            }, {
                'soundfont': 'test',
                'bank': 1,
                'program': 1,
                'note': 1,
                'polyphonic': False,
                'muted': True,
                'capo': 6,
                'volume': 100,
                'panning': 0,
                'mode': 'midigurdy',
                'finetune': 0,
                'chien_threshold': 50,
            }],
            'drone': [],
            'trompette': [],
        },
    }

    rv = client.put('/api/presets/1',
                    data=json.dumps(data),
                    content_type='application/json')

    expected = data
    expected['number'] = 1

    assert rjson(rv) == expected
    assert rv.status_code == 200
    assert Preset.select().count() == 1
Beispiel #11
0
 def post(self):
     order = request.get_json()['order']
     Preset.reorder(order)
     signals.emit('preset:reordered', {'order': order})
     return {'order': [p.id for p in Preset.select(Preset.id)]}
Beispiel #12
0
 def get(self):
     return [preset.to_dict() for preset in Preset.select()]