An open source DAW for GNU/Linux, inspired by modular synths.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.2 KiB

# @begin:license
# Copyright (c) 2015-2019, Benjamin Niemann <>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# @end:license
from libc.stdint cimport uint8_t
from noisicaa.core.status cimport check
from noisicaa.host_system.host_system cimport PyHostSystem
from . cimport block_context
from . cimport buffers
_UNSET = object()
cdef class PyBackendSettings(object):
def __init__(
self, *,
datastream_address=_UNSET, time_scale=1.0):
if datastream_address is not _UNSET:
self.datastream_address = datastream_address
if time_scale is not _UNSET:
self.time_scale = time_scale
cdef BackendSettings get(self):
return self.__settings
def datastream_address(self):
return bytes(self.__settings.datastream_address).decode('utf-8')
def datastream_address(self, value):
self.__settings.datastream_address = value.encode('utf-8')
def time_scale(self):
return float(self.__settings.time_scale)
def time_scale(self, value):
self.__settings.time_scale = <float>value
cdef class PyBackend(object):
def __init__(self, PyHostSystem host_system, name, PyBackendSettings settings):
if isinstance(name, str):
name = name.encode('ascii')
assert isinstance(name, bytes)
cdef StatusOr[Backend*] backend = Backend.create(host_system.get(), name, settings.get())
self.__backend = self.__backend_ptr.get()
cdef Backend* get(self) nogil:
return self.__backend
def setup(self, PyRealm realm):
cdef Realm* c_realm = realm.get()
with nogil:
def cleanup(self):
# Only do cleanup, when we still own the backend.
cdef Backend* backend = self.__backend_ptr.get()
if backend != NULL:
with nogil:
def begin_block(self, block_context.PyBlockContext ctxt):
with nogil:
def end_block(self, block_context.PyBlockContext ctxt):
with nogil:
def output(self, block_context.PyBlockContext ctxt, str channel, float[:] samples):
cdef buffers.BufferPtr c_samples = <BufferPtr>&samples[0]
cdef string c_channel = channel.encode('utf-8')
with nogil:
check(self.__backend.output(ctxt.get(), c_channel, c_samples))