Skip to content

Commit

Permalink
Merge pull request #28 from PedalPi/issue-19-xrun-callback
Browse files Browse the repository at this point in the history
Issue 19 xrun callback
  • Loading branch information
SrMouraSilva committed May 17, 2017
2 parents e4cf9a4 + ebe18b7 commit ac12026
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Version 0.4.0 -- released 05//17
- Remove deprecated files (mod-host auto connect)
- Issue #23 - Add method for secure close in mod-host
- Issue #22 - Fastest load pedalboard
- Issue #19 - x-run callback. Create `pluginsmanager.jack.jack_client.JackClient`

Version 0.3.2 -- released 05/12/17
==================================
Expand Down
13 changes: 13 additions & 0 deletions pluginsmanager/jack/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2017 SrMouraSilva
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
60 changes: 60 additions & 0 deletions pluginsmanager/jack/jack_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2017 SrMouraSilva
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import jack


class JackClient(object):
"""
Based in: http://jackclient-python.readthedocs.io/en/0.4.2/examples.html#chatty-client
Through the :class:`JackClient` it is possible to be notified when `x-run`
occurs and when the Jack server is closed::
>>> client = JackClient()
>>> client.xrun_callback = lambda delay: print('x-run', delay)
>>> client.shutdown_callback = lambda status, reason: print('shutdown: ', status, reason)
:param bool no_start_server: False if starts a new JACK server
True if uses a already started jack (ex: using `jackdump`)
:param name: Jack client name. Default: `JackClient`
"""
def __init__(self, no_start_server=True, name=None):
if name is None:
name = self.__class__.__name__

self.client = jack.Client(name=name, no_start_server=no_start_server)

self.xrun_callback = lambda delay: ...
self.shutdown_callback = lambda status, reason: ...

if self.client.status.server_started:
logging.info('JACK server was started')
else:
logging.info('JACK server was already running')

if self.client.status.name_not_unique:
logging.info('Unique client name generated {}'.format(self.client.name))

@self.client.set_xrun_callback
def xrun(delay):
self.xrun_callback(delay)

@self.client.set_shutdown_callback
def shutdown(status, reason):
self.shutdown_callback(status, reason)

self.client.activate()

11 changes: 6 additions & 5 deletions pluginsmanager/model/system/system_effect_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import jack

from pluginsmanager.model.system.system_effect import SystemEffect


class SystemEffectBuilder(object):
"""
Automatic system physical ports detection
:param JackClient jack_client: :class:`JackClient` instance that will get the information to
generate :class:`SystemEffect`
"""
def __init__(self, no_start_server=True):
self.client = jack.Client("SystemEffectBuilder", no_start_server=no_start_server)
def __init__(self, jack_client):
self.client = jack_client

def build(self):
inputs = []
outputs = []

for port in self.client.get_ports(is_audio=True, is_physical=True):
for port in self.client.client.get_ports(is_audio=True, is_physical=True):
if port.is_input:
inputs.append(port.shortname)
else:
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def readme():

packages=[
'pluginsmanager',
'pluginsmanager/jack',

'pluginsmanager/mod_host',
'pluginsmanager/model',
Expand Down

0 comments on commit ac12026

Please sign in to comment.