To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / JackDevice / ContextJack.h @ 1:b5bcad8e7803
History | View | Annotate | Download (3.59 KB)
| 1 | 1:b5bcad8e7803 | f | /*
|
|---|---|---|---|
| 2 | Copyright (c) 2015, The Cinder Project
|
||
| 3 | |||
| 4 | This code is intended to be used with the Cinder C++ library, http://libcinder.org
|
||
| 5 | |||
| 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that
|
||
| 7 | the following conditions are met:
|
||
| 8 | |||
| 9 | * Redistributions of source code must retain the above copyright notice, this list of conditions and
|
||
| 10 | the following disclaimer.
|
||
| 11 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||
| 12 | the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||
| 13 | |||
| 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
||
| 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||
| 16 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||
| 17 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||
| 18 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||
| 19 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||
| 20 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||
| 21 | POSSIBILITY OF SUCH DAMAGE.
|
||
| 22 | */
|
||
| 23 | |||
| 24 | #pragma once
|
||
| 25 | |||
| 26 | #include "cinder/audio/Context.h" |
||
| 27 | #include <jack/jack.h> |
||
| 28 | |||
| 29 | namespace cinder { namespace audio { namespace linux {
|
||
| 30 | |||
| 31 | class ContextJack; |
||
| 32 | class InputDeviceNodeJack; |
||
| 33 | |||
| 34 | class OutputDeviceNodeJack : public OutputDeviceNode {
|
||
| 35 | public:
|
||
| 36 | OutputDeviceNodeJack( const DeviceRef &device, const Format &format, const std::shared_ptr<ContextJack> &context ); |
||
| 37 | |||
| 38 | void setInput(InputDeviceNodeRef inputDeviceNode);
|
||
| 39 | |||
| 40 | protected:
|
||
| 41 | void initialize() override;
|
||
| 42 | void uninitialize() override;
|
||
| 43 | void enableProcessing() override;
|
||
| 44 | void disableProcessing() override;
|
||
| 45 | bool supportsProcessInPlace() const override { return false; } |
||
| 46 | |||
| 47 | private:
|
||
| 48 | static int jackCallback(jack_nframes_t nframes, void* userData); |
||
| 49 | |||
| 50 | |||
| 51 | void renderToBufferFromInputs();
|
||
| 52 | |||
| 53 | struct RenderData{
|
||
| 54 | RenderData() : inputNode(nullptr), outputNode(nullptr), context(nullptr){}
|
||
| 55 | ~RenderData() { inputNode = nullptr; outputNode = nullptr; context = nullptr; }
|
||
| 56 | Node* outputNode; |
||
| 57 | Node* inputNode; |
||
| 58 | ContextJack* context; |
||
| 59 | } mRenderData; |
||
| 60 | |||
| 61 | std::weak_ptr<ContextJack> mCinderContext; |
||
| 62 | |||
| 63 | jack_client_t *mClient; |
||
| 64 | |||
| 65 | std::array< jack_port_t*, 2 > mOutputPorts;
|
||
| 66 | |||
| 67 | std::shared_ptr<InputDeviceNodeJack> mInputDeviceNode; |
||
| 68 | }; |
||
| 69 | |||
| 70 | class InputDeviceNodeJack : public InputDeviceNode {
|
||
| 71 | friend OutputDeviceNodeJack; |
||
| 72 | |||
| 73 | public:
|
||
| 74 | InputDeviceNodeJack( const DeviceRef &device, const Format &format, const std::shared_ptr<ContextJack> &context ); |
||
| 75 | |||
| 76 | protected:
|
||
| 77 | void initialize() override;
|
||
| 78 | void uninitialize() override;
|
||
| 79 | void enableProcessing() override;
|
||
| 80 | void disableProcessing() override;
|
||
| 81 | void process( Buffer *buffer ) override;
|
||
| 82 | |||
| 83 | private:
|
||
| 84 | std::array< jack_port_t*, 2 > mInputPorts;
|
||
| 85 | }; |
||
| 86 | |||
| 87 | class ContextJack : public Context {
|
||
| 88 | public:
|
||
| 89 | ContextJack(); |
||
| 90 | virtual ~ContextJack(); |
||
| 91 | |||
| 92 | |||
| 93 | OutputDeviceNodeRef createOutputDeviceNode( const DeviceRef &device, const Node::Format &format = Node::Format() ) override; |
||
| 94 | InputDeviceNodeRef createInputDeviceNode( const DeviceRef &device, const Node::Format &format = Node::Format() ) override; |
||
| 95 | |||
| 96 | OutputDeviceNodeRef mOutputDeviceNode; |
||
| 97 | InputDeviceNodeRef mInputDeviceNode; |
||
| 98 | |||
| 99 | |||
| 100 | private:
|
||
| 101 | }; |
||
| 102 | |||
| 103 | } } } // namespace cinder::audio::linux |