FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-rtmidi/examples/basic/midiin_callback.py at master · ritterb8484/python-rtmidi · GitHub
ritterb8484
/
python-rtmidi
Public
forked from
SpotlightKid/python-rtmidi
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-rtmidi
/
examples
/
basic
/
midiin_callback.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
54 lines (42 loc) · 1.33 KB
Breadcrumbs
python-rtmidi
/
examples
/
basic
/
midiin_callback.py
Copy path
File metadata and controls
executable file
·
54 lines (42 loc) · 1.33 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!/usr/bin/env python
#
# midiin_callback.py
#
"""Show how to receive MIDI input by setting a callback function."""
from
__future__
import
print_function
import
logging
import
sys
import
time
from
rtmidi
.
midiutil
import
open_midiinput
log
=
logging
.
getLogger
(
'midiin_callback'
)
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
class
MidiInputHandler
(
object
):
def
__init__
(
self
,
port
):
self
.
port
=
port
self
.
_wallclock
=
time
.
time
()
def
__call__
(
self
,
event
,
data
=
None
):
message
,
deltatime
=
event
self
.
_wallclock
+=
deltatime
print
(
"[%s] @%0.6f %r"
%
(
self
.
port
,
self
.
_wallclock
,
message
))
# Prompts user for MIDI input port, unless a valid port number or name
# is given as the first argument on the command line.
# API backend defaults to ALSA on Linux.
port
=
sys
.
argv
[
1
]
if
len
(
sys
.
argv
)
>
1
else
None
try
:
midiin
,
port_name
=
open_midiinput
(
port
)
except
(
EOFError
,
KeyboardInterrupt
):
sys
.
exit
()
print
(
"Attaching MIDI input callback handler."
)
midiin
.
set_callback
(
MidiInputHandler
(
port_name
))
print
(
"Entering main loop. Press Control-C to exit."
)
try
:
# Just wait for keyboard interrupt,
# everything else is handled via the input callback.
while
True
:
time
.
sleep
(
1
)
except
KeyboardInterrupt
:
print
(
''
)
finally
:
print
(
"Exit."
)
midiin
.
close_port
()
del
midiin
Back
|
FazBrowse Home
|
New Git URL