You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
188 lines
4.3 KiB
188 lines
4.3 KiB
#include "ofApp.h"
|
|
|
|
//--------------------------------------------------------------
|
|
void ofApp::setup(){
|
|
m_sp_uc_setter = ofxUCSetter::Create("OUTPUT",512);
|
|
if (m_sp_uc_setter)
|
|
{
|
|
m_sp_uc_setter->setup();
|
|
}
|
|
|
|
|
|
ofxImGuiParameter::Initialize();
|
|
ctx = ImGui::GetCurrentContext();
|
|
m_imgui_parameter.setup("Test");
|
|
m_imgui_parameter.set_fit_window(true);
|
|
m_imgui_parameter.bind(triggerDuration.set("Trigger Duration", triggerDuration, 0, 2));
|
|
|
|
osc_receiver.setup(7001);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
void ofApp::update(){
|
|
|
|
receiveMessage();
|
|
|
|
|
|
m_sp_uc_setter->update();
|
|
if (m_sp_param_group)
|
|
{
|
|
ofParameterGroup & group =*m_sp_param_group.get();
|
|
for (int i = 0; i < group.size(); ++i)
|
|
{
|
|
ofAbstractParameter& param = group[i];
|
|
auto type_name = param.type();
|
|
if (type_name != typeid(ofParameter<int>).name())
|
|
continue;
|
|
string prefix = "CHANNEL_";
|
|
int ch = ofToInt(param.getName().substr(prefix.size()));
|
|
//printf("ch=%d\n",ch);
|
|
ofParameter<int>& param_int = param.cast<int>();
|
|
if (triggerTimeStamp.find(ch) == triggerTimeStamp.end())
|
|
{
|
|
param_int = 0;
|
|
}
|
|
else
|
|
{
|
|
float stamp = ofGetElapsedTimef();
|
|
if (stamp - triggerTimeStamp[ch] < triggerDuration)
|
|
{
|
|
param_int = 255;
|
|
}
|
|
else
|
|
{
|
|
param_int = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if ((m_sp_param_group = m_sp_uc_setter->get_paramter_group()))
|
|
{
|
|
m_imgui_parameter.bind(*m_sp_param_group.get());
|
|
ofParameterGroup & group = *m_sp_param_group.get();
|
|
m_imgui_parameter.load();
|
|
ofNotifyEvent(group.parameterChangedE(), group);
|
|
}
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
void ofApp::draw(){
|
|
//m_gui.draw();
|
|
|
|
|
|
SetContex();
|
|
ofxImGuiParameter::Draw();
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
void ofApp::keyPressed(int key){
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
void ofApp::keyReleased(int key){
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
void ofApp::mouseMoved(int x, int y){
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
void ofApp::mouseDragged(int x, int y, int button){
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
void ofApp::mousePressed(int x, int y, int button){
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
void ofApp::mouseReleased(int x, int y, int button){
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
void ofApp::mouseEntered(int x, int y){
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
void ofApp::mouseExited(int x, int y){
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
void ofApp::windowResized(int w, int h){
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
void ofApp::gotMessage(ofMessage msg){
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
void ofApp::dragEvent(ofDragInfo dragInfo){
|
|
|
|
}
|
|
void ofApp::SetContex()
|
|
{
|
|
if (ctx )
|
|
ImGui::SetCurrentContext(ctx);
|
|
|
|
}
|
|
void ofApp::receiveMessage()
|
|
{
|
|
while (osc_receiver.hasWaitingMessages()) {
|
|
ofxOscMessage m;
|
|
osc_receiver.getNextMessage(m);
|
|
|
|
std::string msgString;
|
|
msgString = m.getAddress();
|
|
msgString += ":";
|
|
for (size_t i = 0; i < m.getNumArgs(); i++) {
|
|
|
|
// get the argument type
|
|
msgString += " ";
|
|
msgString += m.getArgTypeName(i);
|
|
msgString += ":";
|
|
|
|
// display the argument - make sure we get the right type
|
|
if (m.getArgType(i) == OFXOSC_TYPE_INT32) {
|
|
msgString += ofToString(m.getArgAsInt32(i));
|
|
}
|
|
else if (m.getArgType(i) == OFXOSC_TYPE_FLOAT) {
|
|
msgString += ofToString(m.getArgAsFloat(i));
|
|
}
|
|
else if (m.getArgType(i) == OFXOSC_TYPE_STRING) {
|
|
msgString += m.getArgAsString(i);
|
|
}
|
|
else {
|
|
msgString += "unhandled argument type " + m.getArgTypeName(i);
|
|
}
|
|
}
|
|
printf("%s\n", msgString.c_str());
|
|
|
|
auto addr = m.getAddress();
|
|
auto tokens = ofSplitString(addr, "/");
|
|
|
|
if (tokens.size() == 3 && m.getNumArgs() == 1 && m.getArgType(0) == OFXOSC_TYPE_INT32)
|
|
{
|
|
int ch = ofToInt(tokens[2]);
|
|
int i = m.getArgAsInt32(0);
|
|
if (i == 3)
|
|
{
|
|
printf("channel = %d, enter", ch);
|
|
if (triggerTimeStamp.find(ch) == triggerTimeStamp.end())
|
|
triggerTimeStamp.insert(std::make_pair(ch, -numeric_limits<float>::max()));
|
|
triggerTimeStamp[ch] = ofGetElapsedTimef();
|
|
}
|
|
}
|
|
}
|
|
} |