1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
|
.. SPDX-FileCopyrightText: 2013 Ole Martin Bjorndalen <ombdalen@gmail.com>
..
.. SPDX-License-Identifier: CC-BY-4.0
Meta Message Types
==================
Supported Messages
------------------
sequence_number (0x00)
^^^^^^^^^^^^^^^^^^^^^^
=============== ============ ========
Attribute Values Default
=============== ============ ========
number 0..65535 0
=============== ============ ========
Sequence number in type 0 and 1 MIDI files;
pattern number in type 2 MIDI files.
text (0x01)
^^^^^^^^^^^
============== ============== ========
Attribute Values Default
============== ============== ========
text string ''
============== ============== ========
General "Text" Meta Message. Can be used for any text based data.
copyright (0x02)
^^^^^^^^^^^^^^^^
============== ============== ========
Attribute Values Default
============== ============== ========
text string ''
============== ============== ========
Provides information about a MIDI file's copyright.
track_name (0x03)
^^^^^^^^^^^^^^^^^
============== ============== ========
Attribute Values Default
============== ============== ========
name string ''
============== ============== ========
Stores a MIDI track's name.
instrument_name (0x04)
^^^^^^^^^^^^^^^^^^^^^^
============== ============== ========
Attribute Values Default
============== ============== ========
name string ''
============== ============== ========
Stores an instrument's name.
lyrics (0x05)
^^^^^^^^^^^^^
============== ============== ========
Attribute Values Default
============== ============== ========
text string ''
============== ============== ========
Stores the lyrics of a song. Typically one syllable per Meta Message.
marker (0x06)
^^^^^^^^^^^^^
============== ============== ========
Attribute Values Default
============== ============== ========
text string ''
============== ============== ========
Marks a point of interest in a MIDI file.
Can be used as the marker for the beginning of a verse, solo, etc.
cue_marker (0x07)
^^^^^^^^^^^^^^^^^
============== ============== ========
Attribute Values Default
============== ============== ========
text string ''
============== ============== ========
Marks a cue. IE: 'Cue performer 1', etc
device_name (0x09)
^^^^^^^^^^^^^^^^^^
============== ============== ========
Attribute Values Default
============== ============== ========
name string ''
============== ============== ========
Gives the name of the device.
channel_prefix (0x20)
^^^^^^^^^^^^^^^^^^^^^
============== ============== ========
Attribute Values Default
============== ============== ========
channel 0..255 0
============== ============== ========
Gives the prefix for the channel on which events are played.
midi_port (0x21)
^^^^^^^^^^^^^^^^
============== ============== ========
Attribute Values Default
============== ============== ========
port 0..255 0
============== ============== ========
Gives the MIDI Port on which events are played.
end_of_track (0x2f)
^^^^^^^^^^^^^^^^^^^
============== ============== ========
Attribute Values Default
============== ============== ========
n/a n/a n/a
============== ============== ========
An empty Meta Message that marks the end of a track.
set_tempo (0x51)
^^^^^^^^^^^^^^^^
============== ============== ========
Attribute Values Default
============== ============== ========
tempo 0..16777215 500000
============== ============== ========
Tempo is in microseconds per beat (quarter note). You can use
:py:func:`bpm2tempo` and :py:func:`tempo2bpm` to convert to and from
beats per minute. Note that :py:func:`tempo2bpm` may return a floating
point number.
smpte_offset (0x54)
^^^^^^^^^^^^^^^^^^^
============== ================= ========
Attribute Values Default
============== ================= ========
frame_rate 24, 25, 29.97, 30 24
hours 0..255 0
minutes 0..59 0
seconds 0..59 0
frames 0..255 0
sub_frames 0..99 0
============== ================= ========
time_signature (0x58)
^^^^^^^^^^^^^^^^^^^^^
============================ =============== ========
Attribute Values Default
============================ =============== ========
numerator 0..255 4
denominator 1..2**255 4
clocks_per_click 0..255 24
notated_32nd_notes_per_beat 0..255 8
============================ =============== ========
Time signature of:
4/4 : MetaMessage('time_signature', numerator=4, denominator=4)
3/8 : MetaMessage('time_signature', numerator=3, denominator=8)
.. versionadded:: 1.2.9
Time signature message have the correct default value of 4/4. In earlier
versions the default value was 2/4 due to a typo in the code.
key_signature (0x59)
^^^^^^^^^^^^^^^^^^^^
========= ================== ========
Attribute Values Default
========= ================== ========
key 'C', 'F#m', ... 'C'
========= ================== ========
Valid values: A A#m Ab Abm Am B Bb Bbm Bm C C# C#m Cb Cm D D#m Db Dm E
Eb Ebm Em F F# F#m Fm G G#m Gb Gm
.. versionchanged:: 1.1.5
The mode attribute was removed. Instead, an 'm' is appended to minor keys.
sequencer_specific (0x7f)
^^^^^^^^^^^^^^^^^^^^^^^^^
============== ============== ========
Attribute Values Default
============== ============== ========
data [..] []
============== ============== ========
An unprocessed sequencer specific message containing raw data.
Unknown Meta Messages
---------------------
Unknown meta messages will be returned as ``UnknownMetaMessage``
objects, with ``type`` set to ``unknown_meta``. The messages are saved
back to the file exactly as they came out.
Code that depends on ``UnknownMetaMessage`` may break if the message
in question is ever implemented, so it's best to only use these to
learn about the format of the new message and then implement it as
described below.
``UnknownMetaMessage`` have two attributes:
* ``type_byte`` - a byte which uniquely identifies this message type
* ``data`` - the message data as a list of bytes
These are also visible in the ``repr()`` string::
UnknownMetaMessage(type_byte=251, data=(1, 2, 3), time=0)
Implementing New or Custom Meta Messages
----------------------------------------
If you come across a meta message which is not implemented or you
want to use a custom meta message, you can add it by writing a new
meta message spec::
from mido.midifiles.meta import MetaSpec, add_meta_spec
class MetaSpec_light_color(MetaSpec):
type_byte = 0xf0
attributes = ['r', 'g', 'b']
defaults = [0, 0, 0]
def decode(self, message, data):
# Interpret the data bytes and assign them to attributes.
(message.r, message.g, message.b) = data
def encode(self, message):
# Encode attributes to data bytes and
# return them as a list of ints.
return [message.r, message.g, message.b]
def check(self, name, value):
# (Optional)
# This is called when the user assigns
# to an attribute. You can use this for
# type and value checking. (Name checking
# is already done.
#
# If this method is left out, no type and
# value checking will be done.
if not isinstance(value, int):
raise TypeError('{} must be an integer'.format(name))
if not 0 <= value <= 255:
raise TypeError('{} must be in range 0..255'.format(name))
Then you can add your new message type with::
add_meta_spec(MetaSpec_light_color)
and create messages in the usual way::
>>> from mido import MetaMessage
>>> MetaMessage('light_color', r=120, g=60, b=10)
MetaMessage('light_color', r=120, g=60, b=10, time=0)
and the new message type will now work when reading and writing MIDI
files.
Some additional functions are available::
encode_string(unicode_string)
decode_string(byte_list)
These convert between a Unicode string and a list of bytes using the
current character set in the file.
If your message contains only one string with the attribute name
``text`` or ``name``, you can subclass from one of the existing
messages with these attributes, for example::
class MetaSpec_copyright(MetaSpec_text):
type_byte = 0x02
class MetaSpec_instrument_name(MetaSpec_track_name):
type_byte = 0x04
This allows you to skip everything but ``type_byte``, since the rest
is inherited.
See the existing ``MetaSpec`` classes for further examples.
|