How to use the mido.messages.get_spec function in mido

To help you get started, we’ve selected a few mido examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mido / mido / mido / test_messages.py View on Github external
def test_get_spec():
    from .messages import get_spec

    assert get_spec('note_on').type == 'note_on'
    assert get_spec(0x80).type == 'note_off'
    assert get_spec(0x82).type == 'note_off'

    with raises(LookupError): get_spec(-1)
    with raises(LookupError): get_spec(0)
    with raises(LookupError): get_spec('banana')
github mido / mido / mido / test_messages.py View on Github external
def test_copy_invalid_attribute():
    orig = Message('note_on')
    valid_spec = get_spec('note_on')

    # Pass arguments with invalid names.
    with raises(ValueError): orig.copy(_spec=valid_spec)
    with raises(ValueError): orig.copy(type='continue')
    with raises(ValueError): orig.copy(banana=1)

    # Valid arguments should pass.
    orig.copy(note=0, velocity=0, time=0)
github mido / mido / mido / test_messages.py View on Github external
def test_get_spec():
    from .messages import get_spec

    assert get_spec('note_on').type == 'note_on'
    assert get_spec(0x80).type == 'note_off'
    assert get_spec(0x82).type == 'note_off'

    with raises(LookupError): get_spec(-1)
    with raises(LookupError): get_spec(0)
    with raises(LookupError): get_spec('banana')
github mido / mido / mido / test_messages.py View on Github external
def test_get_spec():
    from .messages import get_spec

    assert get_spec('note_on').type == 'note_on'
    assert get_spec(0x80).type == 'note_off'
    assert get_spec(0x82).type == 'note_off'

    with raises(LookupError): get_spec(-1)
    with raises(LookupError): get_spec(0)
    with raises(LookupError): get_spec('banana')
github mido / mido / mido / test_messages.py View on Github external
def test_set_invalid_attribute():
    """Set an attribute that is not settable."""
    valid_spec = get_spec('note_on')
    msg = Message('note_on')

    with raises(AttributeError): msg._spec = valid_spec
    with raises(AttributeError): msg.type = 'continue'
    with raises(AttributeError): msg.invalid = 'banana'
github mido / mido / mido / test_messages.py View on Github external
def test_get_spec():
    from .messages import get_spec

    assert get_spec('note_on').type == 'note_on'
    assert get_spec(0x80).type == 'note_off'
    assert get_spec(0x82).type == 'note_off'

    with raises(LookupError): get_spec(-1)
    with raises(LookupError): get_spec(0)
    with raises(LookupError): get_spec('banana')
github mido / mido / mido / test_messages.py View on Github external
def test_get_spec():
    from .messages import get_spec

    assert get_spec('note_on').type == 'note_on'
    assert get_spec(0x80).type == 'note_off'
    assert get_spec(0x82).type == 'note_off'

    with raises(LookupError): get_spec(-1)
    with raises(LookupError): get_spec(0)
    with raises(LookupError): get_spec('banana')
github mido / mido / tests.py View on Github external
def test_get_spec(self):
        get_spec = mido.messages.get_spec

        self.assertTrue(get_spec('note_on').type == 'note_on')
        self.assertTrue(get_spec(0x80).type == 'note_off')
        self.assertTrue(get_spec(0x82).type == 'note_off')

        self.assertRaises(LookupError, get_spec, 0)
github mido / mido / mido / midifiles.py View on Github external
def _read_message(self, status_byte):
        try:
            spec = get_spec(status_byte)
        except LookupError:
            raise IOError('undefined status byte 0x{:02x}'.format(status_byte))
        data_bytes = self._file.read_list(spec.length - 1)
        for byte in data_bytes:
            if byte > 127:
                raise IOError('data byte must be in range 0..127')
        return build_message(spec, [status_byte] + data_bytes)