1 /************************************************************************
2 ************************************************************************
3 FAUST Architecture File
4 Copyright (C) 2008-2011 Kjetil Matheussen <k.s.matheussen@notam02.no>
5 ---------------------------------------------------------------------
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 ************************************************************************
21 ************************************************************************/
34 #include <sys/ioctl.h>
38 #include <sys/types.h>
55 #include <rt-various.h> // realtime memory allocation in Snd.
61 struct Meta
: map
<const char*, const char*>
63 void declare (const char* key
, const char* value
) { (*this)[key
]=value
; }
68 //inline void *aligned_calloc(size_t nmemb, size_t size) { return (void*)((unsigned)(calloc((nmemb*size)+15,sizeof(char)))+15 & 0xfffffff0); }
69 inline void *aligned_calloc(size_t nmemb
, size_t size
) { return (void*)((size_t)(calloc((nmemb
*size
)+15,sizeof(char)))+15 & ~15); }
71 // g++ -O3 -lm -ljack `gtk-config --cflags --libs` ex2.cpp
75 #define max(x,y) (((x)>(y)) ? (x) : (y))
76 #define min(x,y) (((x)<(y)) ? (x) : (y))
79 // abs is now predefined
80 //template<typename T> T abs (T a) { return (a<T(0)) ? -a : a; }
83 inline int lsr (int x
, int n
) { return int(((unsigned int)x
) >> n
); }
85 inline int int2pow2 (int x
) { int r
=0; while ((1<<r
)<x
) r
++; return r
; }
89 /******************************************************************************
90 *******************************************************************************
94 *******************************************************************************
95 *******************************************************************************/
97 //inline void *aligned_calloc(size_t nmemb, size_t size) { return (void*)((unsigned)(calloc((nmemb*size)+15,sizeof(char)))+15 & 0xfffffff0); }
107 /******************************************************************************
108 *******************************************************************************
110 GRAPHIC USER INTERFACE (v2)
113 *******************************************************************************
114 *******************************************************************************/
122 typedef void (*uiCallback
)(float val
, void* data
);
125 #ifdef MAKE_GUI // It's enough to compile GUI code once.
128 * Graphic User Interface : abstract definition
133 typedef list
<uiItem
*> clist
;
134 typedef map
<float*, clist
*> zmap
;
137 static list
<UI
*> fGuiList
;
143 UI() : fStopped(false) {
144 fGuiList
.push_back(this);
148 // suppression de this dans fGuiList
151 // -- registerZone(z,c) : zone management
154 void registerZone(float* z
, uiItem
* c
)
157 if (fZoneMap
.find(z
) == fZoneMap
.end()) fZoneMap
[z
] = new clist();
158 fZoneMap
[z
]->push_back(c
);
161 // -- saveState(filename) : save the value of every zone to a file
163 void saveState(const char* filename
)
165 ofstream
f(filename
);
167 for (zmap::iterator i
=fZoneMap
.begin(); i
!=fZoneMap
.end(); i
++) {
168 f
<< *(i
->first
) << ' ';
175 // -- recallState(filename) : load the value of every zone from a file
177 void recallState(const char* filename
)
179 ifstream
f(filename
);
181 for (zmap::iterator i
=fZoneMap
.begin(); i
!=fZoneMap
.end(); i
++) {
188 void updateAllZones();
190 void updateZone(float* z
);
192 static void updateAllGuis()
194 list
<UI
*>::iterator g
;
195 for (g
= fGuiList
.begin(); g
!= fGuiList
.end(); g
++) {
196 (*g
)->updateAllZones();
202 virtual void addButton(const char* label
, float* zone
) = 0;
203 virtual void addToggleButton(const char* label
, float* zone
) = 0;
204 virtual void addCheckButton(const char* label
, float* zone
) = 0;
205 virtual void addVerticalSlider(const char* label
, float* zone
, float init
, float min
, float max
, float step
) = 0;
206 virtual void addHorizontalSlider(const char* label
, float* zone
, float init
, float min
, float max
, float step
) = 0;
207 virtual void addNumEntry(const char* label
, float* zone
, float init
, float min
, float max
, float step
) = 0;
209 // -- passive widgets
211 virtual void addNumDisplay(const char* label
, float* zone
, int precision
) = 0;
212 virtual void addTextDisplay(const char* label
, float* zone
, const char* names
[], float min
, float max
) = 0;
213 virtual void addHorizontalBargraph(const char* label
, float* zone
, float min
, float max
) = 0;
214 virtual void addVerticalBargraph(const char* label
, float* zone
, float min
, float max
) = 0;
216 void addCallback(float* zone
, uiCallback foo
, void* data
);
218 // -- widget's layouts
220 virtual void openFrameBox(const char* label
) = 0;
221 virtual void openTabBox(const char* label
) = 0;
222 virtual void openHorizontalBox(const char* label
) = 0;
223 virtual void openVerticalBox(const char* label
) = 0;
224 virtual void closeBox() = 0;
226 virtual void show() = 0;
227 virtual void run() = 0;
229 virtual void declare(float* zone
, const char* key
, const char* value
) {}
231 void stop() { fStopped
= true; }
232 bool stopped() { return fStopped
; }
237 * User Interface Item: abstract definition
248 uiItem (UI
* ui
, float* zone
) : fGUI(ui
), fZone(zone
), fCache(-123456.654321)
250 ui
->registerZone(zone
, this);
257 void modifyZone(float v
)
262 fGUI
->updateZone(fZone
);
266 float cache() { return fCache
; }
267 virtual void reflectZone() = 0;
275 struct uiCallbackItem
: public uiItem
277 uiCallback fCallback
;
280 uiCallbackItem(UI
* ui
, float* zone
, uiCallback foo
, void* data
)
281 : uiItem(ui
, zone
), fCallback(foo
), fData(data
) {}
283 virtual void reflectZone() {
290 // en cours d'installation de call back. a finir!!!!!
293 * Update all user items reflecting zone z
296 inline void UI::updateZone(float* z
)
299 clist
* l
= fZoneMap
[z
];
300 for (clist::iterator c
= l
->begin(); c
!= l
->end(); c
++) {
301 if ((*c
)->cache() != v
) (*c
)->reflectZone();
307 * Update all user items not up to date
310 inline void UI::updateAllZones()
312 for (zmap::iterator m
= fZoneMap
.begin(); m
!= fZoneMap
.end(); m
++) {
314 clist
* l
= m
->second
;
316 for (clist::iterator c
= l
->begin(); c
!= l
->end(); c
++) {
317 if ((*c
)->cache() != v
) (*c
)->reflectZone();
322 inline void UI::addCallback(float* zone
, uiCallback foo
, void* data
)
324 new uiCallbackItem(this, zone
, foo
, data
);
328 /******************************************************************************
329 *******************************************************************************
331 GRAPHIC USER INTERFACE
334 *******************************************************************************
335 *******************************************************************************/
339 #define stackSize 256
343 #define kSingleMode 0
348 class GTKUI
: public UI
351 static bool fInitialized
;
352 static list
<UI
*> fGuiList
;
357 GtkWidget
* fBox
[stackSize
];
358 int fMode
[stackSize
];
361 GtkWidget
* addWidget(const char* label
, GtkWidget
* w
);
362 virtual void pushBox(int mode
, GtkWidget
* w
);
367 static const gboolean expand
= TRUE
;
368 static const gboolean fill
= TRUE
;
369 static const gboolean homogene
= FALSE
;
371 GTKUI(char * name
, int* pargc
, char*** pargv
);
376 virtual void openFrameBox(const char* label
);
377 virtual void openTabBox(const char* label
= "");
378 virtual void openHorizontalBox(const char* label
= "");
379 virtual void openVerticalBox(const char* label
= "");
381 virtual void closeBox();
385 virtual void addButton(const char* label
, float* zone
);
386 virtual void addToggleButton(const char* label
, float* zone
);
387 virtual void addCheckButton(const char* label
, float* zone
);
388 virtual void addVerticalSlider(const char* label
, float* zone
, float init
, float min
, float max
, float step
);
389 virtual void addHorizontalSlider(const char* label
, float* zone
, float init
, float min
, float max
, float step
);
390 virtual void addNumEntry(const char* label
, float* zone
, float init
, float min
, float max
, float step
);
392 // -- passive display widgets
394 virtual void addNumDisplay(const char* label
, float* zone
, int precision
);
395 virtual void addTextDisplay(const char* label
, float* zone
, const char* names
[], float min
, float max
);
396 virtual void addHorizontalBargraph(const char* label
, float* zone
, float min
, float max
);
397 virtual void addVerticalBargraph(const char* label
, float* zone
, float min
, float max
);
402 virtual void declare(float* zone
, const char* key
, const char* value
) {}
408 /******************************************************************************
409 *******************************************************************************
411 GRAPHIC USER INTERFACE (v2)
414 *******************************************************************************
415 *******************************************************************************/
417 // global static fields
419 bool GTKUI::fInitialized
= false;
420 list
<UI
*> UI::fGuiList
;
424 static gint
delete_event( GtkWidget
*widget
, GdkEvent
*event
, gpointer data
)
429 static void destroy_event( GtkWidget
*widget
, gpointer data
)
435 GTKUI::GTKUI(char * name
, int* pargc
, char*** pargv
)
438 gtk_init(pargc
, pargv
);
442 fWindow
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
443 //gtk_container_set_border_width (GTK_CONTAINER (fWindow), 10);
444 gtk_window_set_title (GTK_WINDOW (fWindow
), name
);
445 gtk_signal_connect (GTK_OBJECT (fWindow
), "delete_event", GTK_SIGNAL_FUNC (delete_event
), NULL
);
446 gtk_signal_connect (GTK_OBJECT (fWindow
), "destroy", GTK_SIGNAL_FUNC (destroy_event
), NULL
);
449 fBox
[fTop
] = gtk_vbox_new (homogene
, 4);
450 fMode
[fTop
] = kBoxMode
;
451 gtk_container_add (GTK_CONTAINER (fWindow
), fBox
[fTop
]);
455 // empilement des boites
457 void GTKUI::pushBox(int mode
, GtkWidget
* w
)
460 assert(fTop
< stackSize
);
465 void GTKUI::closeBox()
472 // les differentes boites
474 void GTKUI::openFrameBox(const char* label
)
476 GtkWidget
* box
= gtk_frame_new (label
);
477 //gtk_container_set_border_width (GTK_CONTAINER (box), 10);
479 pushBox(kSingleMode
, addWidget(label
, box
));
482 void GTKUI::openTabBox(const char* label
)
484 pushBox(kTabMode
, addWidget(label
, gtk_notebook_new ()));
487 void GTKUI::openHorizontalBox(const char* label
)
489 GtkWidget
* box
= gtk_hbox_new (homogene
, 4);
490 gtk_container_set_border_width (GTK_CONTAINER (box
), 10);
492 if (fMode
[fTop
] != kTabMode
&& label
[0] != 0) {
493 GtkWidget
* frame
= addWidget(label
, gtk_frame_new (label
));
494 gtk_container_add (GTK_CONTAINER(frame
), box
);
495 gtk_widget_show(box
);
496 pushBox(kBoxMode
, box
);
498 pushBox(kBoxMode
, addWidget(label
, box
));
502 void GTKUI::openVerticalBox(const char* label
)
504 GtkWidget
* box
= gtk_vbox_new (homogene
, 4);
505 gtk_container_set_border_width (GTK_CONTAINER (box
), 10);
507 if (fMode
[fTop
] != kTabMode
&& label
[0] != 0) {
508 GtkWidget
* frame
= addWidget(label
, gtk_frame_new (label
));
509 gtk_container_add (GTK_CONTAINER(frame
), box
);
510 gtk_widget_show(box
);
511 pushBox(kBoxMode
, box
);
513 pushBox(kBoxMode
, addWidget(label
, box
));
517 GtkWidget
* GTKUI::addWidget(const char* label
, GtkWidget
* w
)
519 switch (fMode
[fTop
]) {
520 case kSingleMode
: gtk_container_add (GTK_CONTAINER(fBox
[fTop
]), w
); break;
521 case kBoxMode
: gtk_box_pack_start (GTK_BOX(fBox
[fTop
]), w
, expand
, fill
, 0); break;
522 case kTabMode
: gtk_notebook_append_page (GTK_NOTEBOOK(fBox
[fTop
]), w
, gtk_label_new(label
)); break;
528 // --------------------------- Press button ---------------------------
530 struct uiButton
: public uiItem
534 uiButton (UI
* ui
, float* zone
, GtkButton
* b
) : uiItem(ui
, zone
), fButton(b
) {}
536 static void pressed( GtkWidget
*widget
, gpointer data
)
538 uiItem
* c
= (uiItem
*) data
;
542 static void released( GtkWidget
*widget
, gpointer data
)
544 uiItem
* c
= (uiItem
*) data
;
548 virtual void reflectZone()
552 if (v
> 0.0) gtk_button_pressed(fButton
); else gtk_button_released(fButton
);
556 void GTKUI::addButton(const char* label
, float* zone
)
559 GtkWidget
* button
= gtk_button_new_with_label (label
);
560 addWidget(label
, button
);
562 uiButton
* c
= new uiButton(this, zone
, GTK_BUTTON(button
));
564 gtk_signal_connect (GTK_OBJECT (button
), "pressed", GTK_SIGNAL_FUNC (uiButton::pressed
), (gpointer
) c
);
565 gtk_signal_connect (GTK_OBJECT (button
), "released", GTK_SIGNAL_FUNC (uiButton::released
), (gpointer
) c
);
569 // --------------------------- Toggle Buttons ---------------------------
571 struct uiToggleButton
: public uiItem
573 GtkToggleButton
* fButton
;
575 uiToggleButton(UI
* ui
, float* zone
, GtkToggleButton
* b
) : uiItem(ui
, zone
), fButton(b
) {}
577 static void toggled (GtkWidget
*widget
, gpointer data
)
579 float v
= (GTK_TOGGLE_BUTTON (widget
)->active
) ? 1.0 : 0.0;
580 ((uiItem
*)data
)->modifyZone(v
);
583 virtual void reflectZone()
587 gtk_toggle_button_set_active(fButton
, v
> 0.0);
591 void GTKUI::addToggleButton(const char* label
, float* zone
)
594 GtkWidget
* button
= gtk_toggle_button_new_with_label (label
);
595 addWidget(label
, button
);
597 uiToggleButton
* c
= new uiToggleButton(this, zone
, GTK_TOGGLE_BUTTON(button
));
598 gtk_signal_connect (GTK_OBJECT (button
), "toggled", GTK_SIGNAL_FUNC (uiToggleButton::toggled
), (gpointer
) c
);
602 // --------------------------- Check Button ---------------------------
604 struct uiCheckButton
: public uiItem
606 GtkToggleButton
* fButton
;
608 uiCheckButton(UI
* ui
, float* zone
, GtkToggleButton
* b
) : uiItem(ui
, zone
), fButton(b
) {}
610 static void toggled (GtkWidget
*widget
, gpointer data
)
612 float v
= (GTK_TOGGLE_BUTTON (widget
)->active
) ? 1.0 : 0.0;
613 ((uiItem
*)data
)->modifyZone(v
);
616 virtual void reflectZone()
620 gtk_toggle_button_set_active(fButton
, v
> 0.0);
624 void GTKUI::addCheckButton(const char* label
, float* zone
)
627 GtkWidget
* button
= gtk_check_button_new_with_label (label
);
628 addWidget(label
, button
);
630 uiCheckButton
* c
= new uiCheckButton(this, zone
, GTK_TOGGLE_BUTTON(button
));
631 gtk_signal_connect (GTK_OBJECT (button
), "toggled", GTK_SIGNAL_FUNC(uiCheckButton::toggled
), (gpointer
) c
);
635 // --------------------------- Adjustmenty based widgets ---------------------------
637 struct uiAdjustment
: public uiItem
641 uiAdjustment(UI
* ui
, float* zone
, GtkAdjustment
* adj
) : uiItem(ui
, zone
), fAdj(adj
) {}
643 static void changed (GtkWidget
*widget
, gpointer data
)
645 float v
= GTK_ADJUSTMENT (widget
)->value
;
646 ((uiItem
*)data
)->modifyZone(v
);
649 virtual void reflectZone()
653 gtk_adjustment_set_value(fAdj
, v
);
657 static int precision(double n
)
659 if (n
< 0.009999) return 3;
660 else if (n
< 0.099999) return 2;
661 else if (n
< 0.999999) return 1;
665 // -------------------------- Vertical Slider -----------------------------------
667 void GTKUI::addVerticalSlider(const char* label
, float* zone
, float init
, float min
, float max
, float step
)
670 GtkObject
* adj
= gtk_adjustment_new(init
, min
, max
, step
, 10*step
, 0);
672 uiAdjustment
* c
= new uiAdjustment(this, zone
, GTK_ADJUSTMENT(adj
));
674 gtk_signal_connect (GTK_OBJECT (adj
), "value-changed", GTK_SIGNAL_FUNC (uiAdjustment::changed
), (gpointer
) c
);
676 GtkWidget
* slider
= gtk_vscale_new (GTK_ADJUSTMENT(adj
));
677 gtk_range_set_inverted (GTK_RANGE(slider
), TRUE
);
678 gtk_scale_set_digits(GTK_SCALE(slider
), precision(step
));
679 gtk_widget_set_usize(slider
, -1, 160);
682 addWidget(label
, slider
);
686 // -------------------------- Horizontal Slider -----------------------------------
688 void GTKUI::addHorizontalSlider(const char* label
, float* zone
, float init
, float min
, float max
, float step
)
691 GtkObject
* adj
= gtk_adjustment_new(init
, min
, max
, step
, 10*step
, 0);
693 uiAdjustment
* c
= new uiAdjustment(this, zone
, GTK_ADJUSTMENT(adj
));
695 gtk_signal_connect (GTK_OBJECT (adj
), "value-changed", GTK_SIGNAL_FUNC (uiAdjustment::changed
), (gpointer
) c
);
697 GtkWidget
* slider
= gtk_hscale_new (GTK_ADJUSTMENT(adj
));
698 gtk_scale_set_digits(GTK_SCALE(slider
), precision(step
));
699 gtk_widget_set_usize(slider
, 160, -1);
702 addWidget(label
, slider
);
707 // ------------------------------ Num Entry -----------------------------------
709 void GTKUI::addNumEntry(const char* label
, float* zone
, float init
, float min
, float max
, float step
)
712 GtkObject
* adj
= gtk_adjustment_new(init
, min
, max
, step
, 10*step
, step
);
714 uiAdjustment
* c
= new uiAdjustment(this, zone
, GTK_ADJUSTMENT(adj
));
716 gtk_signal_connect (GTK_OBJECT (adj
), "value-changed", GTK_SIGNAL_FUNC (uiAdjustment::changed
), (gpointer
) c
);
718 GtkWidget
* spinner
= gtk_spin_button_new (GTK_ADJUSTMENT(adj
), 0.005, precision(step
));
720 //gtk_widget_set_usize(slider, 160, -1);
722 addWidget(label
, spinner
);
727 // ========================== passive widgets ===============================
730 // ------------------------------ Progress Bar -----------------------------------
732 struct uiBargraph
: public uiItem
734 GtkProgressBar
* fProgressBar
;
738 uiBargraph(UI
* ui
, float* zone
, GtkProgressBar
* pbar
, float lo
, float hi
)
739 : uiItem(ui
, zone
), fProgressBar(pbar
), fMin(lo
), fMax(hi
) {}
741 float scale(float v
) { return (v
-fMin
)/(fMax
-fMin
); }
743 virtual void reflectZone()
747 gtk_progress_bar_set_fraction(fProgressBar
, scale(v
));
753 void GTKUI::addVerticalBargraph(const char* label
, float* zone
, float lo
, float hi
)
755 GtkWidget
* pb
= gtk_progress_bar_new();
756 gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(pb
), GTK_PROGRESS_BOTTOM_TO_TOP
);
757 gtk_widget_set_size_request(pb
, 8, -1);
758 new uiBargraph(this, zone
, GTK_PROGRESS_BAR(pb
), lo
, hi
);
760 addWidget(label
, pb
);
765 void GTKUI::addHorizontalBargraph(const char* label
, float* zone
, float lo
, float hi
)
767 GtkWidget
* pb
= gtk_progress_bar_new();
768 gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(pb
), GTK_PROGRESS_LEFT_TO_RIGHT
);
769 gtk_widget_set_size_request(pb
, -1, 8);
770 new uiBargraph(this, zone
, GTK_PROGRESS_BAR(pb
), lo
, hi
);
772 addWidget(label
, pb
);
777 // ------------------------------ Num Display -----------------------------------
779 struct uiNumDisplay
: public uiItem
784 uiNumDisplay(UI
* ui
, float* zone
, GtkLabel
* label
, int precision
)
785 : uiItem(ui
, zone
), fLabel(label
), fPrecision(precision
) {}
787 virtual void reflectZone()
792 if (fPrecision
<= 0) {
793 snprintf(s
, 63, "%d", int(v
));
794 } else if (fPrecision
>3) {
795 snprintf(s
, 63, "%f", v
);
797 const char* format
[] = {"%.1f", "%.2f", "%.3f"};
798 snprintf(s
, 63, format
[fPrecision
-1], v
);
800 gtk_label_set_text(fLabel
, s
);
805 void GTKUI::addNumDisplay(const char* label
, float* zone
, int precision
)
807 GtkWidget
* lw
= gtk_label_new("");
808 new uiNumDisplay(this, zone
, GTK_LABEL(lw
), precision
);
810 addWidget(label
, lw
);
815 // ------------------------------ Text Display -----------------------------------
817 struct uiTextDisplay
: public uiItem
826 uiTextDisplay (UI
* ui
, float* zone
, GtkLabel
* label
, const char* names
[], float lo
, float hi
)
827 : uiItem(ui
, zone
), fLabel(label
), fNames(names
), fMin(lo
), fMax(hi
)
830 while (fNames
[fNum
] != 0) fNum
++;
833 virtual void reflectZone()
838 int idx
= int(fNum
*(v
-fMin
)/(fMax
-fMin
));
840 if (idx
< 0) idx
= 0;
841 else if (idx
>= fNum
) idx
= fNum
-1;
843 gtk_label_set_text(fLabel
, fNames
[idx
]);
848 void GTKUI::addTextDisplay(const char* label
, float* zone
, const char* names
[], float lo
, float hi
)
850 GtkWidget
* lw
= gtk_label_new("");
851 new uiTextDisplay (this, zone
, GTK_LABEL(lw
), names
, lo
, hi
);
853 addWidget(label
, lw
);
862 gtk_widget_show (fBox
[0]);
863 gtk_widget_show (fWindow
);
868 * Update all user items reflecting zone z
871 static gboolean
callUpdateAllGuis(gpointer
)
881 gtk_widget_show (fBox
[0]);
882 gtk_widget_show (fWindow
);
883 gtk_timeout_add(40, callUpdateAllGuis
, 0);
893 typedef list
<uiItem
*> clist
;
894 typedef map
<float*, clist
*> zmap
;
897 static list
<UI
*> fGuiList
;
903 UI() : fStopped(false) {
904 fGuiList
.push_back(this);
908 // suppression de this dans fGuiList
911 // -- zone management
913 void registerZone(float* z
, uiItem
* c
)
915 if (fZoneMap
.find(z
) == fZoneMap
.end()) fZoneMap
[z
] = new clist();
916 fZoneMap
[z
]->push_back(c
);
919 void updateAllZones();
921 void updateZone(float* z
);
923 static void updateAllGuis()
925 list
<UI
*>::iterator g
;
926 for (g
= fGuiList
.begin(); g
!= fGuiList
.end(); g
++) {
927 (*g
)->updateAllZones();
933 virtual void addButton(const char* label
, float* zone
) = 0;
934 virtual void addToggleButton(const char* label
, float* zone
) = 0;
935 virtual void addCheckButton(const char* label
, float* zone
) = 0;
936 virtual void addVerticalSlider(const char* label
, float* zone
, float init
, float min
, float max
, float step
) = 0;
937 virtual void addHorizontalSlider(const char* label
, float* zone
, float init
, float min
, float max
, float step
) = 0;
938 virtual void addNumEntry(const char* label
, float* zone
, float init
, float min
, float max
, float step
) = 0;
940 // -- passive widgets
942 virtual void addNumDisplay(const char* label
, float* zone
, int precision
) = 0;
943 virtual void addTextDisplay(const char* label
, float* zone
, char* names
[], float min
, float max
) = 0;
944 virtual void addHorizontalBargraph(const char* label
, float* zone
, float min
, float max
) = 0;
945 virtual void addVerticalBargraph(const char* label
, float* zone
, float min
, float max
) = 0;
947 void addCallback(float* zone
, uiCallback foo
, void* data
);
949 // -- widget's layouts
951 virtual void openFrameBox(const char* label
) = 0;
952 virtual void openTabBox(const char* label
) = 0;
953 virtual void openHorizontalBox(const char* label
) = 0;
954 virtual void openVerticalBox(const char* label
) = 0;
955 virtual void closeBox() = 0;
957 virtual void show() = 0;
958 virtual void run() = 0;
960 void stop() { fStopped
= true; }
961 bool stopped() { return fStopped
; }
966 * User Interface Item: abstract definition
977 uiItem (UI
* ui
, float* zone
) : fGUI(ui
), fZone(zone
), fCache(-123456.654321)
979 ui
->registerZone(zone
, this);
987 void modifyZone(float v
)
992 fGUI
->updateZone(fZone
);
996 float cache() { return fCache
; }
997 virtual void reflectZone() = 0;
1005 struct uiCallbackItem
: public uiItem
1007 uiCallback fCallback
;
1010 uiCallbackItem(UI
* ui
, float* zone
, uiCallback foo
, void* data
)
1011 : uiItem(ui
, zone
), fCallback(foo
), fData(data
) {}
1013 virtual void reflectZone() {
1016 fCallback(v
, fData
);
1022 * Update all user items reflecting zone z
1025 inline void UI::updateZone(float* z
)
1028 clist
* l
= fZoneMap
[z
];
1029 for (clist::iterator c
= l
->begin(); c
!= l
->end(); c
++) {
1030 if ((*c
)->cache() != v
) (*c
)->reflectZone();
1036 * Update all user items not up to date
1039 inline void UI::updateAllZones()
1041 for (zmap::iterator m
= fZoneMap
.begin(); m
!= fZoneMap
.end(); m
++) {
1042 float* z
= m
->first
;
1043 clist
* l
= m
->second
;
1045 for (clist::iterator c
= l
->begin(); c
!= l
->end(); c
++) {
1046 if ((*c
)->cache() != v
) (*c
)->reflectZone();
1051 inline void UI::addCallback(float* zone
, uiCallback foo
, void* data
)
1053 new uiCallbackItem(this, zone
, foo
, data
);
1059 /******************************************************************************
1060 *******************************************************************************
1064 *******************************************************************************
1065 *******************************************************************************/
1071 //----------------------------------------------------------------
1072 // définition du processeur de signal
1073 //----------------------------------------------------------------
1082 virtual int getNumInputs() = 0;
1083 virtual int getNumOutputs() = 0;
1084 virtual void buildUserInterface(UI
* interface
) = 0;
1085 virtual void init(int samplingRate
) = 0;
1086 virtual void compute(int len
, float** inputs
, float** outputs
) = 0;
1087 virtual void conclude() {}
1089 void* operator new(size_t size
){
1090 return clm_malloc_atomic(size
,"faust new");
1096 //----------------------------------------------------------------------------
1097 // FAUST generated code
1098 //----------------------------------------------------------------------------
1105 class SNDRTGTKUI
: public GTKUI
{
1108 SNDRTGTKUI(char * name
, GtkDialog
*window
);
1112 void registerZone(float* z, uiItem* c){
1114 GTKUI:registerZone(z,c);
1119 SNDRTGTKUI::SNDRTGTKUI(char * name
, GtkDialog
*window
)
1123 fWindow
= GTK_WIDGET(GTK_WINDOW(window
));
1125 fBox
[fTop
] = window
->vbox
;
1126 fMode
[fTop
] = kBoxMode
;
1130 void SNDRTGTKUI::localRun(){
1136 gtk_widget_show (fBox
[0]);
1137 gtk_widget_show (fWindow
);
1138 gtk_timeout_add(40, callUpdateAllGuis
, 0);
1142 extern "C" SNDRTGTKUI
* newGTKUI(char *name
, void* window
){
1143 return new SNDRTGTKUI(name
,(GtkDialog
*)window
);
1146 extern "C" void runGTKUI(SNDRTGTKUI
* ui
){
1150 extern "C" int containsUI(SNDRTGTKUI
* ui
){
1151 return ui
->containsUI
==true?1:0;
1158 extern "C" dsp
* newDsp() { return new mydsp(); }
1159 extern "C" void deleteDsp(dsp
* self
) { delete self
; }
1161 extern "C" int getNumInputs(dsp
* self
) { return self
->getNumInputs(); }
1162 extern "C" int getNumOutputs(dsp
* self
) { return self
->getNumOutputs(); }
1163 extern "C" void buildUserInterface(dsp
* self
,UI
* interface
) { self
->buildUserInterface(interface
); }
1164 extern "C" void init(dsp
* self
, int freq
) { self
->init(freq
); }
1165 extern "C" void compute(dsp
* self
, int len
, float** inputs
, float** outputs
) { self
->compute(len
, inputs
, outputs
); }
1166 extern "C" void conclude(dsp
* self
) { self
->conclude(); }