Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor changes and additions #29

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/example_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def on_peer_connected(self, peer):
def on_peer_disconnected(self, peer):
self.logger.info('Peer disconnected: {}'.format(peer))

def on_midi_commands(self, peer, command_list):
def on_midi_commands(self, peer, command_list, journal):
Brettles marked this conversation as resolved.
Show resolved Hide resolved
for command in command_list:
if command.command == 'note_on':
key = command.params.key
Expand Down
31 changes: 16 additions & 15 deletions pymidi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,22 @@ def _send_note(self, notestr, command, velocity=80, channel=1):
self._send_rtp_command(command)

def _send_rtp_command(self, command):
header = packets.MIDIPacketHeader.create(
rtp_header={
'flags': {
'v': 0x2,
'p': 0,
'x': 0,
'cc': 0,
'm': 0x1,
'pt': 0x61,
},
'sequence_number': ord('K'),
},
timestamp=int(time.time()),
ssrc=self.ssrc,
)
# Does not seem to be used anywhere - removing for possible performnace gain
Brettles marked this conversation as resolved.
Show resolved Hide resolved
# header = packets.MIDIPacketHeader.create(
# rtp_header={
# 'flags': {
# 'v': 0x2,
# 'p': 0,
# 'x': 0,
# 'cc': 0,
# 'm': 0x1,
# 'pt': 0x61,
# },
# 'sequence_number': ord('K'),
# },
# timestamp=int(time.time()),
# ssrc=self.ssrc,
# )

packet = packets.MIDIPacket.create(
header={
Expand Down
10 changes: 10 additions & 0 deletions pymidi/packets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
COMMAND_NOTE_ON = 0x90
COMMAND_AFTERTOUCH = 0xA0
COMMAND_CONTROL_MODE_CHANGE = 0xB0
COMMAND_PITCH_BEND_CHANGE = 0xE0


def to_string(pkt):
Expand All @@ -31,6 +32,10 @@ def to_string(pkt):
items.append(
'{} {} {}'.format(command, entry.params.controller, entry.params.value)
)
elif command == 'aftertouch':
items.append('{} {} {}'.format(command, entry.params.key, entry.params.touch))
elif command == 'pitch_bend_change':
items.append('{} {} {}'.format(command, entry.params.lsb, entry.params.msb))
else:
items.append(command)
detail = ' '.join(('[{}]'.format(i) for i in items))
Expand Down Expand Up @@ -270,6 +275,7 @@ def create(self, **kwargs):
note_off=COMMAND_NOTE_OFF,
aftertouch=COMMAND_AFTERTOUCH,
control_mode_change=COMMAND_CONTROL_MODE_CHANGE,
pitch_bend_change=COMMAND_PITCH_BEND_CHANGE
),
),
'channel' / If(_this.command_byte, Computed(_this.command_byte & 0x0F)),
Expand All @@ -293,6 +299,10 @@ def create(self, **kwargs):
'controller' / Int8ub,
'value' / Int8ub,
),
'pitch_bend_change': Struct(
'lsb' / Int8ub,
'msb' / Int8ub,
),
},
default=Struct(
'unknown' / GreedyBytes,
Expand Down
3 changes: 3 additions & 0 deletions pymidi/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,6 @@ def handle_timestamp(self, data, addr):
elif packet.count == 2:
offset_estimate = ((packet.timestamp_3 + packet.timestamp_1) / 2) - packet.timestamp_2
self.logger.debug('offset estimate: {}'.format(offset_estimate))

latency = (packet.timestamp_3-packet.timestamp_1)/10
self.logger.info('Peer {} latency: {}ms'.format(self.peers_by_ssrc[packet.ssrc].name,latency))
4 changes: 2 additions & 2 deletions pymidi/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def on_peer_connected(self, peer):
def on_peer_disconnected(self, peer):
pass

def on_midi_commands(self, peer, command_list):
def on_midi_commands(self, peer, command_list, journal):
pass


Expand Down Expand Up @@ -77,7 +77,7 @@ def _peer_disconnected_cb(self, peer):
def _midi_command_cb(self, peer, midi_packet):
commands = midi_packet.command.midi_list
for handler in self.handlers:
handler.on_midi_commands(peer, commands)
handler.on_midi_commands(peer, commands, midi_packet.journal)

def _build_control_protocol(self, host, port, family):
logger.info('Control socket on {}:{}'.format(host, port))
Expand Down