From d76825551a7a6d24658cbb723828f0015170798e Mon Sep 17 00:00:00 2001 From: eliott PARIS Date: Tue, 22 May 2018 18:46:08 +0200 Subject: [PATCH 01/19] [select] update and bug-fix - fix bad output when symbol match - output input if doesn't match and not bang - fix io description - Add [sel] alias --- .../KiwiEngine_Objects/KiwiEngine_Select.cpp | 51 +++++++++---------- .../KiwiModel_Objects/KiwiModel_Select.cpp | 20 +++++--- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Select.cpp b/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Select.cpp index a345732b..f2316bb3 100644 --- a/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Select.cpp +++ b/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Select.cpp @@ -38,46 +38,41 @@ namespace kiwi { namespace engine { return std::make_unique & select_model = DataModel::declare(std::move(select_class), select_model); + auto& flip_class = (DataModel::declare(std::move(kiwi_class), flip_class); } std::unique_ptr Select::create(std::vector const& args) @@ -79,13 +81,15 @@ namespace kiwi { namespace model { } else { - if (index == getArguments().size()) + auto const& args = getArguments(); + + if (index == args.size()) { - description = "Ouptuts bang if input doesn't match"; + description = "Input if doesn't match"; } else { - description = "Outputs bang if input matches " + getArguments()[index].getString(); + description = "Outputs bang if input matches \"" + tool::AtomHelper::toString(args[index]) + "\""; } } From 12012641c8a509eb24324902f52a570acffb3e5a Mon Sep 17 00:00:00 2001 From: eliott PARIS Date: Tue, 22 May 2018 19:11:23 +0200 Subject: [PATCH 02/19] fixes various io description issues by removing useless function calls --- .../KiwiApp_Patcher/KiwiApp_PatcherViewIoletHighlighter.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Client/Source/KiwiApp_Patcher/KiwiApp_PatcherViewIoletHighlighter.cpp b/Client/Source/KiwiApp_Patcher/KiwiApp_PatcherViewIoletHighlighter.cpp index 03ee3ceb..055933e5 100644 --- a/Client/Source/KiwiApp_Patcher/KiwiApp_PatcherViewIoletHighlighter.cpp +++ b/Client/Source/KiwiApp_Patcher/KiwiApp_PatcherViewIoletHighlighter.cpp @@ -77,10 +77,7 @@ namespace kiwi void IoletHighlighter::highlight(ObjectFrame const& object, const size_t index, bool is_inlet) { - const auto& object_model = object.getModel(); - - auto new_name = object_model.getName(); - auto new_text = object_model.getIODescription(m_is_inlet, index); + auto const& object_model = object.getModel(); //! Only hilight if either no pin is currently hilighted //! or hilighted pin is different. From 355b6f2380c4373b500330e764aab1d425947e24 Mon Sep 17 00:00:00 2001 From: eliott PARIS Date: Tue, 22 May 2018 19:16:18 +0200 Subject: [PATCH 03/19] [pack] - update first inlet description --- Modules/KiwiModel/KiwiModel_Objects/KiwiModel_Pack.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Modules/KiwiModel/KiwiModel_Objects/KiwiModel_Pack.cpp b/Modules/KiwiModel/KiwiModel_Objects/KiwiModel_Pack.cpp index ee10b9fa..175e8afb 100755 --- a/Modules/KiwiModel/KiwiModel_Objects/KiwiModel_Pack.cpp +++ b/Modules/KiwiModel/KiwiModel_Objects/KiwiModel_Pack.cpp @@ -73,8 +73,15 @@ namespace kiwi { namespace model { default: return "null"; } }(); + + auto description = type_str + " atom " + std::to_string(index + 1) + " in list"; + + if(index == 0) + { + description += ", causes output"; + } - return type_str + " atom " + std::to_string(index + 1) + " in list"; + return std::move(description); } return {}; From c6dbbd59e38662635550efd938ba0e392d40f9e8 Mon Sep 17 00:00:00 2001 From: eliott PARIS Date: Tue, 22 May 2018 19:29:08 +0200 Subject: [PATCH 04/19] [number] - Add patcherview shortcuts (f/i) --- .../KiwiApp_General/KiwiApp_CommandIDs.h | 1 - .../KiwiApp_Patcher/KiwiApp_PatcherView.cpp | 18 ++++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Client/Source/KiwiApp_General/KiwiApp_CommandIDs.h b/Client/Source/KiwiApp_General/KiwiApp_CommandIDs.h index d9f764f0..3239dc8c 100644 --- a/Client/Source/KiwiApp_General/KiwiApp_CommandIDs.h +++ b/Client/Source/KiwiApp_General/KiwiApp_CommandIDs.h @@ -68,7 +68,6 @@ namespace kiwi newBox = 0xf30300, ///< Add a new "box" to the patcher. newMessage = 0xf30301, ///< Add a new "message" object box to the patcher. - newFlonum = 0xf30302, ///< Add a new "flonum" object box to the patcher. newNumber = 0xf30303, ///< Add a new "number" object box to the patcher. newComment = 0xf30304, ///< Add a new "comment" object box to the patcher. newBang = 0xf30305, ///< Add a new "button" object box to the patcher. diff --git a/Client/Source/KiwiApp_Patcher/KiwiApp_PatcherView.cpp b/Client/Source/KiwiApp_Patcher/KiwiApp_PatcherView.cpp index ab048658..4c9d4901 100755 --- a/Client/Source/KiwiApp_Patcher/KiwiApp_PatcherView.cpp +++ b/Client/Source/KiwiApp_Patcher/KiwiApp_PatcherView.cpp @@ -1826,7 +1826,8 @@ namespace kiwi commands.add(CommandIDs::newToggle); commands.add(CommandIDs::newSlider); commands.add(CommandIDs::newMessage); - commands.add(CommandIDs::newComment); + commands.add(CommandIDs::newComment); + commands.add(CommandIDs::newNumber); commands.add(CommandIDs::zoomIn); commands.add(CommandIDs::zoomOut); @@ -1972,6 +1973,14 @@ namespace kiwi result.addDefaultKeypress('s', juce::ModifierKeys::noModifiers); result.setActive(!isLocked()); break; + } + case CommandIDs::newNumber: + { + result.setInfo(TRANS("New Number Box"), TRANS("Add a new number"), CommandCategories::editing, 0); + result.addDefaultKeypress('f', juce::ModifierKeys::noModifiers); + result.addDefaultKeypress('i', juce::ModifierKeys::noModifiers); + result.setActive(!isLocked()); + break; } case CommandIDs::newComment: { @@ -2059,9 +2068,10 @@ namespace kiwi case juce::StandardApplicationCommandIDs::selectAll:{ selectAllObjects(); break; } case CommandIDs::newBox: { createObjectModel("", true); break; } - case CommandIDs::newBang: { createObjectModel("bang", true); break; } - case CommandIDs::newToggle: { createObjectModel("toggle", true); break; } - case CommandIDs::newSlider: { createObjectModel("slider", true); break; } + case CommandIDs::newBang: { createObjectModel("bang", false); break; } + case CommandIDs::newToggle: { createObjectModel("toggle", false); break; } + case CommandIDs::newNumber: { createObjectModel("number", false); break; } + case CommandIDs::newSlider: { createObjectModel("slider", false); break; } case CommandIDs::newComment: { createObjectModel("comment", true); break; } case CommandIDs::newMessage: { createObjectModel("message", true); break; } From a9b2ef5af3df2519e19acda7431075d69dcbb88c Mon Sep 17 00:00:00 2001 From: eliott PARIS Date: Tue, 22 May 2018 19:51:13 +0200 Subject: [PATCH 05/19] [bang] - Add "set" method (flash without output) --- .../KiwiApp_Objects/KiwiApp_BangView.cpp | 19 +++++++++--------- .../KiwiApp_Objects/KiwiApp_BangView.h | 6 ++++-- .../KiwiEngine_Objects/KiwiEngine_Bang.cpp | 20 +++++++++++++------ .../KiwiEngine_Objects/KiwiEngine_Bang.h | 3 ++- .../KiwiModel_Objects/KiwiModel_Bang.cpp | 2 ++ .../KiwiModel_Objects/KiwiModel_Bang.h | 3 ++- 6 files changed, 34 insertions(+), 19 deletions(-) diff --git a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_BangView.cpp b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_BangView.cpp index 840fae94..8e67e40d 100644 --- a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_BangView.cpp +++ b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_BangView.cpp @@ -40,14 +40,15 @@ namespace kiwi { return std::make_unique(model); } - BangView::BangView(model::Object & model): - ObjectView(model), - m_signal(model.getSignal<>(model::Bang::Signal::TriggerBang)), - m_connection(m_signal.connect(std::bind(&BangView::signalTriggered, this))), - m_active(false), - m_mouse_down(false) - { - } + BangView::BangView(model::Object & model) + : ObjectView(model) + , m_trigger_signal(model.getSignal<>(model::Bang::Signal::TriggerBang)) + , m_flash_signal(model.getSignal<>(model::Bang::Signal::FlashBang)) + , m_trigger_connection(m_trigger_signal.connect(std::bind(&BangView::signalTriggered, this))) + , m_flash_connection(m_flash_signal.connect(std::bind(&BangView::signalTriggered, this))) + , m_active(false) + , m_mouse_down(false) + {} BangView::~BangView() { @@ -81,7 +82,7 @@ namespace kiwi { m_mouse_down = true; repaint(); - m_signal(); + m_trigger_signal(); } void BangView::mouseUp(juce::MouseEvent const& e) diff --git a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_BangView.h b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_BangView.h index 3ab0cdd6..0acc6acc 100644 --- a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_BangView.h +++ b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_BangView.h @@ -62,8 +62,10 @@ namespace kiwi { private: // members //! @todo Put border into ObjectView. - flip::Signal<>& m_signal; - flip::SignalConnection m_connection; + flip::Signal<>& m_trigger_signal; + flip::Signal<>& m_flash_signal; + flip::SignalConnection m_trigger_connection; + flip::SignalConnection m_flash_connection; bool m_active; bool m_mouse_down; diff --git a/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Bang.cpp b/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Bang.cpp index a0a98733..13ec8581 100644 --- a/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Bang.cpp +++ b/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Bang.cpp @@ -40,10 +40,11 @@ namespace kiwi { namespace engine { return std::make_unique(model, patcher); } - Bang::Bang(model::Object const& model, Patcher & patcher): - Object(model, patcher), - m_signal(model.getSignal<>(model::Bang::Signal::TriggerBang)), - m_connection(m_signal.connect(std::bind(&Bang::signalTriggered, this))) + Bang::Bang(model::Object const& model, Patcher & patcher) + : Object(model, patcher) + , m_trigger_signal(model.getSignal<>(model::Bang::Signal::TriggerBang)) + , m_flash_signal(model.getSignal<>(model::Bang::Signal::FlashBang)) + , m_connection(m_trigger_signal.connect(std::bind(&Bang::signalTriggered, this))) { } @@ -61,9 +62,16 @@ namespace kiwi { namespace engine { void Bang::receive(size_t index, std::vector const& args) { - if (index == 0) + if (index == 0 && !args.empty()) { - m_signal(); + if(args[0].getString() == "set") + { + m_flash_signal(); + } + else + { + m_trigger_signal(); + } } } diff --git a/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Bang.h b/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Bang.h index b2112019..9fd4893f 100644 --- a/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Bang.h +++ b/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Bang.h @@ -47,7 +47,8 @@ namespace kiwi { namespace engine { private: // members - flip::Signal<> & m_signal; + flip::Signal<>& m_trigger_signal; + flip::Signal<>& m_flash_signal; flip::SignalConnection m_connection; }; diff --git a/Modules/KiwiModel/KiwiModel_Objects/KiwiModel_Bang.cpp b/Modules/KiwiModel/KiwiModel_Objects/KiwiModel_Bang.cpp index b618178c..ec7bdc9f 100755 --- a/Modules/KiwiModel/KiwiModel_Objects/KiwiModel_Bang.cpp +++ b/Modules/KiwiModel/KiwiModel_Objects/KiwiModel_Bang.cpp @@ -56,6 +56,7 @@ namespace kiwi { namespace model { } addSignal<>(Signal::TriggerBang, *this); + addSignal<>(Signal::FlashBang, *this); setRatio(1.); setMinWidth(20.); setWidth(20); @@ -67,6 +68,7 @@ namespace kiwi { namespace model { Object(d) { addSignal<>(Signal::TriggerBang, *this); + addSignal<>(Signal::FlashBang, *this); } std::string Bang::getIODescription(bool is_inlet, size_t index) const diff --git a/Modules/KiwiModel/KiwiModel_Objects/KiwiModel_Bang.h b/Modules/KiwiModel/KiwiModel_Objects/KiwiModel_Bang.h index 0673c878..505ddf00 100755 --- a/Modules/KiwiModel/KiwiModel_Objects/KiwiModel_Bang.h +++ b/Modules/KiwiModel/KiwiModel_Objects/KiwiModel_Bang.h @@ -35,7 +35,8 @@ namespace kiwi { namespace model { enum Signal : SignalKey { - TriggerBang + TriggerBang, + FlashBang }; public: // methods From 78ef1912ed646084af7a3a395685aedc8dd67cb4 Mon Sep 17 00:00:00 2001 From: eliott PARIS Date: Wed, 23 May 2018 01:10:07 +0200 Subject: [PATCH 06/19] [number] bug-fix and improvements : - Output only when value changed - bind to shift shortcut - hide mouse on drag [number~] draw a tilde before the number --- .../KiwiApp_NumberTildeView.cpp | 14 ++++-- .../KiwiApp_Objects/KiwiApp_NumberTildeView.h | 2 + .../KiwiApp_Objects/KiwiApp_NumberView.cpp | 47 +++++++++++++------ .../KiwiApp_Objects/KiwiApp_NumberView.h | 2 + .../KiwiApp_NumberViewBase.cpp | 32 ++++--------- .../KiwiApp_Objects/KiwiApp_NumberViewBase.h | 7 +-- 6 files changed, 60 insertions(+), 44 deletions(-) diff --git a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberTildeView.cpp b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberTildeView.cpp index 2ff4766f..933fc7b8 100644 --- a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberTildeView.cpp +++ b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberTildeView.cpp @@ -38,14 +38,22 @@ namespace kiwi { return std::make_unique(object_model); } - NumberTildeView::NumberTildeView(model::Object & object_model) : - NumberViewBase(object_model) + NumberTildeView::NumberTildeView(model::Object & object_model) + : NumberViewBase(object_model) { setEditable(false); - setIconColour(findColour(ObjectView::ColourIds::Active)); setInterceptsMouseClicks(false, false); } + void NumberTildeView::drawIcon (juce::Graphics& g) const + { + g.setColour (findColour (ObjectView::ColourIds::Active)); + + g.setFont(22.f); + g.drawFittedText("~", getLocalBounds().withWidth(getHeight()).withX(2), + juce::Justification::centredLeft, 1); + } + void NumberTildeView::parameterChanged(std::string const& name, tool::Parameter const& param) { if (name == "value") diff --git a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberTildeView.h b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberTildeView.h index aa043fbe..898b6c6b 100644 --- a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberTildeView.h +++ b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberTildeView.h @@ -48,6 +48,8 @@ namespace kiwi { private: // methods + void drawIcon (juce::Graphics& g) const override; + //! @brief Called when the displayed number has just changed. void displayNumberChanged(double new_number) override final; diff --git a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberView.cpp b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberView.cpp index 5c6bb194..7d4f4ad5 100644 --- a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberView.cpp +++ b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberView.cpp @@ -40,13 +40,12 @@ namespace kiwi { return std::make_unique(object_model); } - NumberView::NumberView(model::Object & object_model) : - NumberViewBase(object_model), - m_output_message(object_model.getSignal<>(model::Message::Signal::outputMessage)), - m_sensitivity(1), - m_mouse_info() + NumberView::NumberView(model::Object & object_model) + : NumberViewBase(object_model) + , m_output_message(object_model.getSignal<>(model::Message::Signal::outputMessage)) + , m_sensitivity(1) + , m_mouse_info() { - setIconColour(findColour(ObjectView::ColourIds::Outline)); setInterceptsMouseClicks(true, true); } @@ -54,6 +53,23 @@ namespace kiwi { { } + void NumberView::drawIcon (juce::Graphics& g) const + { + g.setColour(findColour(ObjectView::ColourIds::Outline)); + + const juce::Rectangle icon_bounds = getLocalBounds() + .withWidth(m_indent - 4).withHeight(getHeight() - 8).translated(2, 4); + + juce::Path corner; + + corner.addTriangle(icon_bounds.getTopLeft().toFloat(), + icon_bounds.getTopRight().toFloat() + + juce::Point(0, (icon_bounds.getHeight() / 2.)), + icon_bounds.getBottomLeft().toFloat()); + + g.fillPath(corner); + } + void NumberView::mouseDoubleClick(juce::MouseEvent const& e) { getLabel().showEditor(); @@ -66,7 +82,7 @@ namespace kiwi { m_mouse_info.m_mouse_down_value = getDisplayNumber(); m_mouse_info.m_mouse_down_y = e.y; - if (e.mods.isAltDown()) + if (e.mods.isShiftDown()) { m_mouse_info.m_is_alt_down = true; m_mouse_info.m_alt_down_value = getDisplayNumber(); @@ -78,15 +94,15 @@ namespace kiwi { { if (e.getDistanceFromDragStartY() != 0) { - double new_value = 0; + double new_value = m_value; - if (!m_mouse_info.m_is_alt_down && e.mods.isAltDown()) + if (!m_mouse_info.m_is_alt_down && e.mods.isShiftDown()) { m_mouse_info.m_is_alt_down = true; m_mouse_info.m_alt_down_value = getDisplayNumber(); m_mouse_info.m_alt_down_y = e.y; } - else if(m_mouse_info.m_is_alt_down && !e.mods.isAltDown()) + else if(m_mouse_info.m_is_alt_down && !e.mods.isShiftDown()) { m_mouse_info.m_mouse_down_value = getDisplayNumber(); m_mouse_info.m_mouse_down_y = e.y; @@ -95,7 +111,7 @@ namespace kiwi { m_mouse_info.m_alt_down_y = 0; } - if (e.mods.isAltDown()) + if (e.mods.isShiftDown()) { new_value = m_mouse_info.m_alt_down_value - (m_sensitivity * (e.y - m_mouse_info.m_alt_down_y)) / 100.; } @@ -104,9 +120,12 @@ namespace kiwi { new_value = m_mouse_info.m_mouse_down_value - m_sensitivity * (e.y - m_mouse_info.m_mouse_down_y); } - setParameter("value", tool::Parameter(tool::Parameter::Type::Float, {new_value})); - m_output_message(); - repaint(); + if(new_value != m_value) + { + setParameter("value", tool::Parameter(tool::Parameter::Type::Float, {new_value})); + m_output_message(); + repaint(); + } } } diff --git a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberView.h b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberView.h index 11a456f8..2e2baffe 100644 --- a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberView.h +++ b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberView.h @@ -61,6 +61,8 @@ namespace kiwi { private: // methods + void drawIcon (juce::Graphics& g) const override; + //! @brief Stores the initial value before draging. void mouseDown(juce::MouseEvent const& e) override final; diff --git a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberViewBase.cpp b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberViewBase.cpp index f62d1400..abee5c69 100644 --- a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberViewBase.cpp +++ b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberViewBase.cpp @@ -30,11 +30,10 @@ namespace kiwi { // NUMBER VIEW BASE // // ================================================================================ // - NumberViewBase::NumberViewBase(model::Object & object_model) : - EditableObjectView(object_model), - m_value(0), - m_indent(9), - m_icon_colour(findColour (ObjectView::ColourIds::Outline)) + NumberViewBase::NumberViewBase(model::Object & object_model) + : EditableObjectView(object_model) + , m_value(0) + , m_indent(9) { juce::Label & label = getLabel(); @@ -65,18 +64,12 @@ namespace kiwi { g.setColour (findColour (ObjectView::ColourIds::Outline)); drawOutline(g); - - juce::Path corner; - - g.setColour(m_icon_colour); - - juce::Rectangle triangle_bounds = getLocalBounds().withWidth(m_indent - 4).withHeight(getHeight() - 8).translated(2, 4); - - corner.addTriangle(triangle_bounds.getTopLeft().toFloat(), - triangle_bounds.getTopRight().toFloat() + juce::Point(0, (triangle_bounds.getHeight() / 2.)), - triangle_bounds.getBottomLeft().toFloat()); - - g.fillPath(corner); + drawIcon(g); + } + + void NumberViewBase::drawIcon (juce::Graphics& g) const + { + // nothing by default } void NumberViewBase::resized() @@ -86,11 +79,6 @@ namespace kiwi { getLabel().setBounds(label_bounds); } - void NumberViewBase::setIconColour(juce::Colour colour) - { - m_icon_colour = colour; - } - double NumberViewBase::getDisplayNumber() const { return m_value; diff --git a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberViewBase.h b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberViewBase.h index 8a03f84f..aed12c4c 100644 --- a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberViewBase.h +++ b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberViewBase.h @@ -50,9 +50,7 @@ namespace kiwi { //! @brief Returns the displayed text as a number. double getDisplayNumber() const; - //! @brief Sets the triangle icon colour. - //! @details By default colour is outline colour. - void setIconColour(juce::Colour colour); + virtual void drawIcon (juce::Graphics& g) const; private: // methods @@ -78,11 +76,10 @@ namespace kiwi { //! @details Overrides EditableOjectView::createTextEditor. juce::TextEditor* createdTextEditor() override final; - private: // members + protected: // members double m_value; int m_indent; - juce::Colour m_icon_colour; private: // deleted methods From 1909594860354a711574450cca7b48fc3418fef3 Mon Sep 17 00:00:00 2001 From: eliott PARIS Date: Wed, 23 May 2018 10:54:03 +0200 Subject: [PATCH 07/19] [number] - improve decimal drag --- .../KiwiApp_Objects/KiwiApp_NumberView.cpp | 120 +++++++++++------- .../KiwiApp_Objects/KiwiApp_NumberView.h | 18 +-- .../KiwiApp_NumberViewBase.cpp | 4 +- 3 files changed, 83 insertions(+), 59 deletions(-) diff --git a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberView.cpp b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberView.cpp index 7d4f4ad5..2d0faa02 100644 --- a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberView.cpp +++ b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberView.cpp @@ -43,15 +43,12 @@ namespace kiwi { NumberView::NumberView(model::Object & object_model) : NumberViewBase(object_model) , m_output_message(object_model.getSignal<>(model::Message::Signal::outputMessage)) - , m_sensitivity(1) - , m_mouse_info() { setInterceptsMouseClicks(true, true); } NumberView::~NumberView() - { - } + {} void NumberView::drawIcon (juce::Graphics& g) const { @@ -79,50 +76,87 @@ namespace kiwi { { e.source.enableUnboundedMouseMovement(true, true); - m_mouse_info.m_mouse_down_value = getDisplayNumber(); - m_mouse_info.m_mouse_down_y = e.y; + m_last_drag_pos = e.position; + m_drag_value = m_value; + + auto const& label = getLabel(); + const auto textArea = label.getBorderSize().subtractedFrom(label.getBounds()); + + juce::GlyphArrangement glyphs; + glyphs.addFittedText (label.getFont(), label.getText(), + textArea.getX(), 0., textArea.getWidth(), getHeight(), + juce::Justification::centredLeft, 1, + label.getMinimumHorizontalScale()); - if (e.mods.isShiftDown()) + double decimal_x = getWidth(); + for(int i = 0; i < glyphs.getNumGlyphs(); ++i) { - m_mouse_info.m_is_alt_down = true; - m_mouse_info.m_alt_down_value = getDisplayNumber(); - m_mouse_info.m_alt_down_y = e.y; + auto const& glyph = glyphs.getGlyph(i); + if(glyph.getCharacter() == '.') + { + decimal_x = glyph.getRight(); + } } - } - - void NumberView::mouseDrag(juce::MouseEvent const& e) - { - if (e.getDistanceFromDragStartY() != 0) + + const bool is_dragging_decimal = e.x > decimal_x; + + m_decimal_drag = is_dragging_decimal ? 6 : 0; + + if(is_dragging_decimal) { - double new_value = m_value; + juce::GlyphArrangement decimals_glyph; + static const juce::String decimals_str("000000"); - if (!m_mouse_info.m_is_alt_down && e.mods.isShiftDown()) - { - m_mouse_info.m_is_alt_down = true; - m_mouse_info.m_alt_down_value = getDisplayNumber(); - m_mouse_info.m_alt_down_y = e.y; - } - else if(m_mouse_info.m_is_alt_down && !e.mods.isShiftDown()) - { - m_mouse_info.m_mouse_down_value = getDisplayNumber(); - m_mouse_info.m_mouse_down_y = e.y; - m_mouse_info.m_is_alt_down = false; - m_mouse_info.m_is_alt_down = 0; - m_mouse_info.m_alt_down_y = 0; - } + decimals_glyph.addFittedText (label.getFont(), decimals_str, + decimal_x, 0, getWidth(), getHeight(), + juce::Justification::centredLeft, 1, + label.getMinimumHorizontalScale()); - if (e.mods.isShiftDown()) + for(int i = 0; i < decimals_glyph.getNumGlyphs(); ++i) { - new_value = m_mouse_info.m_alt_down_value - (m_sensitivity * (e.y - m_mouse_info.m_alt_down_y)) / 100.; - } - else - { - new_value = m_mouse_info.m_mouse_down_value - m_sensitivity * (e.y - m_mouse_info.m_mouse_down_y); + auto const& glyph = decimals_glyph.getGlyph(i); + if(e.x <= glyph.getRight()) + { + m_decimal_drag = i+1; + break; + } } + } + } + + void NumberView::mouseDrag(juce::MouseEvent const& e) + { + setMouseCursor(juce::MouseCursor::NoCursor); + updateMouseCursor(); + + if (e.mouseWasDraggedSinceMouseDown()) + { + const int decimal = m_decimal_drag + e.mods.isShiftDown(); + const double increment = (decimal == 0) ? 1. : (1. / std::pow(10., decimal)); + const double delta_y = e.y - m_last_drag_pos.y; + m_last_drag_pos = e.position; - if(new_value != m_value) + m_drag_value += increment * -delta_y; + + if(m_drag_value != m_value) { - setParameter("value", tool::Parameter(tool::Parameter::Type::Float, {new_value})); + // truncate value and set + + double new_value = m_drag_value; + + if(decimal > 0) + { + const int sign = (new_value > 0) ? 1 : -1; + unsigned int ui_temp = (new_value * std::pow(10, decimal)) * sign; + new_value = (((double)ui_temp)/std::pow(10, decimal) * sign); + } + else + { + new_value = static_cast(new_value); + } + + setParameter("value", + tool::Parameter(tool::Parameter::Type::Float, {new_value})); m_output_message(); repaint(); } @@ -131,11 +165,11 @@ namespace kiwi { void NumberView::mouseUp(juce::MouseEvent const& e) { - m_mouse_info.m_mouse_down_value = 0; - m_mouse_info.m_mouse_down_y = 0; - m_mouse_info.m_is_alt_down = false; - m_mouse_info.m_alt_down_value = 0; - m_mouse_info.m_alt_down_y = 0; + setMouseCursor(juce::MouseCursor::NormalCursor); + updateMouseCursor(); + + juce::Desktop::getInstance() + .getMainMouseSource().setScreenPosition(e.getMouseDownScreenPosition().toFloat()); } void NumberView::parameterChanged(std::string const& name, tool::Parameter const& param) diff --git a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberView.h b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberView.h index 2e2baffe..1c6e2b5a 100644 --- a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberView.h +++ b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberView.h @@ -34,17 +34,6 @@ namespace kiwi { //! @brief The view of any textual kiwi object. class NumberView : public NumberViewBase { - private: // members - - struct MouseInfo - { - double m_mouse_down_value = 0; - int m_mouse_down_y = 0; - bool m_is_alt_down = false; - double m_alt_down_value = 0; - int m_alt_down_y = 0; - }; - public: // methods // @brief The declaration method. @@ -83,9 +72,10 @@ namespace kiwi { private: // members - flip::Signal<> & m_output_message; - int m_sensitivity; - MouseInfo m_mouse_info; + flip::Signal<>& m_output_message; + int m_decimal_drag = 0; + juce::Point m_last_drag_pos {}; + double m_drag_value = 0; private: // deleted methods diff --git a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberViewBase.cpp b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberViewBase.cpp index abee5c69..08c03281 100644 --- a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberViewBase.cpp +++ b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberViewBase.cpp @@ -89,7 +89,7 @@ namespace kiwi { m_value = number; juce::String display_value(std::to_string(m_value)); - + display_value = display_value.trimCharactersAtEnd("0"); getLabel().setText(display_value, juce::NotificationType::dontSendNotification); @@ -97,7 +97,7 @@ namespace kiwi { void NumberViewBase::textChanged() { - m_value = getLabel().getText().getFloatValue(); + m_value = getLabel().getText().getDoubleValue(); displayNumberChanged(m_value); } From 473fa95a43d7fc3df0036902ab1d64ac9aa40bc1 Mon Sep 17 00:00:00 2001 From: eliott PARIS Date: Wed, 23 May 2018 18:12:24 +0200 Subject: [PATCH 08/19] [random] clean and bug-fix: - default range is 0 (was 100) - output random value between 0 and range-1 (was 0 and range) - fix warning message typo - default seed is 0 (was 1) - a seed of 0 means that it is initialized with an unpredictable time value. - seed can now be set --- .../KiwiEngine_Objects/KiwiEngine_Random.cpp | 48 +++++++++---------- .../KiwiEngine_Objects/KiwiEngine_Random.h | 14 ++++-- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Random.cpp b/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Random.cpp index 4e143b0f..97f1d1c8 100644 --- a/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Random.cpp +++ b/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Random.cpp @@ -41,24 +41,13 @@ namespace kiwi { namespace engine { return std::make_unique(model, patcher); } - Random::Random(model::Object const& model, Patcher& patcher): - Object(model, patcher), - m_random_generator(), - m_random_distribution(0, 100) + Random::Random(model::Object const& model, Patcher& patcher) + : Object(model, patcher) { - m_random_generator.seed(1); + auto const& args = model.getArguments(); - std::vector const& args = model.getArguments(); - - if (args.size() > 0 && args[0].isNumber()) - { - setRange(args[0].getInt()); - } - - if (args.size() > 1 && args[1].isNumber()) - { - setSeed(args[1].getInt()); - } + setRange((args.size() > 0 && args[0].isNumber()) ? args[0].getInt() : 0ll); + setSeed((args.size() > 1 && args[1].isNumber()) ? args[1].getInt() : 0ll); } void Random::receive(size_t index, std::vector const& args) @@ -67,11 +56,11 @@ namespace kiwi { namespace engine { { if (args[0].isBang()) { - send(0, {m_random_distribution(m_random_generator)}); + send(0, {getNextRandomValue()}); } else { - warning("random inlet 1 only understand bang"); + warning("random: inlet 1 only understand bang"); } } else if (index == 1) @@ -82,7 +71,7 @@ namespace kiwi { namespace engine { } else { - warning("random inlet 2 only understand numbers"); + warning("random: inlet 2 only understand numbers"); } } else if (index == 2) @@ -93,18 +82,29 @@ namespace kiwi { namespace engine { } else { - warning("random inlet 2 only understand numbers"); + warning("random: inlet 3 only understand numbers"); } } } - void Random::setRange(int range) + void Random::setRange(int64_t range) { - m_random_distribution.param(std::uniform_int_distribution::param_type(0, std::max(0, range))); + m_random_distribution.param(rnd_distribution_t::param_type(0ll, std::max(0ll, range - 1))); + } + + void Random::setSeed(int64_t seed) + { + if(seed == 0) + { + // obtain a seed from the timer + seed = (clock_t::now() - m_start_time).count(); + } + + m_random_generator.seed(seed); } - void Random::setSeed(int seed) + int64_t Random::getNextRandomValue() { - m_random_generator.seed(); + return m_random_distribution(m_random_generator); } }} diff --git a/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Random.h b/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Random.h index cd21fd12..052b1f5d 100644 --- a/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Random.h +++ b/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Random.h @@ -23,6 +23,7 @@ #include +#include #include namespace kiwi { namespace engine { @@ -45,14 +46,19 @@ namespace kiwi { namespace engine { private: // methods - void setRange(int range); + void setRange(int64_t range); + void setSeed(int64_t new_seed); - void setSeed(int new_seed); + int64_t getNextRandomValue(); private: // members - std::mt19937 m_random_generator; - std::uniform_int_distribution m_random_distribution; + using clock_t = std::chrono::high_resolution_clock; + using rnd_distribution_t = std::uniform_int_distribution; + + clock_t::time_point m_start_time { clock_t::now() }; + std::mt19937 m_random_generator {}; + rnd_distribution_t m_random_distribution {0ll, 0ll}; }; }} From 706ea81c3bc52913492967b0219114b4c873d423 Mon Sep 17 00:00:00 2001 From: eliott PARIS Date: Thu, 24 May 2018 12:05:15 +0200 Subject: [PATCH 09/19] [random] - fix typo --- .../KiwiEngine/KiwiEngine_Objects/KiwiEngine_Random.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Random.cpp b/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Random.cpp index 97f1d1c8..25ab1887 100644 --- a/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Random.cpp +++ b/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Random.cpp @@ -60,7 +60,7 @@ namespace kiwi { namespace engine { } else { - warning("random: inlet 1 only understand bang"); + warning("random: inlet 1 only understands bang"); } } else if (index == 1) @@ -71,7 +71,7 @@ namespace kiwi { namespace engine { } else { - warning("random: inlet 2 only understand numbers"); + warning("random: inlet 2 only understands numbers"); } } else if (index == 2) @@ -82,14 +82,14 @@ namespace kiwi { namespace engine { } else { - warning("random: inlet 3 only understand numbers"); + warning("random: inlet 3 only understands numbers"); } } } void Random::setRange(int64_t range) { - m_random_distribution.param(rnd_distribution_t::param_type(0ll, std::max(0ll, range - 1))); + m_random_distribution.param(rnd_distribution_t::param_type(0, std::max(0, range - 1))); } void Random::setSeed(int64_t seed) From 0296c4d733c7184b75a03a0cd360e65e469f057e Mon Sep 17 00:00:00 2001 From: eliott PARIS Date: Thu, 24 May 2018 15:44:04 +0200 Subject: [PATCH 10/19] [hub] - disable message in undo --- .../KiwiModel_Objects/KiwiModel_Hub.cpp | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/Modules/KiwiModel/KiwiModel_Objects/KiwiModel_Hub.cpp b/Modules/KiwiModel/KiwiModel_Objects/KiwiModel_Hub.cpp index 68097e2a..d5a5c4e0 100755 --- a/Modules/KiwiModel/KiwiModel_Objects/KiwiModel_Hub.cpp +++ b/Modules/KiwiModel/KiwiModel_Objects/KiwiModel_Hub.cpp @@ -31,20 +31,20 @@ namespace kiwi { namespace model { void Hub::declare() { // Objectclass - std::unique_ptr hub_class(new ObjectClass("hub", &Hub::create)); + auto kiwi_class = std::make_unique("hub", &Hub::create); // Parameters - std::unique_ptr param_message(new ParameterClass(tool::Parameter::Type::String)); + auto param_message = std::make_unique(tool::Parameter::Type::String); - hub_class->addAttribute("message", std::move(param_message)); + kiwi_class->addAttribute("message", std::move(param_message)); // DataModel - flip::Class & hub_model = DataModel::declare() - .name(hub_class->getModelName().c_str()) - .inherit() - .member, &Hub::m_message>("message"); + auto& flip_class = DataModel::declare() + .name(kiwi_class->getModelName().c_str()) + .inherit() + .member, &Hub::m_message>("message"); - Factory::add(std::move(hub_class), hub_model); + Factory::add(std::move(kiwi_class), flip_class); } std::unique_ptr Hub::create(std::vector const& args) @@ -52,21 +52,24 @@ namespace kiwi { namespace model { return std::make_unique(args); } - Hub::Hub(std::vector const& args): - Object(), - m_message() + Hub::Hub(std::vector const& args) + : Object() + , m_message() { if (args.size() > 0) throw Error("message too many arguments"); pushInlet({PinType::IType::Control}); pushOutlet(PinType::IType::Control); + + m_message.disable_in_undo(); } - Hub::Hub(flip::Default& d): - Object(d), - m_message() + Hub::Hub(flip::Default& d) + : Object(d) + , m_message() { + m_message.disable_in_undo(); } void Hub::writeAttribute(std::string const& name, tool::Parameter const& parameter) From ea9d10d9949508c442e95fc69114055d78c54fcb Mon Sep 17 00:00:00 2001 From: eliott PARIS Date: Thu, 24 May 2018 15:45:37 +0200 Subject: [PATCH 11/19] Use document to retrieve the object model from ref in the engine::Object --- Modules/KiwiEngine/KiwiEngine_Object.cpp | 26 ++++++++----------- Modules/KiwiEngine/KiwiEngine_Object.h | 4 +-- .../KiwiEngine_Objects/KiwiEngine_Hub.cpp | 5 +--- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/Modules/KiwiEngine/KiwiEngine_Object.cpp b/Modules/KiwiEngine/KiwiEngine_Object.cpp index 34582f98..3f97bf7c 100644 --- a/Modules/KiwiEngine/KiwiEngine_Object.cpp +++ b/Modules/KiwiEngine/KiwiEngine_Object.cpp @@ -81,14 +81,10 @@ namespace kiwi }); } - model::Object & Object::getObjectModel() + model::Object& Object::getObjectModel() { - flip::Array & objects = m_patcher.getPatcherModel().getObjects(); - - return *std::find_if(objects.begin(), objects.end(), [this](model::Object const & object_model) - { - return object_model.ref() == m_ref; - }); + return m_patcher.getPatcherModel().document() + .object(m_ref); } void Object::parameterChanged(std::string const& param_name, tool::Parameter const& param) @@ -99,20 +95,20 @@ namespace kiwi { } - void Object::setAttribute(std::string const& name, tool::Parameter const& param) + void Object::setAttribute(std::string const& name, tool::Parameter && param) { - deferMain([this, name, param]() - { - getObjectModel().setAttribute(name, param); + deferMain([this, name, param {std::move(param)}]() { + + auto& object_model = getObjectModel(); + object_model.setAttribute(name, param); + model::DocumentManager::commit(object_model); - model::DocumentManager::commit(getObjectModel()); }); } - void Object::setParameter(std::string const& name, tool::Parameter const& param) + void Object::setParameter(std::string const& name, tool::Parameter && param) { - deferMain([this, name, param] - { + deferMain([this, name, param {std::move(param)}]() { getObjectModel().setParameter(name, param); }); } diff --git a/Modules/KiwiEngine/KiwiEngine_Object.h b/Modules/KiwiEngine/KiwiEngine_Object.h index 9eec2937..3dabd993 100644 --- a/Modules/KiwiEngine/KiwiEngine_Object.h +++ b/Modules/KiwiEngine/KiwiEngine_Object.h @@ -140,11 +140,11 @@ namespace kiwi //! @brief Changes one of the data model's attributes. //! @details For thread safety actual model's modification is called on the main thread. - void setAttribute(std::string const& name, tool::Parameter const& parameter); + void setAttribute(std::string const& name, tool::Parameter && parameter); //! @brief Changes one of the data model's parameter. //! @details For thread safety actual model's modification is called on the main thread. - void setParameter(std::string const& name, tool::Parameter const& parameter); + void setParameter(std::string const& name, tool::Parameter && parameter); private: // methods diff --git a/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Hub.cpp b/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Hub.cpp index 2f987b86..46f6b382 100644 --- a/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Hub.cpp +++ b/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Hub.cpp @@ -62,11 +62,8 @@ namespace kiwi { namespace engine { { if (index == 0 && !args.empty()) { - setAttribute("message", - tool::Parameter(tool::Parameter::Type::String, - {tool::AtomHelper::toString(args)})); + setAttribute("message", { tool::Parameter::Type::String, {tool::AtomHelper::toString(args)}}); } } }} - From 6adc2bddb93f06d76e730d7db817f7429de474f4 Mon Sep 17 00:00:00 2001 From: eliott PARIS Date: Thu, 24 May 2018 15:47:55 +0200 Subject: [PATCH 12/19] Add a commit label when an attribute has been changed by the view => allow undo/redo of [message] and [comment] text edition. --- .../KiwiApp_Objects/KiwiApp_ObjectView.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_ObjectView.cpp b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_ObjectView.cpp index c6341f96..acf2f4c0 100644 --- a/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_ObjectView.cpp +++ b/Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_ObjectView.cpp @@ -55,11 +55,11 @@ namespace kiwi void ObjectView::setAttribute(std::string const& name, tool::Parameter const& parameter) { - model::Object & object_model = getModel(); - - object_model.setAttribute(name, parameter); - - model::DocumentManager::commit(object_model); + model::Object& object_model = getModel(); + object_model.setAttribute(name, parameter); + + const auto commit_msg = object_model.getName() + " \"" + name + "\" changed"; + model::DocumentManager::commit(object_model, commit_msg); } void ObjectView::setParameter(std::string const& name, tool::Parameter const& parameter) From 7cad3a2fdfb6f16a4d7f87a06dcc5a2fb7d2ba65 Mon Sep 17 00:00:00 2001 From: eliott PARIS Date: Thu, 24 May 2018 20:17:04 +0200 Subject: [PATCH 13/19] fix unsupported lambda capture by move syntax on linux --- Modules/KiwiEngine/KiwiEngine_Object.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/KiwiEngine/KiwiEngine_Object.cpp b/Modules/KiwiEngine/KiwiEngine_Object.cpp index 3f97bf7c..b1db1b60 100644 --- a/Modules/KiwiEngine/KiwiEngine_Object.cpp +++ b/Modules/KiwiEngine/KiwiEngine_Object.cpp @@ -97,7 +97,7 @@ namespace kiwi void Object::setAttribute(std::string const& name, tool::Parameter && param) { - deferMain([this, name, param {std::move(param)}]() { + deferMain([this, name, param = std::move(param)]() { auto& object_model = getObjectModel(); object_model.setAttribute(name, param); @@ -108,7 +108,7 @@ namespace kiwi void Object::setParameter(std::string const& name, tool::Parameter && param) { - deferMain([this, name, param {std::move(param)}]() { + deferMain([this, name, param = std::move(param)]() { getObjectModel().setParameter(name, param); }); } From fef64303c36388e13953f48be249d2476e944be7 Mon Sep 17 00:00:00 2001 From: eliott PARIS Date: Thu, 31 May 2018 17:17:21 +0200 Subject: [PATCH 14/19] Remove "kiwi::model" text prefix in model::Error --- Modules/KiwiModel/KiwiModel_Error.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Modules/KiwiModel/KiwiModel_Error.h b/Modules/KiwiModel/KiwiModel_Error.h index 3fdcd760..99b57d50 100644 --- a/Modules/KiwiModel/KiwiModel_Error.h +++ b/Modules/KiwiModel/KiwiModel_Error.h @@ -33,12 +33,14 @@ namespace kiwi { namespace model { public: //! @brief The std::string constructor. - explicit Error(const std::string& message) : - std::runtime_error(std::string("kiwi::model ") + message) {} + explicit Error(std::string const& message) + : std::runtime_error(message) + {} //! @brief The const char* constructor. - explicit Error(const char* message) : - std::runtime_error(std::string("kiwi::model ") + std::string(message)) {} + explicit Error(const char* message) + : std::runtime_error(std::string(message)) + {} //! @brief The destructor. virtual inline ~Error() noexcept = default; From a3ed67afbde777ebc3ea5cdef114c9d555e10b78 Mon Sep 17 00:00:00 2001 From: eliott PARIS Date: Thu, 31 May 2018 17:19:57 +0200 Subject: [PATCH 15/19] [random] - remove seed inlet and add a seed method, remove range inlet when the range argument is specified --- .../KiwiEngine_Objects/KiwiEngine_Random.cpp | 27 ++++++------ .../KiwiModel_Objects/KiwiModel_Random.cpp | 41 ++++++++++--------- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Random.cpp b/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Random.cpp index 25ab1887..7ef8c638 100644 --- a/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Random.cpp +++ b/Modules/KiwiEngine/KiwiEngine_Objects/KiwiEngine_Random.cpp @@ -52,15 +52,29 @@ namespace kiwi { namespace engine { void Random::receive(size_t index, std::vector const& args) { + if(args.empty()) + return; // abort + if (index == 0) { if (args[0].isBang()) { send(0, {getNextRandomValue()}); } + else if (args[0].getString() == "seed") + { + if(args.size() > 1 && args[1].isNumber()) + { + setSeed(args[1].getInt()); + } + else + { + warning("random: seed message must be followed by an integer"); + } + } else { - warning("random: inlet 1 only understands bang"); + warning("random: inlet 1 only understands bang or seed message"); } } else if (index == 1) @@ -74,17 +88,6 @@ namespace kiwi { namespace engine { warning("random: inlet 2 only understands numbers"); } } - else if (index == 2) - { - if (args[0].isNumber()) - { - setSeed(args[0].getInt()); - } - else - { - warning("random: inlet 3 only understands numbers"); - } - } } void Random::setRange(int64_t range) diff --git a/Modules/KiwiModel/KiwiModel_Objects/KiwiModel_Random.cpp b/Modules/KiwiModel/KiwiModel_Objects/KiwiModel_Random.cpp index b1e45c5b..346b436d 100755 --- a/Modules/KiwiModel/KiwiModel_Objects/KiwiModel_Random.cpp +++ b/Modules/KiwiModel/KiwiModel_Objects/KiwiModel_Random.cpp @@ -30,11 +30,13 @@ namespace kiwi { namespace model { void Random::declare() { - std::unique_ptr random_class(new ObjectClass("random", &Random::create)); + auto kiwi_class = std::make_unique("random", &Random::create); - flip::Class & random_model = DataModel::declare().name(random_class->getModelName().c_str()).inherit(); + auto& flip_class = DataModel::declare() + .name(kiwi_class->getModelName().c_str()) + .inherit(); - Factory::add(std::move(random_class), random_model); + Factory::add(std::move(kiwi_class), flip_class); } std::unique_ptr Random::create(std::vector const& args) @@ -46,22 +48,25 @@ namespace kiwi { namespace model { { if (args.size() > 2) { - throw Error("random too many arguments"); + throw Error("random: too many arguments"); } - if (args.size() > 1 && !args[1].isNumber()) + if (args.size() > 0 && !args[0].isNumber()) { - throw Error("random seed argument must be a number"); + throw Error("random: range argument must be a number"); } - if (args.size() > 0 && !args[0].isNumber()) + if (args.size() > 1 && !args[1].isNumber()) { - throw Error("random range argument must be a number"); + throw Error("random: seed argument must be a number"); } - pushInlet({PinType::IType::Control}); - pushInlet({PinType::IType::Control}); - pushInlet({PinType::IType::Control}); + pushInlet({PinType::IType::Control}); // bang or seed message inlet + + if (args.size() == 0) + { + pushInlet({PinType::IType::Control}); // range inlet + } pushOutlet(PinType::IType::Control); } @@ -72,23 +77,19 @@ namespace kiwi { namespace model { { if (index == 0) { - return "bang causes random number generation"; + return "bang causes random number generation, seed sets the seed"; } else if (index == 1) { - return "Sets the range"; - } - else if (index == 2) - { - return "Sets the seed"; + return "Sets the maximum range (exclusive)"; } } - else + else if(index == 0) { - return "Ouputs ramdom number"; + return "Outputs random number"; } - return ""; + return {}; } }} From b8bc9d87eafe1b9aedd46c40bbd3582ffadf7082 Mon Sep 17 00:00:00 2001 From: eliott PARIS Date: Thu, 31 May 2018 17:21:41 +0200 Subject: [PATCH 16/19] Increment data model version to v4 and add v3 to v4 converter --- .../KiwiModel_Converter.cpp | 136 ++++++++++++++++-- .../KiwiModel_Converter.h | 10 +- Modules/KiwiModel/KiwiModel_Def.h | 2 +- 3 files changed, 131 insertions(+), 17 deletions(-) diff --git a/Modules/KiwiModel/KiwiModel_Converters/KiwiModel_Converter.cpp b/Modules/KiwiModel/KiwiModel_Converters/KiwiModel_Converter.cpp index 355bf162..1b1c4457 100755 --- a/Modules/KiwiModel/KiwiModel_Converters/KiwiModel_Converter.cpp +++ b/Modules/KiwiModel/KiwiModel_Converters/KiwiModel_Converter.cpp @@ -24,6 +24,8 @@ #include #include +#include + namespace kiwi { namespace model { // ================================================================================ // @@ -32,7 +34,7 @@ namespace kiwi { namespace model { void Converter::convert_v1_v2(flip::BackEndIR & backend) { - flip::BackEndIR::Type & patcher = backend.root; + flip::BackEndIR::Type& patcher = backend.root; // removing patcher name. patcher.members.remove_if([](std::pair const& member) @@ -40,34 +42,142 @@ namespace kiwi { namespace model { return member.first == "patcher_name"; }); - backend.version = "v2"; + backend.complete_conversion("v2"); } - bool Converter::process(flip::BackEndIR & backend) + void Converter::convert_v3_v4(flip::BackEndIR & backend) + { + flip::BackEndIR::Type& patcher = backend.root; + + // random object conversion: + // - remove seed inlet (was third inlet in < v4) + // - remove range inlet (second) if range argument is defined + + walk(patcher, [](flip::BackEndIR::Type& type) { + + if (type.get_class () != "cicm.kiwi.object.random") + return; // abort + + auto const& text_value = type.member("text").second.value.blob; + const std::string text { text_value.begin(), text_value.end() }; + const auto parsed_text = tool::AtomHelper::parse(text); + + auto& inlets = type.member("inlets").second.array; + + if(inlets.size() == 3) + { + inlets.erase(inlets.begin()); + + const bool has_range_arg = (parsed_text.size() > 1 + && parsed_text[1].isNumber()); + if(has_range_arg) + { + inlets.erase(inlets.begin()); + } + } + }); + + backend.complete_conversion("v4"); + } + + void Converter::remove_invalid_links(flip::BackEndIR& backend) { - bool success = false; + flip::BackEndIR::Type& patcher = backend.root; + + auto& objects = patcher.member("objects").second.array; + + // A link is considered invalid if sender or receiver object does not exist, + // or if it's bound to a pin that does not exist. + auto is_invalid_link = [&objects](flip::BackEndIR::Type& type) { + + auto const& sender_ref = type.member("sender_obj").second.value.ref; + auto const& receiver_ref = type.member("receiver_obj").second.value.ref; + auto const& sender_outlet = type.member("outlet_index").second.value.int_num; + auto const& receiver_inlet = type.member("inlet_index").second.value.int_num; + + bool sender_found = false; + bool receiver_found = false; + + // check sender validity + for(auto& object : objects) + { + auto& type = object.second; + + if(!sender_found && type.ref == sender_ref) + { + sender_found = true; + + const auto outlet_count = type.member("outlets").second.array.size(); + if(sender_outlet >= outlet_count) + { + // bad outlet + return true; + } + } + + if(!receiver_found && type.ref == receiver_ref) + { + receiver_found = true; + + const auto inlet_count = type.member("inlets").second.array.size(); + if(receiver_inlet >= inlet_count) + { + // bad inlet + return true; + } + } + + if(sender_found && receiver_found) + { + break; + } + } + + return (!sender_found || !receiver_found); + }; - process_rollback(backend); + auto& links = patcher.member("links").second.array; + auto iter = links.begin(); + const auto end_iter = links.cend(); + for(; iter != end_iter;) + { + if (is_invalid_link(iter->second)) + { + links.erase(iter++); + } + else + { + ++iter; + } + } + } + + bool Converter::process(flip::BackEndIR & backend) + { std::string current_version(KIWI_MODEL_VERSION_STRING); if (current_version.compare(backend.version) >= 0) { - if (backend.version.compare("v1") == 0) + if (backend.version == "v1") { convert_v1_v2(backend); } - if (backend.version.compare("v2") == 0 || backend.version.compare("v3") == 0) + // no change from v2 to v3 ! + + if (backend.version == "v2") + { + backend.complete_conversion("v3"); + } + + if (backend.version == "v3") { - success = true; + convert_v3_v4(backend); + remove_invalid_links(backend); } } - return success; - } - - void Converter::process_rollback(flip::BackEndIR & backend) - { + return (backend.version == current_version); } }} diff --git a/Modules/KiwiModel/KiwiModel_Converters/KiwiModel_Converter.h b/Modules/KiwiModel/KiwiModel_Converters/KiwiModel_Converter.h index 20fe00ff..e39e491e 100755 --- a/Modules/KiwiModel/KiwiModel_Converters/KiwiModel_Converter.h +++ b/Modules/KiwiModel/KiwiModel_Converters/KiwiModel_Converter.h @@ -42,9 +42,13 @@ namespace kiwi { namespace model { private: // methods //! @brief Converts a v1 data model to a v2 data model. - static void convert_v1_v2(flip::BackEndIR & backend); + static void convert_v1_v2(flip::BackEndIR& backend); - //! @brief Rollbacks depecrated revisions. - static void process_rollback(flip::BackEndIR & backend); + //! @brief Converts a v3 data model to a v4 data model. + static void convert_v3_v4(flip::BackEndIR& backend); + + //! @brief Removes invalid links + static void remove_invalid_links(flip::BackEndIR& backend); }; + }} diff --git a/Modules/KiwiModel/KiwiModel_Def.h b/Modules/KiwiModel/KiwiModel_Def.h index e78c0eac..edea2518 100644 --- a/Modules/KiwiModel/KiwiModel_Def.h +++ b/Modules/KiwiModel/KiwiModel_Def.h @@ -21,4 +21,4 @@ #pragma once -#define KIWI_MODEL_VERSION_STRING "v3" +#define KIWI_MODEL_VERSION_STRING "v4" From 59c6e1e33a8b9cbff53b06fe44a67f70d9e226f1 Mon Sep 17 00:00:00 2001 From: eliott PARIS Date: Thu, 31 May 2018 17:22:19 +0200 Subject: [PATCH 17/19] set Kiwi App version to 1.0.1 --- Ressources/Project/Xcode/Info.plist | 4 ++-- Scripts/setup-Win32.iss | 3 +-- Scripts/setup-x64.iss | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Ressources/Project/Xcode/Info.plist b/Ressources/Project/Xcode/Info.plist index 6e2eecc1..9e33453b 100755 --- a/Ressources/Project/Xcode/Info.plist +++ b/Ressources/Project/Xcode/Info.plist @@ -15,9 +15,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0.0 + 1.0.1 CFBundleVersion - 1.0.0 + 1.0.1 NSHighResolutionCapable NSHumanReadableCopyright diff --git a/Scripts/setup-Win32.iss b/Scripts/setup-Win32.iss index 1578fb46..2d8710e4 100644 --- a/Scripts/setup-Win32.iss +++ b/Scripts/setup-Win32.iss @@ -2,7 +2,7 @@ ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! #define MyAppName "Kiwi" -#define MyAppVersion "v1.0.0-beta" +#define MyAppVersion "v1.0.1" #define MyAppPublisher "CICM" #define MyAppURL "http://kiwi.mshparisnord.fr/" #define MyAppExeName "Kiwi.exe" @@ -61,4 +61,3 @@ Root: HKCR; Subkey: "{#MyAppName}\shell\open\command"; ValueData: """{app}\{#My [Run] Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent - diff --git a/Scripts/setup-x64.iss b/Scripts/setup-x64.iss index 092da3f3..d51909f6 100644 --- a/Scripts/setup-x64.iss +++ b/Scripts/setup-x64.iss @@ -2,7 +2,7 @@ ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! #define MyAppName "Kiwi" -#define MyAppVersion "v1.0.0-beta" +#define MyAppVersion "v1.0.1" #define MyAppPublisher "CICM" #define MyAppURL "http://kiwi.mshparisnord.fr/" #define MyAppExeName "Kiwi.exe" @@ -61,4 +61,3 @@ Root: HKCR; Subkey: "{#MyAppName}\shell\open\command"; ValueData: """{app}\{#My [Run] Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent - From f0d8ba0c445249646abba2ebe2600d6af2b65932 Mon Sep 17 00:00:00 2001 From: eliott PARIS Date: Fri, 1 Jun 2018 12:25:48 +0200 Subject: [PATCH 18/19] update documentation --- Client/Source/KiwiApp.h | 4 ++-- docs/developper/dev.md | 4 ++-- docs/software/getting-started.md | 9 ++++----- docs/software/objects.md | 30 +++++++++++++++--------------- docs/software/versions.md | 31 +++++++++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 24 deletions(-) diff --git a/Client/Source/KiwiApp.h b/Client/Source/KiwiApp.h index 098e8547..ac7cbb2f 100644 --- a/Client/Source/KiwiApp.h +++ b/Client/Source/KiwiApp.h @@ -34,8 +34,8 @@ namespace ProjectInfo { const char* const projectName = "Kiwi"; - const char* const versionString = "v1.0.0"; - const int versionNumber = 0x100; + const char* const versionString = "v1.0.1"; + const int versionNumber = 0x101; } namespace kiwi diff --git a/docs/developper/dev.md b/docs/developper/dev.md index 592ed76a..a7136821 100644 --- a/docs/developper/dev.md +++ b/docs/developper/dev.md @@ -35,7 +35,7 @@ Here is a list of tested compilers depending on your platform. - MacOs: clang 7.3.1 - Windows: msvc 19.0 -- Linus: gcc-4.9 +- Linux: gcc-4.9 ```shell python ./Script/build.py @@ -85,7 +85,7 @@ The api server also uses a json file for its settings. Its easier to use the sam ex: ```json { - "session_port": 1000, + "session_port": 1000, "backend_directory": "server_backend", "open_token": "etienned@o", "kiwi_version": "v1.0.0" diff --git a/docs/software/getting-started.md b/docs/software/getting-started.md index 421af933..31e029b8 100644 --- a/docs/software/getting-started.md +++ b/docs/software/getting-started.md @@ -10,20 +10,19 @@ Kiwi is compatible with the three main operating system. - Macos : version 10.7 and later. - Windows : windows 7 and later. -- Linus : tested with ubuntu 14.04 +- Linux : tested with ubuntu 14.04 ## Installing -Once download is complete, the corresponding archive shall be extracted by double clicking on it. A Kiwi folder containing the application is then created. On macos and linux copy the application to your app folder (Application folder on Mac, /usr/bin on linux). Windows users may execute the installer. +Once download is complete, the corresponding archive shall be extracted by double clicking on it. A Kiwi folder containing the application is then created. On macOS and linux, copy the application to your app folder (Application folder on Mac, /usr/bin on linux). Windows users may execute the installer. -## Lauching Kiwi +## Launching Kiwi -When Kiwi is executed three main windows appear : The Document Browser, the Beacon Dispatcher and Kiwi's console. +When Kiwi is executed two main windows appear : The Document Browser and the Kiwi's console. -
diff --git a/docs/software/objects.md b/docs/software/objects.md index 0d78787b..f6f464ec 100644 --- a/docs/software/objects.md +++ b/docs/software/objects.md @@ -12,15 +12,15 @@ A list of help patches describing how each object works is Date: Fri, 1 Jun 2018 12:33:25 +0200 Subject: [PATCH 19/19] readme update --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 14ac9dcb..4f5dad66 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,8 @@ Kiwi's documentation can be found [here](http://musicoll.github.io/Kiwi). Kiwi's ### Papers -- [JIM 2017](https://jim2017.sciencesconf.org/data/Eliott_Paris2017aa.pdf) (fr). +- [JIM 2017](https://hal.archives-ouvertes.fr/hal-01550190/document) (fr). +- [JIM 2018](https://hal.archives-ouvertes.fr/hal-01791492/document) (fr). ---