File: printer.py

package info (click to toggle)
python-mido 1.3.3-0.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 920 kB
  • sloc: python: 4,006; makefile: 127; sh: 4
file content (28 lines) | stat: -rw-r--r-- 676 bytes parent folder | download
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
# SPDX-FileCopyrightText: 2013 Ole Martin Bjorndalen <ombdalen@gmail.com>
#
# SPDX-License-Identifier: MIT

"""
A simple custom backend with an output port type which prints messages
to stdout.
"""
from mido.ports import BaseOutput


def get_devices():
    return [{'name': 'The Print Port',
             'is_input': False,
             'is_output': True}]


class Output(BaseOutput):
    def _open(self, **kwargs):
        device = get_devices()[0]

        if self.name is None:
            self.name = device['name']
        elif self.name != device['name']:
            raise ValueError(f'unknown port {self.name!r}')

    def _send(self, message):
        print(message)