From d8860e377e11355d7f69bca4634d1a143ef6100e Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 9 Jan 2015 23:39:25 +0100 Subject: [PATCH] [DEV] flow now link themself --- eaudiofx/Thread.cpp | 3 ++ eaudiofx/base/GeneratorSignal.cpp | 15 +++------ eaudiofx/base/ReceiverRtAudio.cpp | 15 +++------ eaudiofx/core/Block.cpp | 22 ++++++++++++- eaudiofx/core/Block.h | 2 +- eaudiofx/core/BlockMeta.cpp | 42 ++++++++++++++++++++++++- eaudiofx/core/BlockMeta.h | 2 ++ eaudiofx/core/Buffer.cpp | 2 ++ eaudiofx/core/Buffer.h | 2 +- eaudiofx/core/BufferAudio.cpp | 4 +++ eaudiofx/core/BufferAudioFreq.cpp | 3 ++ eaudiofx/core/Processing.cpp | 16 ++++++++++ eaudiofx/core/Processing.h | 2 +- eaudiofx/flow/Base.cpp | 52 ++++++++++++++++++++++++++++++- eaudiofx/flow/Base.h | 38 +++++++++++++++++++++- eaudiofx/flow/Flow.h | 18 +++++++++++ eaudiofx/flow/Interface.cpp | 46 +++++++++++++++++++++++++++ eaudiofx/flow/Interface.h | 15 +++++++-- test/Windows.cpp | 22 ++++++++++--- test/Windows.h | 1 + 20 files changed, 286 insertions(+), 36 deletions(-) diff --git a/eaudiofx/Thread.cpp b/eaudiofx/Thread.cpp index 8a61ad4..938010b 100644 --- a/eaudiofx/Thread.cpp +++ b/eaudiofx/Thread.cpp @@ -10,6 +10,9 @@ #include #include +#undef __class__ +#define __class__ "Thread" + static const char* threadGetCharState(enum eaudiofx::status state) { const char* ret = (const char*)""; switch (state) { diff --git a/eaudiofx/base/GeneratorSignal.cpp b/eaudiofx/base/GeneratorSignal.cpp index f4e25ba..bde3880 100644 --- a/eaudiofx/base/GeneratorSignal.cpp +++ b/eaudiofx/base/GeneratorSignal.cpp @@ -12,6 +12,9 @@ #include +#undef __class__ +#define __class__ "GeneratorSignal" + void eaudiofx::GeneratorSignal::init() { eaudiofx::Block::init(); } @@ -19,17 +22,7 @@ void eaudiofx::GeneratorSignal::init() { eaudiofx::GeneratorSignal::GeneratorSignal() : m_phase(0), m_output(*this, "out", "Output sinus generated", "{ type:'audio', freq:48000, format:'int16', channels:2}") { - /* - // set output : - m_io.insert( - std::pair( - "out", - eaudiofx::Block::IOProperty( - eaudiofx::Block::ioOutput, - "{ type:'audio', compression:'raw', frequency:48000, channel:2, format:'float' }", - new eaudiofx::BufferAudio(*this) - ) ) ); - */ + addObjectType("eaudiofx::GeneratorSignal"); } diff --git a/eaudiofx/base/ReceiverRtAudio.cpp b/eaudiofx/base/ReceiverRtAudio.cpp index 54eb4d9..4ce7516 100644 --- a/eaudiofx/base/ReceiverRtAudio.cpp +++ b/eaudiofx/base/ReceiverRtAudio.cpp @@ -11,6 +11,9 @@ #include #include +#undef __class__ +#define __class__ "ReceiverRtAudio" + int eaudiofx::ReceiverRtAudio::rtAudioCallBack(void *_outputBuffer, void *_inputBuffer, unsigned int _nBufferFrames, @@ -66,17 +69,7 @@ void eaudiofx::ReceiverRtAudio::init() { eaudiofx::ReceiverRtAudio::ReceiverRtAudio() : m_processStarted(false), m_input(*this, "in", "Input audio flow", "{ type:'audio', freq:[8000, 16000, 32000, 48000, 64000, 96000, 128000, 192000], format:['int8','int16','int32','float']}") { - /* - // set output : - m_io.insert( - std::pair( - "in", - eaudiofx::Block::IOProperty( - eaudiofx::Block::ioInput, - "{ type:'audio', compression:'raw', frequency:48000, channel:2, format:'float' }", - NULL - ) ) ); - */ + addObjectType("eaudiofx::ReceiverRtAudio"); }; diff --git a/eaudiofx/core/Block.cpp b/eaudiofx/core/Block.cpp index 99992c0..fd1e228 100644 --- a/eaudiofx/core/Block.cpp +++ b/eaudiofx/core/Block.cpp @@ -11,10 +11,12 @@ #include #include +#undef __class__ +#define __class__ "Block" eaudiofx::Block::Block() { - + addObjectType("eaudiofx::Block"); } eaudiofx::Block::~Block() { @@ -22,3 +24,21 @@ eaudiofx::Block::~Block() { } + +std::shared_ptr eaudiofx::Block::getBlockNamed(const std::string& _name) { + std::shared_ptr out; + EAUDIOFX_INFO(" get block : " << _name); + std::shared_ptr parrent = m_parent.lock(); + if (parrent != nullptr) { + std::shared_ptr parrentBlock = std::dynamic_pointer_cast(parrent); + if (parrentBlock != nullptr) { + return parrentBlock->getBlockNamed(_name); + } else { + EAUDIOFX_INFO(" Parent is not a Block ..."); + } + } else { + EAUDIOFX_INFO(" No parent ..."); + } + return out; +} + diff --git a/eaudiofx/core/Block.h b/eaudiofx/core/Block.h index 1c29f38..3ea6a00 100644 --- a/eaudiofx/core/Block.h +++ b/eaudiofx/core/Block.h @@ -90,7 +90,7 @@ namespace eaudiofx { int32_t algoProcess(int64_t _currentTime, int64_t _processTimeSlot) { return eaudiofx::ERR_NONE; } - + virtual std::shared_ptr getBlockNamed(const std::string& _name); }; }; diff --git a/eaudiofx/core/BlockMeta.cpp b/eaudiofx/core/BlockMeta.cpp index b217388..49b532f 100644 --- a/eaudiofx/core/BlockMeta.cpp +++ b/eaudiofx/core/BlockMeta.cpp @@ -9,10 +9,12 @@ #include #include +#undef __class__ +#define __class__ "BlockMeta" eaudiofx::BlockMeta::BlockMeta() { - + addObjectType("eaudiofx::BlockMeta"); } eaudiofx::BlockMeta::~BlockMeta() { @@ -60,6 +62,7 @@ int32_t eaudiofx::BlockMeta::addBlock(const std::shared_ptr& _b } } m_list.push_back(_block); + _block->setParent(shared_from_this()); return eaudiofx::ERR_NONE; } @@ -167,3 +170,40 @@ int32_t eaudiofx::BlockMeta::algoStop() { return ret; }; + +std::shared_ptr eaudiofx::BlockMeta::getBlockNamed(const std::string& _name) { + std::shared_ptr out; + EAUDIOFX_DEBUG("[" << m_name << "] try get Block : " << _name); + // Special case for proxy flow ... + if ( _name == "" + || _name == m_name.get()) { + EAUDIOFX_DEBUG(" ==> find Him"); + return std::static_pointer_cast(shared_from_this()); + } + // find in sub elements. + for (auto &it : m_list) { + if (it == nullptr) { + continue; + } + EAUDIOFX_DEBUG(" check : " << it->getName()); + if (it->getName() == _name) { + out = it; + EAUDIOFX_DEBUG(" ==> find this one"); + break; + } + } + return out; +} + +void eaudiofx::BlockMeta::flowLinkInput() { + EAUDIOFX_INFO("[" << getId() << "] Meta block Link: '" << getName() << "'"); + // find in sub elements. + for (auto &it : m_list) { + if (it == nullptr) { + continue; + } + it->flowLinkInput(); + } + // Call upper class + eaudiofx::Block::flowLinkInput(); +} diff --git a/eaudiofx/core/BlockMeta.h b/eaudiofx/core/BlockMeta.h index 0b4225c..41bd674 100644 --- a/eaudiofx/core/BlockMeta.h +++ b/eaudiofx/core/BlockMeta.h @@ -82,6 +82,8 @@ namespace eaudiofx { virtual int32_t algoStart(); virtual int32_t algoStop(); + virtual std::shared_ptr getBlockNamed(const std::string& _name); + virtual void flowLinkInput(); }; }; diff --git a/eaudiofx/core/Buffer.cpp b/eaudiofx/core/Buffer.cpp index c168caa..2b5316e 100644 --- a/eaudiofx/core/Buffer.cpp +++ b/eaudiofx/core/Buffer.cpp @@ -8,6 +8,8 @@ #include +#undef __class__ +#define __class__ "Buffer" eaudiofx::Buffer::Buffer(eaudiofx::Block& _parent) : diff --git a/eaudiofx/core/Buffer.h b/eaudiofx/core/Buffer.h index 0bb5763..1143983 100644 --- a/eaudiofx/core/Buffer.h +++ b/eaudiofx/core/Buffer.h @@ -14,7 +14,7 @@ namespace eaudiofx { class Block; - class Buffer { + class Buffer : public std::enable_shared_from_this { public: Buffer(eaudiofx::Block& _parent); virtual ~Buffer() {}; diff --git a/eaudiofx/core/BufferAudio.cpp b/eaudiofx/core/BufferAudio.cpp index 811aaba..aa0adf3 100644 --- a/eaudiofx/core/BufferAudio.cpp +++ b/eaudiofx/core/BufferAudio.cpp @@ -9,6 +9,10 @@ #include #include +#undef __class__ +#define __class__ "BufferAudio" + + eaudiofx::BufferAudio::BufferAudio(eaudiofx::Block& _parent, const std::string& _description) : eaudiofx::Buffer(_parent), m_frequency(48000), diff --git a/eaudiofx/core/BufferAudioFreq.cpp b/eaudiofx/core/BufferAudioFreq.cpp index 319a2dd..85f1000 100644 --- a/eaudiofx/core/BufferAudioFreq.cpp +++ b/eaudiofx/core/BufferAudioFreq.cpp @@ -8,6 +8,9 @@ #include +#undef __class__ +#define __class__ "BufferAudioFreq" + eaudiofx::BufferAudioFreq::BufferAudioFreq(eaudiofx::Block& _parent) : eaudiofx::BufferAudio(_parent) { diff --git a/eaudiofx/core/Processing.cpp b/eaudiofx/core/Processing.cpp index ae5b8c7..72852e5 100644 --- a/eaudiofx/core/Processing.cpp +++ b/eaudiofx/core/Processing.cpp @@ -11,6 +11,12 @@ #include +#undef __class__ +#define __class__ "Processing" +eaudiofx::Processing::Processing() { + addObjectType("eaudiofx::Processing"); +}; + int32_t eaudiofx::Processing::process() { EAUDIOFX_INFO("Start process : '" << getName() << "'"); return eaudiofx::ERR_NONE; @@ -34,6 +40,16 @@ int32_t eaudiofx::Processing::waitEndOfProcess() { bool eaudiofx::Processing::stateStart() { EAUDIOFX_INFO("Start Processing : '" << getName() << "'"); + // TODO : Add return code ... and test all of theses events ... + // Init request flow update: + flowLinkInput(); + // check if the IOs are compatible + flowCheckAllCompatibility(); + // Allocate all Outputs + flowAllocateOutput(); + // Get pointer on all Inputs + flowGetInput(); + // init algorithm int32_t ret = algoInit(); if (ret != eaudiofx::ERR_NONE) { return ret; diff --git a/eaudiofx/core/Processing.h b/eaudiofx/core/Processing.h index c0594b9..1a78a59 100644 --- a/eaudiofx/core/Processing.h +++ b/eaudiofx/core/Processing.h @@ -19,7 +19,7 @@ namespace eaudiofx { class Processing : public eaudiofx::BlockMeta, eaudiofx::Thread { protected: - Processing() {}; + Processing(); void init() { eaudiofx::BlockMeta::init(); }; diff --git a/eaudiofx/flow/Base.cpp b/eaudiofx/flow/Base.cpp index 82850cd..83243f4 100644 --- a/eaudiofx/flow/Base.cpp +++ b/eaudiofx/flow/Base.cpp @@ -10,6 +10,10 @@ #include #include #include +#include + +#undef __class__ +#define __class__ "flow::Base" eaudiofx::flow::Base::Base(eaudiofx::flow::Interface& _flowInterfaceLink, bool _input, @@ -20,14 +24,60 @@ eaudiofx::flow::Base::Base(eaudiofx::flow::Interface& _flowInterfaceLink, m_name(_name), m_description(_description), m_input(_input) { + m_ref = std::make_shared(this); // add a reference on the current signal ... m_flowInterfaceLink.flowAdd(this); m_formatAvaillable.parse(_formatAvaillable); - EAUDIOFX_INFO(" create flow : " << _name << " mode:'" << (m_input==true?"input":"output") << "' prop:"); + EAUDIOFX_INFO("Create flow : '" << m_name << "' mode:'" << (m_input==true?"input":"output") << "' prop:"); m_formatAvaillable.display(); } +eaudiofx::flow::Base::~Base() { + m_ref->removeBase(); + EAUDIOFX_INFO("Remove flow : '" << m_name << "' mode:'" << (m_input==true?"input":"output") << "'"); +}; + std::ostream& eaudiofx::flow::operator <<(std::ostream& _os, const eaudiofx::flow::Base& _obj) { _os << _obj.getName(); return _os; } + +void eaudiofx::flow::Base::link() { + EAUDIOFX_INFO(" link flow : '" << m_name << "' mode:'" << (m_input==true?"input":"output") << "' (no code)"); +} + +void checkCompatibility() { + EAUDIOFX_INFO(" chack flow : '" << m_name << "' (no code)"); +} + +void getInputBuffer() { + EAUDIOFX_INFO(" get Buffers : '" << m_name << "' (no code)"); +} + +// due to the fact it acces at the block interface, we need to write it here ... +std::shared_ptr eaudiofx::flow::Base::getFlowReference(const std::string& _blockName, + const std::string& _flowLinkName) { + std::shared_ptr out; + if (_flowLinkName == "") { + EAUDIOFX_INFO(" Get flow : " << _blockName << ":" << _flowLinkName << " nothing to do ==> no connection ..."); + } + std::shared_ptr blockRemote = m_flowInterfaceLink.getBlockNamed(_blockName); + if (blockRemote == nullptr) { + EAUDIOFX_ERROR(" Get flow : '" << m_name << "' mode:'input' to " << _blockName << ":" << _flowLinkName << " Error no remote block"); + } else { + out = blockRemote->getFlowReference(_flowLinkName); + if (out == nullptr) { + EAUDIOFX_ERROR(" Get flow : '" << m_name << "' mode:'input' to " << _blockName << ":" << _flowLinkName << " Error no Flow found"); + } else { + EAUDIOFX_INFO(" Get flow : " << _blockName << ":" << _flowLinkName); + } + } + return out; +} + +/* +std::shared_ptr eaudiofx::flow::Base::getBlockNamed(const std::string& _name) { + EAUDIOFX_ERROR("NEED to call Parrent ..."); + return nullptr; +} +*/ diff --git a/eaudiofx/flow/Base.h b/eaudiofx/flow/Base.h index bdcfd58..81bfec1 100644 --- a/eaudiofx/flow/Base.h +++ b/eaudiofx/flow/Base.h @@ -17,6 +17,7 @@ namespace eaudiofx { namespace flow { + class BaseReference; class Base { protected: eaudiofx::flow::Interface& m_flowInterfaceLink; @@ -41,7 +42,7 @@ namespace eaudiofx { /** * @brief Destructor. */ - virtual ~Base() { }; + virtual ~Base(); const std::string& getName() const { return m_name; @@ -67,8 +68,43 @@ namespace eaudiofx { const std::string& _flowLinkName) { EAUDIOFX_ERROR("[" << m_name << "] Can not create a link on an Output (only manage with input ...)"); } + protected: + std::shared_ptr m_ref; //!< To simplify implementation code we use a temporary variable to shared the current reference... + public: + std::shared_ptr getReference() { + return m_ref; + } + virtual void addReference(const std::shared_ptr& _reference) { + EAUDIOFX_ERROR("[" << m_name << "] Can not add reference ..."); + } + protected: + std::shared_ptr getFlowReference(const std::string& _blockName, + const std::string& _flowLinkName); + public: + virtual void link(); + virtual void checkCompatibility(); + virtual void getInputBuffer(); + //virtual std::shared_ptr getBlockNamed(const std::string& _name); }; std::ostream& operator <<(std::ostream& _os, const eaudiofx::flow::Base& _obj); + // we use a reference to simplify code of every blocks... + //! @not-in-doc + class BaseReference : public std::enable_shared_from_this { + protected: + Base* m_basePointer; + public: + BaseReference(Base* _base = nullptr) : + m_basePointer(_base) { + // nothing to do ... + } + ~BaseReference() {} + void removeBase() { + m_basePointer = nullptr; + } + inline Base* getBase() const { + return m_basePointer; + } + }; }; }; #endif diff --git a/eaudiofx/flow/Flow.h b/eaudiofx/flow/Flow.h index 31616dc..ed02fc5 100644 --- a/eaudiofx/flow/Flow.h +++ b/eaudiofx/flow/Flow.h @@ -62,6 +62,7 @@ namespace eaudiofx { private: std::string m_blockName; //!< Temporary value of flow link (when not linked & distant block can be created after) : Block name std::string m_flowName; //!< Temporary value of flow link (when not linked & distant block can be created after) : Flow name + std::weak_ptr m_remoteFlow; //!< reference on the remote flow. public: /** * @brief Create a parameter with a specific type. @@ -87,10 +88,24 @@ namespace eaudiofx { m_flowName = _flowLinkName; EAUDIOFX_INFO("[" << Base::m_name << "] Link with : '" << m_blockName << "':'" << m_flowName << "'"); } + virtual void link() { + EAUDIOFX_INFO(" link flow : '" << Base::m_name << "' mode:'input' to " << m_blockName << ":" << m_flowName); + std::shared_ptr remoteFlow = Base::getFlowReference(m_blockName, m_flowName); + m_remoteFlow = remoteFlow; + if (remoteFlow == nullptr) { + EAUDIOFX_ERROR(" link flow : '" << Base::m_name << "' mode:'input' to " << m_blockName << ":" << m_flowName << " Error no Flow found"); + return; + } + // set our own cross reference to the remote ... + remoteFlow->getBase()->addReference(Base::getReference()); + } }; #undef __class__ #define __class__ "flow::Output" template class Output : public Flow { + protected: + std::vector> m_remoteFlow; //!< List of reference on the remote flow (multiple childs). + ejson::Document m_formatMix; //!< current format that is now availlable on the flow (can be on error) represent the intersection of all flow connected public: /** * @brief Create a parameter with a specific type. @@ -110,6 +125,9 @@ namespace eaudiofx { * @brief Destructor. */ virtual ~Output() { }; + virtual void addReference(const std::shared_ptr& _reference) { + m_remoteFlow.push_back(_reference); + } }; }; #undef __class__ diff --git a/eaudiofx/flow/Interface.cpp b/eaudiofx/flow/Interface.cpp index c9425ec..fd31ec3 100644 --- a/eaudiofx/flow/Interface.cpp +++ b/eaudiofx/flow/Interface.cpp @@ -72,3 +72,49 @@ void eaudiofx::flow::Interface::flowSetLinkWith(const std::string& _flowName, } EAUDIOFX_ERROR("Can not find Flow : '" << _flowName << "'"); } + +void eaudiofx::flow::Interface::flowLinkInput() { + EAUDIOFX_INFO(" Block update the flows links"); + for (auto &it : m_list) { + if(it != nullptr) { + it->link(); + } + } +} + +void eaudiofx::flow::Interface::flowCheckAllCompatibility() { + EAUDIOFX_INFO(" Block Check the flows Capabilities"); + for (auto &it : m_list) { + if(it != nullptr) { + it->checkCompatibility(); + } + } +} + +void eaudiofx::flow::Interface::flowAllocateOutput() { + EAUDIOFX_WARNING(" Block need to allocate all his output"); +} + +void eaudiofx::flow::Interface::flowGetInput() { + EAUDIOFX_WARNING(" Block Get input data pointers"); + for (auto &it : m_list) { + if(it != nullptr) { + it->getInputBuffer(); + } + } +} + + +std::shared_ptr eaudiofx::flow::Interface::getFlowReference(const std::string& _flowName) { + std::shared_ptr out; + for (auto &it : m_list) { + if( it != nullptr + && it->getName() == _flowName) { + out = it->getReference(); + break; + } + } + return out; +} + + diff --git a/eaudiofx/flow/Interface.h b/eaudiofx/flow/Interface.h index 7059a06..fdb5796 100644 --- a/eaudiofx/flow/Interface.h +++ b/eaudiofx/flow/Interface.h @@ -14,8 +14,10 @@ #include namespace eaudiofx { + class Block; namespace flow { class Base; + class BaseReference; class Interface { friend class eaudiofx::flow::Base; // to register parameter in the list. private: @@ -62,14 +64,23 @@ namespace eaudiofx { const std::string& _flowLinkName); public: // get pointer on the specidic input and output from all the IOs - virtual void flowLinkAllInputOutput() {}; + virtual void flowLinkInput(); // check if the IOs are compatible virtual void flowCheckAllCompatibility() {}; // Allocate all Outputs virtual void flowAllocateOutput() {}; // Get pointer on all Inputs - virtual void flowgetInput() {}; + virtual void flowGetInput() {}; + /** + * @brief Get The block named ... + * @param[in] _name Name of the block requested + * @return The block requested if it exist. + */ + virtual std::shared_ptr getBlockNamed(const std::string& _name) { + return nullptr; + } + std::shared_ptr getFlowReference(const std::string& _name); }; }; }; diff --git a/test/Windows.cpp b/test/Windows.cpp index ea27ecb..c38c197 100644 --- a/test/Windows.cpp +++ b/test/Windows.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -38,9 +39,14 @@ void appl::Windows::init() { composition += " Play 1\n"; composition += " \n"; composition += " \n"; - composition += " \n"; + composition += " \n"; composition += " \n"; @@ -54,11 +60,16 @@ void appl::Windows::init() { } setSubWidget(m_composer); subBind(ewol::widget::Button, "bt-play1", signalPressed, shared_from_this(), &appl::Windows::onCallbackPlay); - subBind(ewol::widget::Button, "bt-play2", signalPressed, shared_from_this(), &appl::Windows::onCallbackStop); + subBind(ewol::widget::Button, "bt-stop1", signalPressed, shared_from_this(), &appl::Windows::onCallbackStop); + subBind(ewol::widget::Button, "bt-play-stop", signalPressed, shared_from_this(), &appl::Windows::onCallbackPlayStop); } std::shared_ptr process = NULL; - +void appl::Windows::onCallbackPlayStop() { + onCallbackPlay(); + usleep(500000); + onCallbackStop(); +} void appl::Windows::onCallbackPlay() { #if 0 APPL_INFO("Play Requested ..."); @@ -106,13 +117,14 @@ void appl::Windows::onCallbackPlay() { APPL_ERROR("can not create processing ..."); return; } + process->setName("main Process"); APPL_INFO("Create Generator Sinus"); std::shared_ptr generator = eaudiofx::GeneratorSignal::create(); if (generator == NULL) { APPL_ERROR("can not create Generator ..."); return; } - generator->setName("myGeneratorSinus"); + generator->setName("myGenerator"); process->addBlock(generator); APPL_INFO("Create Receiver ..."); diff --git a/test/Windows.h b/test/Windows.h index 8b86b88..44780ce 100644 --- a/test/Windows.h +++ b/test/Windows.h @@ -24,6 +24,7 @@ namespace appl { public: // callback functions void onCallbackPlay(); void onCallbackStop(); + void onCallbackPlayStop(); }; };