LMMS
Loading...
Searching...
No Matches
Fl_Osc_Tree.H
Go to the documentation of this file.
1/*
2 ZynAddSubFX - a software synthesizer
3
4 Fl_Osc_Tree.H - OSC Based Tree
5 Copyright (C) 2016 Mark McCurry
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11*/
12#pragma once
13#include <rtosc/ports.h>
14#include "Fl_Osc_Interface.h"
15#include <FL/Fl_Tree.H>
16
17class Fl_Osc_Tree: public Fl_Tree
18{
19 public:
20 Fl_Osc_Tree(int X, int Y, int W, int H, const char *L=0)
21 :Fl_Tree(X,Y,W,H,L)
22 {
23 root_label("");
24 add("nil");
25 add("/nil/nil");
26 close(first());
28 }
29
30 void sprout(std::string s)
31 {
32 if(s[s.length()-1] == '/') {
33 attach(s);
34 attach(s+"nil");
35 close(s.c_str());
36 } else
37 attach(s);
38 }
39
40 void attach(std::string s)
41 {
42 if(!find_item(s.c_str()))
43 add(s.c_str());
44 }
45
46 static void cb(Fl_Widget *w, void*)
47 {
48 using namespace rtosc;
50 int reason = t->callback_reason();
51
52 char pathname[1024];
53 t->item_pathname(pathname, sizeof(pathname), t->callback_item());
54
55
56 if(reason==1) {
57 char *colon = index(pathname, ':');
58 if(colon) {
59 *colon = 0;
60 t->osc->writeValue("/learn", string(pathname));
61 }
62 }
63
64 if(reason==3) //Populate fields
65 {
66 const Ports &p = *Fl_Osc_Tree::subtree_lookup(t->root_ports,pathname+1);
67 printf("ok, I got the tree\n");
68 if(auto *i = t->find_item((std::string(pathname)+"/"+"nil").c_str()))
69 t->remove(i);
70 for(const Port &port : p) {
71 printf("handling '%s'\n", port.name);
72 const bool subnodes = index(port.name, '/');
73 const bool enumerated = index(port.name, '#');
74 const string path = std::string(pathname)+"/"+port.name;
75 if(!enumerated) {
76 t->sprout(path);
77 } else {
78 char tmpa[1024];
79 char tmpb[1024];
80 strncpy(tmpa, path.c_str(), 1024);
81 char *pound = index(tmpa, '#');
82 int N = atoi(pound+1);
83 *pound = 0;
84 char terminal = subnodes ? '/' : '\0';
85
86 for(int i = 0; i < N; ++i) {
87 snprintf(tmpb, 1024, "%s%d%c",
88 tmpa, i, terminal);
89 t->sprout(tmpb);
90 }
91 }
92 }
93
94 }
95 }
96
97 static const rtosc::Ports *subtree_lookup(const rtosc::Ports *p, std::string s)
98 {
99 using namespace rtosc;
100 if(s=="")
101 return p;
102
103 if(s[s.length()-1] != '/')
104 s += '/';
105
106 for(const Port &port : *p) {
107 const char *name = port.name;
108 if(!index(name, '/'))//only accept objects that will have subports
109 continue;
110 if(rtosc_match(name, s.c_str(), NULL)) {
111 return subtree_lookup(port.ports,
112 s.substr(index(s.c_str(), '/')-s.c_str()+1));
113 }
114 }
115
116 //TODO else case
117 return p;
118 }
119
122};
#define NULL
Definition CarlaBridgeFormat.cpp:30
Definition Fl_Osc_Interface.h:56
void attach(std::string s)
Definition Fl_Osc_Tree.H:40
void sprout(std::string s)
Definition Fl_Osc_Tree.H:30
Fl_Osc_Interface * osc
Definition Fl_Osc_Tree.H:121
static void cb(Fl_Widget *w, void *)
Definition Fl_Osc_Tree.H:46
rtosc::Ports * root_ports
Definition Fl_Osc_Tree.H:120
Fl_Osc_Tree(int X, int Y, int W, int H, const char *L=0)
Definition Fl_Osc_Tree.H:20
static const rtosc::Ports * subtree_lookup(const rtosc::Ports *p, std::string s)
Definition Fl_Osc_Tree.H:97
UINT_D64 w
Definition inflate.c:942
struct huft * t
Definition inflate.c:943
register unsigned i
Definition inflate.c:1575
unsigned s
Definition inflate.c:1555
bool rtosc_match(const char *pattern, const char *msg, const char **path_end)
Definition dispatch.c:132
static const char * name
Definition pugl.h:1582
#define X(str)
Definition juce_LV2Common.h:197
Definition globals.h:37
#define N
Definition nseel-cfunc.c:36
Definition lv2apply.c:40
Definition ports.h:161
RECT const char void(* callback)(const char *droppath))) SWELL_API_DEFINE(BOOL
Definition swell-functions.h:1004
uch * p
Definition crypt.c:594