Skip to content

Commit

Permalink
Merge branch 'dev/v0.3.0beta'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	src/details/ofxpubsubosc_type_utils.h
#	src/ofxOscPublisher.h
  • Loading branch information
2bbb committed May 8, 2018
2 parents 603e2fb + 90c413f commit 110f24a
Show file tree
Hide file tree
Showing 19 changed files with 2,922 additions and 2,370 deletions.
77 changes: 36 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ easy utility for publish/subscribe OSC message.

## Notice

* this addon is tested with oF0.9.0~
* this addon is tested with oF0.9.8~
* if you use oF0.9.0~, then you can use `std::function<void(ofxOscMessage &)>`! detail: [API Reference](API_Reference.md#API_lambda_callback)
* **if you use oF~0.8.4, then you can use [branch:v0_1_x_oF084](../../tree/v0_1_x_oF084)**
* if you have challange spirit, please use dev/main branch.
* if you want to join development ofxPubSubOsc, open the issue and post the PR for [dev/main](tree/dev/main).
* if you have challange spirit, please use dev/vX.Y.Z branch.
* if you want to join development ofxPubSubOsc, open the issue and post the PR for dev/vX.Y.Z.

## TOC

Expand Down Expand Up @@ -72,6 +72,8 @@ public:
## <a name="SimpleAPI">Simple API Reference</a>
_API Reference is imperfect now._
#### If you want to use advanced features, see [Advanced](API_Reference.md)
### <a name="SimpleAPI_ofxSubscribeOsc">ofxSubscribeOsc</a>
Expand Down Expand Up @@ -129,6 +131,10 @@ unregister all the messages sending to _ip:port_.
**NOTE**: registable type is same to `ofxPublishOsc`. see [more ofxPublishOsc](API_Reference.md#API_ofxPublishOsc).
### <a name="SimpleAPI_ofxSendOsc">ofxSendOsc</a>
* void ofxSendOsc(const string &_ip_, int _port_, const string &_address_, Arguments && ... arguments)
## <a name="SupportedTypes">Supported types</a>
* Arithmetic is any type of Int32, Int64 or Float
Expand Down Expand Up @@ -189,13 +195,33 @@ if you use `vector<SomeType> vec;`, when `vec` will be resized every receiving O
**NOTE**: do NOT use `vector<vector<SupportedType>>`, `vector<SupportedType>[size]`
### <a name="SupportedTypes_Callback">Callback</a>
* `T (\*callback)(ofxOscMessage &)`;
* pair of `U &that`, `T (U::\*callback)(ofxOscMessage &)`;
* pair of `U \*that`, `T (U::\*callback)(ofxOscMessage &)`;
* `std::function<void(ofxOscMessage &)>`
#### Subscribe
* `std::function<R(Arguments ...)>`;
* `std::function<R(ofxOscMessage &)>`
* pair of `U &that`, `T (U::\*callback)(Arguments ...)`;
* pair of `U \*that`, `T (U::\*callback)(Arguments ...)`;
`Arguments ...` are all of types we can use in
#### Publish
* `std::function<T()>`;
* pair of `U &that`, `T (U::\*callback)()`;
* pair of `U \*that`, `T (U::\*callback)()`;
## <a name="UpdateHistory">Update history</a>
### 2018/05/08 ver 0.3.0
* refactor all for C++11
* add `ofxSendOsc`
* ofxSubscribeOsc got more flexible.
* multi arguments
* multi arguments callback
* add `ofxOscMessageEx`
### 2016/01/25 [ver 0.2.2](../../releases/tag/v0_2_2) release
* bugfix: about `ofQuaternion`'s `operator>>`, `operator<<` (issued by [musiko](https://github.com/musiko). thanks!!!)
Expand All @@ -208,39 +234,6 @@ if you use `vector<SomeType> vec;`, when `vec` will be resized every receiving O
* update exmaples (xcodeproj) for oF0.9.0
* some cleaning source and doxygen
### 2016/01/02 [ver 0.2.0](../../releases/tag/v0_2_0) release *(this version is broken)*
* *after this release, we will only test on oF0.9.0~*
* new feature: multi-subscribe, multi-publish
* `ofxSubscribeOsc` returns `ofxSubscriberIdentifier`
* `ofxPublishOsc` returns `ofxPublisherIdentifier`
* TODO: API Reference
* add iterators to [ofxOscSubscriberManager](API_Reference.md#Advanced_ofxOscSubscriberManager)
* add iterators to [ofxOscPublisherManager](API_Reference.md#Advanced_ofxOscPublisherManager)
* add all port operation to ofxUnsubscribeOsc, ofxNotifyToSubscribedOsc, ofxRemoveLeakedOscPicker
* add ofxSetLeakedOscPickerAll
* add ofxSubscribeOsc with `std::initializer_list<int> port` and `std::initializer_list<std::string> addresses`
* add iterators to [ofxOscPublisherManager](API_Reference.md#Advanced_ofxOscPublisherManager)
* add all port operation to ofxUnpublishOsc, ofxUnregisterPublishingOsc
* add feature publishing r-value. (i.e., you can do `ofxPublishOsc(host, port, "/bar", "value!!")`)
* add `const` to lambda callback (proposed by [satoruhiga](https://github.com/satoruhiga). thanks!!)
* add useful macro `SubscribeOsc(port, name)` is same as `ofxSubscribeOsc(port, "/name", name)` (porposed by [hanasaan](https://github.com/hanasaan). thanks!!)
* add `std::` prefix
* cleaning up conditional macro about oF0.8.x
* some bugfix around lambda
* TODO: update some API Documentations
### 2016/01/25 [ver 0.1.3](../../releases/tag/v0_1_3) release
* bugfix: about `ofQuaternion`'s `operator>>`, `operator<<` (issued by [musiko](https://github.com/musiko). thanks!!!)
### 2016/01/02 [ver 0.1.2](../../releases/tag/v0_1_2) release
* this is *final update added new feature, with oF0.8.4 support*
* after this release, "ver 0.1.x will only bugfie about supporting oF0.8.4
* add new feature ofxNotifyToSubscribedOsc (proposed by [satcy](https://github.com/satcy). thanks!!)
* some bugfix
### [Older update histories](Update_History.md)
Expand Down Expand Up @@ -268,6 +261,7 @@ MIT License.
* [IWATANI Nariaki](https://github.com/nariakiiwatani)
* [USAMI Takuto](https://github.com/usm916)
* [HORII Satoshi](https://github.com/satcy)
* [Tomoto Yusuke](https://github.com/yusuketomoto)
* [HANAI Yuuya](https://github.com/hanasaan)
* [musiko](https://github.com/musiko)
Expand All @@ -279,4 +273,5 @@ And please throw a pull request if you have a cool idea!!
If you get happy with using this addon, and you're rich, please donation for support continuous development.
Bitcoin: `17AbtW73aydfYH3epP8T3UDmmDCcXSGcaf`
Bitcoin: `386iAzZ7m99sMyUQjM7TrZg1Uft518zpgv`
55 changes: 55 additions & 0 deletions src/details/Publisher/ofxOscPublishCondition.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// ofxOscPublishCondition.h
//
// Created by ISHII 2bit on 2016/05/31.
//
//

#pragma once

#ifndef ofxOscPublishCondition_h
#define ofxOscPublishCondition_h

#include <string>
#include <functional>

#include "ofxPubSubOscSettings.h"

namespace ofx {
namespace PubSubOsc {
namespace Publish {
struct BasicCondition {
BasicCondition() : bPublishNow(true) {};

inline bool getCondition() { return isPublishNow() && inner_condition(); };

inline bool isPublishNow() const { return bPublishNow; };
inline void setEnablePublish(bool bEnablePublish) { this->bPublishNow = bEnablePublish; };

virtual bool inner_condition() { return true; };

using Ref = std::shared_ptr<BasicCondition>;
private:
bool bPublishNow;
};

struct Condition : BasicCondition {
Condition(bool &ref) : BasicCondition(), ref(ref) {};
virtual bool inner_condition() { return ref; };
private:
bool &ref;
};

struct ConditionFunction : BasicCondition {
ConditionFunction(std::function<bool()> getter) : BasicCondition(), getter(getter) {};
virtual bool inner_condition() { return getter(); };
private:
std::function<bool()> getter;
};

using ConditionRef = BasicCondition::Ref;
};
};
};

#endif /* ofxOscPublishCondition_h */
210 changes: 210 additions & 0 deletions src/details/Publisher/ofxOscPublishParameter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
//
// ofxOscPublishParameter.h
//
// Created by ISHII 2bit on 2016/05/31.
//
//

#pragma once

#ifndef ofxOscPublishParameter_h
#define ofxOscPublishParameter_h

#include <type_traits>
#include <functional>
#include <map>

#include "ofxPubSubOscSettings.h"
#include "ofxOscPublishCondition.h"
#include "ofxOscPublisherSetImplementation.h"

namespace ofx {
namespace PubSubOsc {
namespace Publish {
struct AbstractParameter {
AbstractParameter() : condition(new BasicCondition) {}
virtual bool write(ofxOscMessage &m, const std::string &address) {
if(!canPublish() || !isChanged()) return false;
writeForce(m, address);
return true;
}
virtual void writeForce(ofxOscMessage &m, const std::string &address) = 0;
void setCondition(ConditionRef ref) { condition = ref; };

inline void setEnablePublish(bool bEnablePublish) { condition->setEnablePublish(bEnablePublish); };
inline bool isPublishNow() const { return condition->isPublishNow(); };
protected:
bool canPublish() {
return condition->getCondition();
}
virtual bool isChanged() { return true; };
private:
ConditionRef condition;
};

using ParameterRef = std::shared_ptr<AbstractParameter>;

template <typename T, bool isCheckValue>
struct Parameter : AbstractParameter {
Parameter(T &t)
: t(t) {}

virtual void writeForce(ofxOscMessage &m, const std::string &address) {
m.setAddress(address);
set(m, get());
}
protected:
virtual bool isChanged() { return true; }
virtual type_ref<T> get() { return t; }
T &t;
};

template <typename T>
struct Parameter<T, true> : Parameter<T, false> {
Parameter(T &t)
: Parameter<T, false>(t) {}

protected:
virtual bool isChanged() {
if(old != this->get()) {
old = this->get();
return true;
} else {
return false;
}
}

T old;
};

template <typename Base, std::size_t size>
struct Parameter<Base(&)[size], true> : AbstractParameter {
Parameter(Base (&t)[size])
: t(t) { for(std::size_t i = 0; i < size; i++) old[i] = t[i]; }
virtual ~Parameter() { };

virtual void writeForce(ofxOscMessage &m, const std::string &address) {
m.setAddress(address);
set(m, get());
}

protected:
virtual bool isChanged() {
bool isChange = false;
for(std::size_t i = 0; i < size; i++) {
isChange = isChange || (old[i] != get()[i]);
if(isChange) break;
}

if(isChange) {
for(std::size_t i = 0; i < size; i++) {
old[i] = get()[i];
}
return true;
} else {
return false;
}
}

virtual Base (&get())[size] { return t; }
Base (&t)[size];
Base old[size];
};

template <typename T, bool isCheckValue>
struct ConstParameter : AbstractParameter {
ConstParameter(const T &t)
: t(t) {}

virtual void writeForce(ofxOscMessage &m, const std::string &address) {
m.setAddress(address);
set(m, get());
}
protected:
virtual bool isChanged() { return true; }
virtual const T &get() { return t; }
const T t;
};

template <typename T>
struct ConstParameter<T, true> : ConstParameter<T, false> {
ConstParameter(const T &t)
: ConstParameter<T, false>(t) {}

protected:
virtual bool isChanged() {
static bool initial{true};
bool tmp = initial;
initial = false;
return tmp;
}
};

template <typename Base, std::size_t size>
struct ConstParameter<const Base(&)[size], false> : AbstractParameter {
ConstParameter(const Base (&t)[size])
: t(t) {}

virtual void writeForce(ofxOscMessage &m, const std::string &address) {
m.setAddress(address);
set(m, get());
}

protected:
virtual bool isChanged() { return true; }

virtual const Base (&get())[size] { return t; }
const Base (&t)[size];
};

template <typename Base, std::size_t size>
struct ConstParameter<const Base(&)[size], true> : ConstParameter<const Base(&)[size], false> {
ConstParameter(const Base(&t)[size])
: ConstParameter<const Base(&)[size], false>(t) {}

protected:
virtual bool isChanged() {
static bool initial{true};
bool tmp = initial;
initial = false;
return tmp;
}
};

template <typename T, bool isCheckValue>
struct FunctionParameter : Parameter<T, isCheckValue> {
using Function = std::function<T()>;
FunctionParameter(Function getter)
: Parameter<T, isCheckValue>(dummy)
, getter(getter) {}

protected:
virtual type_ref<T> get() { return dummy = getter(); }
Function getter;
remove_ref<T> dummy;
};

template <typename Base, std::size_t size, bool isCheckValue>
struct FunctionParameter<Base(&)[size], isCheckValue> : Parameter<Base(&)[size], isCheckValue> {
using T = Base (&)[size];
using Function = std::function<T()>;
FunctionParameter(Function getter)
: Parameter<Base(&)[size], isCheckValue>(dummy)
, getter(getter) {}

protected:
virtual Base (&get())[size] {
Base (&arr)[size] = getter();
for(std::size_t i = 0; i < size; i++) dummy[i] = arr[i];
return dummy;
}
Function getter;
Base dummy[size];
};

using Targets = std::multimap<std::string, ParameterRef>;
};
};
};

#endif /* ofxOscPublishParameter_h */
Loading

0 comments on commit 110f24a

Please sign in to comment.