Clang-format the code and some whitespace clean-upswq
authorAlexander Koenig <alex@lisas.de>
Sun, 14 Feb 2021 08:38:33 +0000 (09:38 +0100)
committerAlexander Koenig <alex@lisas.de>
Sun, 14 Feb 2021 08:38:33 +0000 (09:38 +0100)
72 files changed:
src/.clang-format [new file with mode: 0644]
src/main.cc
src/tX_audiodevice.cc
src/tX_audiodevice.h
src/tX_audiofile.cc
src/tX_audiofile.h
src/tX_capabilities.cc
src/tX_capabilities.h
src/tX_dial.c
src/tX_dial.h
src/tX_dialog.cc
src/tX_dialog.h
src/tX_endian.c
src/tX_endian.h
src/tX_engine.cc
src/tX_engine.h
src/tX_event.cc
src/tX_event.h
src/tX_extdial.cc
src/tX_extdial.h
src/tX_flash.c
src/tX_flash.h
src/tX_global.c
src/tX_global.h
src/tX_knobloader.c
src/tX_knobloader.h
src/tX_ladspa.cc
src/tX_ladspa.h
src/tX_ladspa_class.cc
src/tX_ladspa_class.h
src/tX_legacy_global.c
src/tX_legacy_vtt.cc
src/tX_loaddlg.cc
src/tX_loaddlg.h
src/tX_logo.c
src/tX_maingui.cc
src/tX_maingui.h
src/tX_midiin.cc
src/tX_midiin.h
src/tX_mouse.cc
src/tX_mouse.h
src/tX_panel.cc
src/tX_panel.h
src/tX_pbutton.cc
src/tX_pbutton.h
src/tX_prelis.cc
src/tX_prelis.h
src/tX_seqpar.cc
src/tX_seqpar.h
src/tX_sequencer.cc
src/tX_sequencer.h
src/tX_tape.cc
src/tX_tape.h
src/tX_types.h
src/tX_ui_callbacks.cc
src/tX_ui_callbacks.h
src/tX_ui_interface.cc
src/tX_ui_interface.h
src/tX_ui_support.cc
src/tX_ui_support.h
src/tX_vtt.cc
src/tX_vtt.h
src/tX_vttfx.cc
src/tX_vttfx.h
src/tX_vttgui.cc
src/tX_vttgui.h
src/tX_widget.c
src/tX_widget.h
src/version.h
src/wav_file.h
src/wav_read.c
src/wav_write.c

diff --git a/src/.clang-format b/src/.clang-format
new file mode 100644 (file)
index 0000000..bc2a6d9
--- /dev/null
@@ -0,0 +1,90 @@
+---
+Language:        Cpp
+# BasedOnStyle:  WebKit
+AccessModifierOffset: -2
+AlignAfterOpenBracket: DontAlign
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlinesLeft: false
+AlignOperands:   false
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+  AfterClass:      false
+  AfterControlStatement: false
+  AfterEnum:       false
+  AfterFunction:   false
+  AfterNamespace:  false
+  AfterObjCDeclaration: false
+  AfterStruct:     false
+  AfterUnion:      false
+  BeforeCatch:     false
+  BeforeElse:      false
+  IndentBraces:    false
+BreakBeforeBinaryOperators: All
+BreakBeforeBraces: Custom
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: true
+ColumnLimit:     0
+CommentPragmas:  '^ IWYU pragma:'
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat:   false
+ExperimentalAutoDetectBinPacking: false
+ForEachMacros:   [ foreach, Q_FOREACH, BOOST_FOREACH ]
+IncludeCategories:
+  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
+    Priority:        2
+  - Regex:           '^(<|"(gtest|isl|json)/)'
+    Priority:        3
+  - Regex:           '.*'
+    Priority:        1
+IndentCaseLabels: false
+IndentWidth:     4
+IndentWrappedFunctionNames: false
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd:   ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: All
+ObjCBlockIndentWidth: 4
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Left
+ReflowComments:  true
+SortIncludes:    true
+SpaceAfterCStyleCast: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles:  false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard:        Cpp03
+TabWidth:        8
+UseTab:          Never
+...
+
index 46831854e26e2e89cad2171f7497da745a201949..09ae886ae0bd34214de2ee943606ad01a2ad27b8 100644 (file)
@@ -14,9 +14,9 @@
 
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
-    
+
     File: main.c
-    
+
     Description: This contains the main() function. All the initializing
                 happens here.
 */
@@ -25,7 +25,6 @@
 
 #define BENCH_CYCLES 100000
 
-#include <stdio.h>
 #include "tX_maingui.h"
 #include <malloc.h>
 #include <math.h>
 #include <config.h>
 #endif
 
+#include "tX_audiodevice.h"
+#include "tX_dialog.h"
 #include "tX_endian.h"
-#include "tX_types.h"
 #include "tX_global.h"
-#include "tX_audiodevice.h"
+#include "tX_types.h"
 #include "version.h"
-#include "tX_dialog.h"
-#include <gtk/gtk.h>
 #include <glib.h>
+#include <gtk/gtk.h>
 #include <string.h>
 
+#include "tX_capabilities.h"
+#include "tX_engine.h"
 #include "tX_ladspa.h"
 #include "tX_ladspa_class.h"
-#include "tX_engine.h"
-#include "tX_capabilities.h"
 #include "tX_pbutton.h"
 
-#ifdef CREATE_BENCHMARK 
+#ifdef CREATE_BENCHMARK
 #include "tX_vtt.h"
 #endif
 
 #include <unistd.h>
 #endif
 
-#ifdef USE_JACK        
-void jack_check()
-{
-       if ((!tX_jack_client::get_instance()) && (globals.audiodevice_type==JACK)) {
-               tx_note("Couldn't connect to JACK server - JACK output not available.\n\nIf you want to use JACK, ensure the JACK daemon is running before you start terminatorX.", true);
-       }
+#ifdef USE_JACK
+void jack_check() {
+    if ((!tX_jack_client::get_instance()) && (globals.audiodevice_type == JACK)) {
+        tx_note("Couldn't connect to JACK server - JACK output not available.\n\nIf you want to use JACK, ensure the JACK daemon is running before you start terminatorX.", true);
+    }
 }
 #endif // USE_JACK
 
-static bool timesup=false;
+static bool timesup = false;
 
-gboolean timeout(void *)
-{
-       timesup=true;
-       return FALSE;
+gboolean timeout(void*) {
+    timesup = true;
+    return FALSE;
 }
 
-void show_help()
-{
-                       
-       fprintf(stderr, "\
+void show_help() {
+
+    fprintf(stderr, "\
 usage: terminatorX [options]\n\
 \n\
   -h, --help                   Display help info\n\
@@ -96,265 +92,268 @@ usage: terminatorX [options]\n\
 \n");
 }
 
-int parse_args(int *argc, char **argv)
-{
-       // pass over argv once to see if we need to load an alternate_rc file
-       for (int i = 1 ; i != *argc ; ++i ) {
-               if ((strcmp(argv[i], "-r") == 0) || (strcmp(argv[i], "--rc-file") == 0)) {
-                       if (argv[i+1] ) {       
-                               ++i;
-                               fprintf(stderr, "tX: Loading alternate rc file %s\n", argv[i]);
-                               globals.alternate_rc = argv[i];
-                       } else {
-                               show_help();    
-                               exit(1);
-                       }
-                       break;
-               }
-       }
-       
-       // load up the global values
-       load_globals();
-
-       // default the flag options, or they'll be set from last execution... (think globals.no_gui ;)
-       globals.no_gui = 0;
-       globals.alternate_rc = 0;
-       globals.store_globals = 1;
-       globals.startup_set = 0;
-               
-       // then pass over again, this time setting passed values
-       for (int i = 1 ; i < *argc ; ++i ) {
-               if ((strcmp(argv[i], "-f") == 0) || (strcmp(argv[i], "--file") == 0)) {
-                       ++i;
-                       globals.startup_set = argv[i];
-               } else if (((strcmp(argv[i], "-r") == 0) || (strcmp(argv[i], "--rc-file") == 0)) && (argv[i+1])) {
-                       ++i;
-                       globals.alternate_rc = argv[i];
-               } else if ((strcmp(argv[i], "-d") == 0) || (strcmp(argv[i], "--dont-save") == 0)) {
-                       fprintf(stderr, "tX: Do not save settings on exit\n");
-                       globals.store_globals = 0;
-
-               } else if ((strcmp(argv[i], "-s") == 0) || (strcmp(argv[i], "--std-out") == 0)) {
-                       globals.use_stdout_cmdline = 1;
-                       globals.use_stdout = 1;
-               } else if ((strncmp(argv[i], "--device",8) == 0)) {
-                       if (strlen(argv[i]+9)<=PATH_MAX)
-                               strcpy(globals.oss_device,argv[i]+9);
-                       else {
-                               show_help();
-                               exit(1);
-                       }
-               } else {
-                       show_help();
-                       exit(1);
-               }
-       }
-       return 1;
+int parse_args(int* argc, char** argv) {
+    // pass over argv once to see if we need to load an alternate_rc file
+    for (int i = 1; i != *argc; ++i) {
+        if ((strcmp(argv[i], "-r") == 0) || (strcmp(argv[i], "--rc-file") == 0)) {
+            if (argv[i + 1]) {
+                ++i;
+                fprintf(stderr, "tX: Loading alternate rc file %s\n", argv[i]);
+                globals.alternate_rc = argv[i];
+            } else {
+                show_help();
+                exit(1);
+            }
+            break;
+        }
+    }
+
+    // load up the global values
+    load_globals();
+
+    // default the flag options, or they'll be set from last execution... (think globals.no_gui ;)
+    globals.no_gui = 0;
+    globals.alternate_rc = 0;
+    globals.store_globals = 1;
+    globals.startup_set = 0;
+
+    // then pass over again, this time setting passed values
+    for (int i = 1; i < *argc; ++i) {
+        if ((strcmp(argv[i], "-f") == 0) || (strcmp(argv[i], "--file") == 0)) {
+            ++i;
+            globals.startup_set = argv[i];
+        } else if (((strcmp(argv[i], "-r") == 0) || (strcmp(argv[i], "--rc-file") == 0)) && (argv[i + 1])) {
+            ++i;
+            globals.alternate_rc = argv[i];
+        } else if ((strcmp(argv[i], "-d") == 0) || (strcmp(argv[i], "--dont-save") == 0)) {
+            fprintf(stderr, "tX: Do not save settings on exit\n");
+            globals.store_globals = 0;
+
+        } else if ((strcmp(argv[i], "-s") == 0) || (strcmp(argv[i], "--std-out") == 0)) {
+            globals.use_stdout_cmdline = 1;
+            globals.use_stdout = 1;
+        } else if ((strncmp(argv[i], "--device", 8) == 0)) {
+            if (strlen(argv[i] + 9) <= PATH_MAX)
+                strcpy(globals.oss_device, argv[i] + 9);
+            else {
+                show_help();
+                exit(1);
+            }
+        } else {
+            show_help();
+            exit(1);
+        }
+    }
+    return 1;
 }
 
-void checkenv(const char *name)
-{
-       char *value;
-       int length;
-       
-       value=getenv(name);
-       if (value) {
-               length=strlen(value);
-               /*
+void checkenv(const char* name) {
+    char* value;
+    int length;
+
+    value = getenv(name);
+    if (value) {
+        length = strlen(value);
+        /*
                 strnlen requires extra macros...
                 length=strnlen(value, PATH_MAX+1);
                */
-               
-               if (length>=PATH_MAX) {
-                       tX_error("Your \"%s\" environment variable seems malicious (%i chars).", name, length);
-                       tX_error("Please correct that and restart terminatorX.");
-                       exit(-1);
-               }
-       }
+
+        if (length >= PATH_MAX) {
+            tX_error("Your \"%s\" environment variable seems malicious (%i chars).", name, length);
+            tX_error("Please correct that and restart terminatorX.");
+            exit(-1);
+        }
+    }
 }
 
-int main(int argc, char **argv)
-{
-       bool keep_caps_failed = false;
-       bool root_dropped = false;
-
-#ifdef USE_CAPABILITIES        
-       if (!geteuid()) {
-               if (prctl(PR_SET_KEEPCAPS, 1, -1, -1, -1)) {
-                       keep_caps_failed = true;
-               }
-               set_nice_capability(CAP_PERMITTED);
-       }
+int main(int argc, char** argv) {
+    bool keep_caps_failed = false;
+    bool root_dropped = false;
+
+#ifdef USE_CAPABILITIES
+    if (!geteuid()) {
+        if (prctl(PR_SET_KEEPCAPS, 1, -1, -1, -1)) {
+            keep_caps_failed = true;
+        }
+        set_nice_capability(CAP_PERMITTED);
+    }
 #endif
 
-       GError *mouse_error = mouse.open_channel();
-
-       if ((!geteuid()) && (getuid() != geteuid())) {
-               int result=setuid(getuid());
-               root_dropped = true;
-               
-               if (result) {
-                       tX_error("main() panic: can't drop root privileges.");
-                       exit(2);
-               }
-       }
-       
-       /* No suidroot below this comment. */
-
-       fprintf(stderr, "%s - Copyright (C) 1999-2021 by Alexander König\n", VERSIONSTRING);
-       fprintf(stderr, "terminatorX comes with ABSOLUTELY NO WARRANTY - for details read the license.\n");
-
-       if (keep_caps_failed) {
-               tX_error("failed to keep capabilities.");
-       }
-
-       if (root_dropped) {
-               tX_msg("started suid-root - root privileges dropped.");
-       }
-
-       
-#ifdef USE_CAPABILITIES                
-       set_nice_capability(CAP_EFFECTIVE);     
+    GError* mouse_error = mouse.open_channel();
+
+    if ((!geteuid()) && (getuid() != geteuid())) {
+        int result = setuid(getuid());
+        root_dropped = true;
+
+        if (result) {
+            tX_error("main() panic: can't drop root privileges.");
+            exit(2);
+        }
+    }
+
+    /* No suidroot below this comment. */
+
+    fprintf(stderr, "%s - Copyright (C) 1999-2021 by Alexander König\n", VERSIONSTRING);
+    fprintf(stderr, "terminatorX comes with ABSOLUTELY NO WARRANTY - for details read the license.\n");
+
+    if (keep_caps_failed) {
+        tX_error("failed to keep capabilities.");
+    }
+
+    if (root_dropped) {
+        tX_msg("started suid-root - root privileges dropped.");
+    }
+
+#ifdef USE_CAPABILITIES
+    set_nice_capability(CAP_EFFECTIVE);
 #endif
-       
-       /* Theses checks are now sort of unecessary... Anyway... */
-       checkenv("HOME");
-       checkenv("XLOCALEDIR"); 
 
-       gtk_init (&argc, &argv);
-       
+    /* Theses checks are now sort of unecessary... Anyway... */
+    checkenv("HOME");
+    checkenv("XLOCALEDIR");
+
+    gtk_init(&argc, &argv);
+
 #ifdef USE_STARTUP_NOTIFICATION
-       // startup isn't really finished with the nagbox alone...
-       gtk_window_set_auto_startup_notification(FALSE);
-#endif 
-       
-       parse_args(&argc, argv); // loads settings
-
-       if (globals.show_nag) { 
-               show_about(1);
-               g_timeout_add(2000, (GSourceFunc) timeout, NULL);
-       }
-       
-       tX_engine *engine=tX_engine::get_instance();
-       LADSPA_Class::init();
-       LADSPA_Plugin::init();
-
-#ifdef USE_JACK        
-       if (globals.audiodevice_type == JACK) {
-               // only init jack interface when chosen via configuration
-               // to allow wiring of jack in-/outputs
-               tX_jack_client::get_instance()->init();
-       }
-#endif 
+    // startup isn't really finished with the nagbox alone...
+    gtk_window_set_auto_startup_notification(FALSE);
+#endif
+
+    parse_args(&argc, argv); // loads settings
+
+    if (globals.show_nag) {
+        show_about(1);
+        g_timeout_add(2000, (GSourceFunc)timeout, NULL);
+    }
+
+    tX_engine* engine = tX_engine::get_instance();
+    LADSPA_Class::init();
+    LADSPA_Plugin::init();
+
+#ifdef USE_JACK
+    if (globals.audiodevice_type == JACK) {
+        // only init jack interface when chosen via configuration
+        // to allow wiring of jack in-/outputs
+        tX_jack_client::get_instance()->init();
+    }
+#endif
 
 #ifdef USE_SCHEDULER
-       tX_debug("main() GUI thread is p:%i, t:%i and has policy %i.", getpid(), (int) pthread_self(), sched_getscheduler(getpid()));
-#endif 
-       create_maingui(globals.width, globals.height);
-       
-       if (globals.show_nag) {
-               while (!timesup) {
-                       while (gtk_events_pending()) { gtk_main_iteration(); }
-                       gdk_display_flush(gdk_display_get_default());
-                       usleep(250);
-               }
-               destroy_about();
-       }
-       
+    tX_debug("main() GUI thread is p:%i, t:%i and has policy %i.", getpid(), (int)pthread_self(), sched_getscheduler(getpid()));
+#endif
+    create_maingui(globals.width, globals.height);
+
+    if (globals.show_nag) {
+        while (!timesup) {
+            while (gtk_events_pending()) {
+                gtk_main_iteration();
+            }
+            gdk_display_flush(gdk_display_get_default());
+            usleep(250);
+        }
+        destroy_about();
+    }
+
 #ifdef USE_JACK
-       jack_check();
+    jack_check();
 #endif
-       display_maingui();
-       
-       if (globals.startup_set) {
-               while (gtk_events_pending()) { gtk_main_iteration(); }
-               gdk_display_flush(gdk_display_get_default());
-               tX_cursor::set_cursor(tX_cursor::WAIT_CURSOR);
-               load_tt_part(globals.startup_set);
-               tX_cursor::reset_cursor();
-       } else {
+    display_maingui();
+
+    if (globals.startup_set) {
+        while (gtk_events_pending()) {
+            gtk_main_iteration();
+        }
+        gdk_display_flush(gdk_display_get_default());
+        tX_cursor::set_cursor(tX_cursor::WAIT_CURSOR);
+        load_tt_part(globals.startup_set);
+        tX_cursor::reset_cursor();
+    } else {
 #ifdef USE_ALSA_MIDI_IN
-               if (globals.auto_assign_midi) tX_midiin::auto_assign_midi_mappings(NULL, NULL);
-#endif         
-       }
-
-       if (mouse_error) {
-               char buffer[4096];
-               const char *errorFmt = "<span size=\"larger\" weight=\"bold\">Failed to access input hardware</span>\n\n"
-                       "terminatorX failed to get direct access to the Linux input interface and "
-                       "will now fall back to the standard \"pointer warp\" mode, which may result in "
-                       "<span weight=\"bold\">significantly reduced scratching precision</span>.\n\nTo achieve "
-                       "high precision scratching either\n - <span style=\"italic\">install terminatorX suid-root</span>, or\n"
-                       " - <span style=\"italic\">add the users running terminatorX to a group that can access the special "
-                       "file \"/dev/input/mice\"</span>\nand restart terminatorX.\n\n"
-                       "The reported error was: <span weight=\"bold\">%s</span>";
-
-
-               if (globals.input_fallback_warning) {
-                       snprintf(buffer, 4096, errorFmt, mouse_error->message);
-                       GtkWidget *dialog=gtk_message_dialog_new_with_markup(GTK_WINDOW(main_window), GTK_DIALOG_DESTROY_WITH_PARENT,
-                                       GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", "");
-                       gtk_message_dialog_set_markup(GTK_MESSAGE_DIALOG(dialog), buffer);
-                       GtkWidget *message_area = gtk_message_dialog_get_message_area(GTK_MESSAGE_DIALOG(dialog));
-                       GtkWidget *check_button = gtk_check_button_new_with_mnemonic ("Show this warning next time");
-                       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_button), 1);
-                       gtk_widget_show(check_button);
-                       gtk_box_pack_start(GTK_BOX(message_area), check_button, FALSE, FALSE, 0);
-                       gtk_widget_grab_focus(gtk_dialog_get_widget_for_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE));
-                       gtk_dialog_run(GTK_DIALOG(dialog));
-                       globals.input_fallback_warning=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_button));
-                       gtk_widget_destroy(dialog);
-               } else {
-                       tX_warning("Failed t access input hardware: %s", mouse_error->message);
-               }
-
-               g_error_free(mouse_error);
-       }
-               
+        if (globals.auto_assign_midi)
+            tX_midiin::auto_assign_midi_mappings(NULL, NULL);
+#endif
+    }
+
+    if (mouse_error) {
+        char buffer[4096];
+        const char* errorFmt = "<span size=\"larger\" weight=\"bold\">Failed to access input hardware</span>\n\n"
+                               "terminatorX failed to get direct access to the Linux input interface and "
+                               "will now fall back to the standard \"pointer warp\" mode, which may result in "
+                               "<span weight=\"bold\">significantly reduced scratching precision</span>.\n\nTo achieve "
+                               "high precision scratching either\n - <span style=\"italic\">install terminatorX suid-root</span>, or\n"
+                               " - <span style=\"italic\">add the users running terminatorX to a group that can access the special "
+                               "file \"/dev/input/mice\"</span>\nand restart terminatorX.\n\n"
+                               "The reported error was: <span weight=\"bold\">%s</span>";
+
+        if (globals.input_fallback_warning) {
+            snprintf(buffer, 4096, errorFmt, mouse_error->message);
+            GtkWidget* dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(main_window), GTK_DIALOG_DESTROY_WITH_PARENT,
+                GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", "");
+            gtk_message_dialog_set_markup(GTK_MESSAGE_DIALOG(dialog), buffer);
+            GtkWidget* message_area = gtk_message_dialog_get_message_area(GTK_MESSAGE_DIALOG(dialog));
+            GtkWidget* check_button = gtk_check_button_new_with_mnemonic("Show this warning next time");
+            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_button), 1);
+            gtk_widget_show(check_button);
+            gtk_box_pack_start(GTK_BOX(message_area), check_button, FALSE, FALSE, 0);
+            gtk_widget_grab_focus(gtk_dialog_get_widget_for_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE));
+            gtk_dialog_run(GTK_DIALOG(dialog));
+            globals.input_fallback_warning = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_button));
+            gtk_widget_destroy(dialog);
+        } else {
+            tX_warning("Failed t access input hardware: %s", mouse_error->message);
+        }
+
+        g_error_free(mouse_error);
+    }
+
 #ifdef USE_STARTUP_NOTIFICATION
-       gdk_notify_startup_complete();
-#endif 
-       
+    gdk_notify_startup_complete();
+#endif
+
 #ifndef CREATE_BENCHMARK
-       gtk_main();
+    gtk_main();
+
+    store_globals();
 
-       store_globals();
+    mouse.close_channel();
 
-       mouse.close_channel();
+    delete engine;
 
-       delete engine;
-       
-       fprintf(stderr, "Have a nice life.\n");
+    fprintf(stderr, "Have a nice life.\n");
 #else // CREATE_BENCHMARK
-       gtk_widget_hide(main_window);
-       while (gtk_events_pending()) gtk_main_iteration(); gdk_display_flush(gdk_display_get_default());
-       gdk_display_flush(gdk_display_get_default());
-       
-       vtt_class::set_sample_rate(48000);
-       
-       printf("\n* BENCHMARKING *\n");
-       
-       GTimer *bench_time = g_timer_new();
-       gulong micros;
-       double ratio;
-       double res;
-       list <vtt_class *> :: iterator vtt;
-       
-       for (vtt=vtt_class::main_list.begin(); vtt!=vtt_class::main_list.end(); vtt++) {
-               if ((*vtt)->autotrigger) (*vtt)->trigger();
-       }
-       
-       sleep(3);       
-       g_timer_start(bench_time);
-       
-       for (int i=0; i<BENCH_CYCLES; i++) {
-               vtt_class::render_all_turntables();
-       }
-       g_timer_stop(bench_time);
-       res=g_timer_elapsed(bench_time, &micros);
-       
-       ratio=((double) BENCH_CYCLES)/res;
-       printf ("Rendered %i blocks in %f secons,\n=> %f blocks per second.\n\n", (long) BENCH_CYCLES, res, ratio);
+    gtk_widget_hide(main_window);
+    while (gtk_events_pending())
+        gtk_main_iteration();
+    gdk_display_flush(gdk_display_get_default());
+    gdk_display_flush(gdk_display_get_default());
+
+    vtt_class::set_sample_rate(48000);
+
+    printf("\n* BENCHMARKING *\n");
+
+    GTimer* bench_time = g_timer_new();
+    gulong micros;
+    double ratio;
+    double res;
+    list<vtt_class*>::iterator vtt;
+
+    for (vtt = vtt_class::main_list.begin(); vtt != vtt_class::main_list.end(); vtt++) {
+        if ((*vtt)->autotrigger)
+            (*vtt)->trigger();
+    }
+
+    sleep(3);
+    g_timer_start(bench_time);
+
+    for (int i = 0; i < BENCH_CYCLES; i++) {
+        vtt_class::render_all_turntables();
+    }
+    g_timer_stop(bench_time);
+    res = g_timer_elapsed(bench_time, &micros);
+
+    ratio = ((double)BENCH_CYCLES) / res;
+    printf("Rendered %i blocks in %f secons,\n=> %f blocks per second.\n\n", (long)BENCH_CYCLES, res, ratio);
 #endif // CREATE_BENCHMARK
-       return (0);
+    return (0);
 }
index d7956a4063052847a5f281e01e115287dc155503..e9770432b5e9e8dd37b2038e62427297232a618e 100644 (file)
 /*
     terminatorX - realtime audio scratching software
     Copyright (C) 1999-2021  Alexander König
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
+
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
+
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
     File: tX_aduiodevice.cc
-    Description: Implements Audiodevice handling... 
-*/    
+
+    Description: Implements Audiodevice handling...
+*/
 
 #define ALSA_PCM_NEW_HW_PARAMS_API
 
 #include "tX_audiodevice.h"
 #include "tX_vtt.h"
 
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <sys/soundcard.h>
 #include <config.h>
+#include <fcntl.h>
 #include <string.h>
+#include <sys/ioctl.h>
+#include <sys/soundcard.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 
 #include "tX_endian.h"
 
 #ifndef __USE_XOPEN
-#      define __USE_XOPEN // we need this for swab()
-#      include <unistd.h>
-#      undef __USE_XOPEN
+#define __USE_XOPEN // we need this for swab()
+#include <unistd.h>
+#undef __USE_XOPEN
 #else
-#      include <unistd.h>
+#include <unistd.h>
 #endif
 
-#include <string.h>
+#include "tX_engine.h"
 #include <errno.h>
 #include <stdlib.h>
-#include "tX_engine.h"
+#include <string.h>
 
-tX_audiodevice :: tX_audiodevice() : samples_per_buffer(0),
-current_buffer(0), buffer_pos(0), is_open(false)
-{
-       sample_buffer[0]=NULL;
-       sample_buffer[1]=NULL;
-       engine=tX_engine::get_instance();
-}
-
-void tX_audiodevice :: start() {
-       sample_buffer[0]=new int16_t[samples_per_buffer*2];
-       sample_buffer[1]=new int16_t[samples_per_buffer*2];
-       int current=0;
-       vtt_buffer_size=vtt_class::get_mix_buffer_size()<<1;
-       
-       buffer_pos=0;
-       
-       while (!engine->is_stopped()) {
-               current=current ? 0 : 1;
-               
-               int16_t *current_buffer=sample_buffer[current];
-               int16_t *next_buffer=sample_buffer[current ? 0 : 1];
-               
-               fill_buffer(current_buffer, next_buffer);
-               play(current_buffer);
-       }
-       
-       delete [] sample_buffer[0];
-       delete [] sample_buffer[1];
-}
-
-void tX_audiodevice :: fill_buffer(int16_t *target_buffer, int16_t *next_target_buffer) {
-       int prefill=0;
-       
-       while (buffer_pos <= samples_per_buffer) {
-               int16_t *data=engine->render_cycle();
-               
-               int rest=(buffer_pos+vtt_buffer_size)-samples_per_buffer;
-               
-               if (rest<=0) {
-                       memcpy(&target_buffer[buffer_pos], data, vtt_buffer_size << 1);
-               } else {
-                       memcpy(&target_buffer[buffer_pos], data, (vtt_buffer_size-rest) << 1);
-                       memcpy(next_target_buffer, &data[vtt_buffer_size-rest], rest << 1);
-                       prefill=rest;
-               }
-               
-               buffer_pos+=vtt_buffer_size;
-       }
-       
-       buffer_pos=prefill;
+tX_audiodevice ::tX_audiodevice()
+    : samples_per_buffer(0)
+    , current_buffer(0)
+    , buffer_pos(0)
+    , is_open(false) {
+    sample_buffer[0] = NULL;
+    sample_buffer[1] = NULL;
+    engine = tX_engine::get_instance();
+}
+
+void tX_audiodevice ::start() {
+    sample_buffer[0] = new int16_t[samples_per_buffer * 2];
+    sample_buffer[1] = new int16_t[samples_per_buffer * 2];
+    int current = 0;
+    vtt_buffer_size = vtt_class::get_mix_buffer_size() << 1;
+
+    buffer_pos = 0;
+
+    while (!engine->is_stopped()) {
+        current = current ? 0 : 1;
+
+        int16_t* current_buffer = sample_buffer[current];
+        int16_t* next_buffer = sample_buffer[current ? 0 : 1];
+
+        fill_buffer(current_buffer, next_buffer);
+        play(current_buffer);
+    }
+
+    delete[] sample_buffer[0];
+    delete[] sample_buffer[1];
+}
+
+void tX_audiodevice ::fill_buffer(int16_t* target_buffer, int16_t* next_target_buffer) {
+    int prefill = 0;
+
+    while (buffer_pos <= samples_per_buffer) {
+        int16_t* data = engine->render_cycle();
+
+        int rest = (buffer_pos + vtt_buffer_size) - samples_per_buffer;
+
+        if (rest <= 0) {
+            memcpy(&target_buffer[buffer_pos], data, vtt_buffer_size << 1);
+        } else {
+            memcpy(&target_buffer[buffer_pos], data, (vtt_buffer_size - rest) << 1);
+            memcpy(next_target_buffer, &data[vtt_buffer_size - rest], rest << 1);
+            prefill = rest;
+        }
+
+        buffer_pos += vtt_buffer_size;
+    }
+
+    buffer_pos = prefill;
 }
 
 /* Driver Specific Code follows.. */
 
 #ifdef USE_OSS
 
-int tX_audiodevice_oss :: open()
-{
-       int i=0;
-       int p;
-       int buff_cfg;
-
-       if (fd) return (1);
-       fd=::open(globals.oss_device, O_WRONLY, 0);
-       
-       if (fd==-1) {
-               tX_error("tX_audiodevice_oss::open() can't open device: %s", strerror(errno));
-               return -1;
-       }
-       
-       is_open=true;
-       
-       /* setting buffer size */       
-       buff_cfg=(globals.oss_buff_no<<16) | globals.oss_buff_size;
-       p=buff_cfg;
-
-       tX_debug("tX_audiodevice_oss::open() - buff_no: %i, buff_size: %i, buff_cfg: %08x", globals.oss_buff_no, globals.oss_buff_size, buff_cfg);
-               
-       i = ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &p);
-       ioctl(fd, SNDCTL_DSP_RESET, 0);         
-
-       /* 16 Bits */
-       
-       p =  16;
-       i +=  ioctl(fd, SOUND_PCM_WRITE_BITS, &p);
-
-       /* STEREO :) */
-       
-       p =  2;
-       i += ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &p);
-       
-       /* 44.1 khz */
-
-       p =  globals.oss_samplerate;
-       i += ioctl(fd, SOUND_PCM_WRITE_RATE, &p);
-       
-       sample_rate=globals.oss_samplerate;
-       
-       /* Figure actual blocksize.. */
-       
-       i += ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &blocksize);
-
-       samples_per_buffer=blocksize/sizeof(int16_t);
-
-       tX_debug("tX_adudiodevice_oss::open() - blocksize: %i, samples_per_buffer: %i", blocksize, samples_per_buffer);
-       
-       ioctl(fd, SNDCTL_DSP_SYNC, 0);
-
-       return i;
-}
-
-int tX_audiodevice_oss :: close()
-{
-       if (!fd) {      
-               return(1);              
-       }
-       is_open=false;
-       ::close(fd);
-       fd=0;
-       blocksize=0;
-               
-       return 0;
-}
-
-tX_audiodevice_oss :: tX_audiodevice_oss() : tX_audiodevice(),
-fd(0), blocksize(0) {}
-
-void tX_audiodevice_oss :: play(int16_t *buffer)
-{
+int tX_audiodevice_oss ::open() {
+    int i = 0;
+    int p;
+    int buff_cfg;
+
+    if (fd)
+        return (1);
+    fd = ::open(globals.oss_device, O_WRONLY, 0);
+
+    if (fd == -1) {
+        tX_error("tX_audiodevice_oss::open() can't open device: %s", strerror(errno));
+        return -1;
+    }
+
+    is_open = true;
+
+    /* setting buffer size */
+    buff_cfg = (globals.oss_buff_no << 16) | globals.oss_buff_size;
+    p = buff_cfg;
+
+    tX_debug("tX_audiodevice_oss::open() - buff_no: %i, buff_size: %i, buff_cfg: %08x", globals.oss_buff_no, globals.oss_buff_size, buff_cfg);
+
+    i = ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &p);
+    ioctl(fd, SNDCTL_DSP_RESET, 0);
+
+    /* 16 Bits */
+
+    p = 16;
+    i += ioctl(fd, SOUND_PCM_WRITE_BITS, &p);
+
+    /* STEREO :) */
+
+    p = 2;
+    i += ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &p);
+
+    /* 44.1 khz */
+
+    p = globals.oss_samplerate;
+    i += ioctl(fd, SOUND_PCM_WRITE_RATE, &p);
+
+    sample_rate = globals.oss_samplerate;
+
+    /* Figure actual blocksize.. */
+
+    i += ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &blocksize);
+
+    samples_per_buffer = blocksize / sizeof(int16_t);
+
+    tX_debug("tX_adudiodevice_oss::open() - blocksize: %i, samples_per_buffer: %i", blocksize, samples_per_buffer);
+
+    ioctl(fd, SNDCTL_DSP_SYNC, 0);
+
+    return i;
+}
+
+int tX_audiodevice_oss ::close() {
+    if (!fd) {
+        return (1);
+    }
+    is_open = false;
+    ::close(fd);
+    fd = 0;
+    blocksize = 0;
+
+    return 0;
+}
+
+tX_audiodevice_oss ::tX_audiodevice_oss()
+    : tX_audiodevice()
+    , fd(0)
+    , blocksize(0) {}
+
+void tX_audiodevice_oss ::play(int16_t* buffer) {
 #ifdef BIG_ENDIAN_MACHINE
-       swapbuffer (buffer, samples_per_buffer);
+    swapbuffer(buffer, samples_per_buffer);
 #endif
-       int res=write(fd, buffer, blocksize);   
-       if (res==-1) {
-               tX_error("failed to write to audiodevice: %s", strerror(errno));
-               exit(-1);
-       }
+    int res = write(fd, buffer, blocksize);
+    if (res == -1) {
+        tX_error("failed to write to audiodevice: %s", strerror(errno));
+        exit(-1);
+    }
 }
 
 #endif //USE_OSS
 
 #ifdef USE_ALSA
 
-#define tX_abs(x) (x<0 ? -x : x)
-
-int tX_audiodevice_alsa :: open()
-{
-       snd_pcm_stream_t stream = SND_PCM_STREAM_PLAYBACK;
-       snd_pcm_hw_params_t *hw_params;
-       char pcm_name[64];
-       char *pos;
-       
-       strncpy(pcm_name, globals.alsa_device_id, sizeof(pcm_name));
-       if ((pos = strchr(pcm_name, '#')) != NULL) *pos = 0;
-       
-       if (snd_pcm_open(&pcm_handle, pcm_name, stream, 0) < 0) {
-               tX_error("ALSA: Failed to access PCM device \"%s\"", pcm_name);
-               return -1;
-       }
-       
-       is_open=true;
-
-       snd_pcm_hw_params_alloca(&hw_params);   
-       
-       if (snd_pcm_hw_params_any(pcm_handle, hw_params) < 0) {
-               tX_error("ALSA: Failed to configure PCM device \"%s\"", pcm_name);
-               snd_pcm_hw_params_free (hw_params);
-               return -1;
-       }
-       
-       /* Setting INTERLEAVED stereo... */
+#define tX_abs(x) (x < 0 ? -x : x)
+
+int tX_audiodevice_alsa ::open() {
+    snd_pcm_stream_t stream = SND_PCM_STREAM_PLAYBACK;
+    snd_pcm_hw_params_t* hw_params;
+    char pcm_name[64];
+    char* pos;
+
+    strncpy(pcm_name, globals.alsa_device_id, sizeof(pcm_name));
+    if ((pos = strchr(pcm_name, '#')) != NULL)
+        *pos = 0;
+
+    if (snd_pcm_open(&pcm_handle, pcm_name, stream, 0) < 0) {
+        tX_error("ALSA: Failed to access PCM device \"%s\"", pcm_name);
+        return -1;
+    }
+
+    is_open = true;
+
+    snd_pcm_hw_params_alloca(&hw_params);
+
+    if (snd_pcm_hw_params_any(pcm_handle, hw_params) < 0) {
+        tX_error("ALSA: Failed to configure PCM device \"%s\"", pcm_name);
+        snd_pcm_hw_params_free(hw_params);
+        return -1;
+    }
+
+    /* Setting INTERLEAVED stereo... */
 #ifdef USE_ALSA_MEMCPY
-       if (snd_pcm_hw_params_set_access(pcm_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED) < 0) {
+    if (snd_pcm_hw_params_set_access(pcm_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED) < 0) {
 #else
-       if (snd_pcm_hw_params_set_access(pcm_handle, hw_params, SND_PCM_ACCESS_MMAP_INTERLEAVED) < 0) {
-#endif 
-               tX_error("ALSA: Failed to set interleaved access for PCM device \"%s\"", pcm_name);
-               snd_pcm_hw_params_free (hw_params);
-               return -1;
-       }
-       
-       /* Make it 16 Bit native endian */
-       if (snd_pcm_hw_params_set_format(pcm_handle, hw_params, SND_PCM_FORMAT_S16) < 0) {
-               tX_error("ALSA: Error setting 16 Bit sample width for PCM device \"%s\"", pcm_name);
-               snd_pcm_hw_params_free (hw_params);
-               return -1;
-       }
-       
-       /* Setting sampling rate */
-       unsigned int hw_rate=(unsigned int)globals.alsa_samplerate;
-       int dir;
-       
-       if (snd_pcm_hw_params_set_rate_near(pcm_handle, hw_params, &hw_rate, &dir) < 0) {
-               tX_error("ALSA: Failed setting sample rate: %i", globals.alsa_samplerate);
-               snd_pcm_hw_params_free (hw_params);
-               return -1;
-       }
-       
-       if (dir != 0) {
-               if (tX_abs(globals.alsa_samplerate - hw_rate) > 2) {
-                       tX_warning("ALSA: The PCM device \"%s\" doesn\'t support %i Hz playback - using %i instead", pcm_name, globals.alsa_samplerate, hw_rate);
-               }
-       }       
-
-       sample_rate=hw_rate;
-       
-       /* Using stereo output */
-       if (snd_pcm_hw_params_set_channels(pcm_handle, hw_params, 2) < 0) {
-               tX_error("ALSA: PCM device \"%s\" does not support stereo operation", pcm_name);
-               snd_pcm_hw_params_free (hw_params);
-               return -1;
-       }
-       
-       unsigned int buffer_time=globals.alsa_buffer_time;
-       unsigned int period_time=globals.alsa_period_time;
-       
-       if (snd_pcm_hw_params_set_buffer_time_near(pcm_handle, hw_params, &buffer_time, &dir) < 0) {
-               tX_error("ALSA: failed to set the buffer time opf %i usecs", globals.alsa_buffer_time);
-               return -1;
-       }
-
-       long unsigned int buffer_size;
-
-       if (snd_pcm_hw_params_get_buffer_size(hw_params, &buffer_size) < 0) {
-               tX_error("ALSA: failed to retrieve buffer size");
-               return -1;
-       }
-       
-       tX_debug("ALSA: buffer size is %lu", buffer_size);
-       
-       if (snd_pcm_hw_params_set_period_time_near(pcm_handle, hw_params, &period_time, &dir) < 0) {
-               tX_error("ALSA: failed to set period time %i", globals.alsa_period_time);
-               return -1;
-       }
-       
-       if (snd_pcm_hw_params_get_period_size(hw_params, &period_size, &dir)<0) {
-               tX_error("ALSA: failed to retrieve period size");
-               return -1;
-       }
-       
-       samples_per_buffer=period_size;
-       
-       /* Apply all that setup work.. */
-       if (snd_pcm_hw_params(pcm_handle, hw_params) < 0) {
-               tX_error("ALSA: Failed to apply settings to PCM device \"%s\"", pcm_name);
-               snd_pcm_hw_params_free (hw_params);
-               return -1;
-       }
-       
-       if (globals.alsa_free_hwstats) {
-               snd_pcm_hw_params_free (hw_params);
-       }
-       
-       return 0; //snd_pcm_prepare(pcm_handle);
-}
-
-int tX_audiodevice_alsa :: close()
-{
-       if (is_open) {
-               snd_pcm_close(pcm_handle);
-       }
-       is_open=false;
-       
-       return 0;
-}
-
-tX_audiodevice_alsa :: tX_audiodevice_alsa() : tX_audiodevice(),
-pcm_handle(NULL) {}
-
-void tX_audiodevice_alsa :: play(int16_t *buffer)
-{
-       int underrun_ctr=0;
-       snd_pcm_sframes_t pcmreturn;
-       
+    if (snd_pcm_hw_params_set_access(pcm_handle, hw_params, SND_PCM_ACCESS_MMAP_INTERLEAVED) < 0) {
+#endif
+        tX_error("ALSA: Failed to set interleaved access for PCM device \"%s\"", pcm_name);
+        snd_pcm_hw_params_free(hw_params);
+        return -1;
+    }
+
+    /* Make it 16 Bit native endian */
+    if (snd_pcm_hw_params_set_format(pcm_handle, hw_params, SND_PCM_FORMAT_S16) < 0) {
+        tX_error("ALSA: Error setting 16 Bit sample width for PCM device \"%s\"", pcm_name);
+        snd_pcm_hw_params_free(hw_params);
+        return -1;
+    }
+
+    /* Setting sampling rate */
+    unsigned int hw_rate = (unsigned int)globals.alsa_samplerate;
+    int dir;
+
+    if (snd_pcm_hw_params_set_rate_near(pcm_handle, hw_params, &hw_rate, &dir) < 0) {
+        tX_error("ALSA: Failed setting sample rate: %i", globals.alsa_samplerate);
+        snd_pcm_hw_params_free(hw_params);
+        return -1;
+    }
+
+    if (dir != 0) {
+        if (tX_abs(globals.alsa_samplerate - hw_rate) > 2) {
+            tX_warning("ALSA: The PCM device \"%s\" doesn\'t support %i Hz playback - using %i instead", pcm_name, globals.alsa_samplerate, hw_rate);
+        }
+    }
+
+    sample_rate = hw_rate;
+
+    /* Using stereo output */
+    if (snd_pcm_hw_params_set_channels(pcm_handle, hw_params, 2) < 0) {
+        tX_error("ALSA: PCM device \"%s\" does not support stereo operation", pcm_name);
+        snd_pcm_hw_params_free(hw_params);
+        return -1;
+    }
+
+    unsigned int buffer_time = globals.alsa_buffer_time;
+    unsigned int period_time = globals.alsa_period_time;
+
+    if (snd_pcm_hw_params_set_buffer_time_near(pcm_handle, hw_params, &buffer_time, &dir) < 0) {
+        tX_error("ALSA: failed to set the buffer time opf %i usecs", globals.alsa_buffer_time);
+        return -1;
+    }
+
+    long unsigned int buffer_size;
+
+    if (snd_pcm_hw_params_get_buffer_size(hw_params, &buffer_size) < 0) {
+        tX_error("ALSA: failed to retrieve buffer size");
+        return -1;
+    }
+
+    tX_debug("ALSA: buffer size is %lu", buffer_size);
+
+    if (snd_pcm_hw_params_set_period_time_near(pcm_handle, hw_params, &period_time, &dir) < 0) {
+        tX_error("ALSA: failed to set period time %i", globals.alsa_period_time);
+        return -1;
+    }
+
+    if (snd_pcm_hw_params_get_period_size(hw_params, &period_size, &dir) < 0) {
+        tX_error("ALSA: failed to retrieve period size");
+        return -1;
+    }
+
+    samples_per_buffer = period_size;
+
+    /* Apply all that setup work.. */
+    if (snd_pcm_hw_params(pcm_handle, hw_params) < 0) {
+        tX_error("ALSA: Failed to apply settings to PCM device \"%s\"", pcm_name);
+        snd_pcm_hw_params_free(hw_params);
+        return -1;
+    }
+
+    if (globals.alsa_free_hwstats) {
+        snd_pcm_hw_params_free(hw_params);
+    }
+
+    return 0; //snd_pcm_prepare(pcm_handle);
+}
+
+int tX_audiodevice_alsa ::close() {
+    if (is_open) {
+        snd_pcm_close(pcm_handle);
+    }
+    is_open = false;
+
+    return 0;
+}
+
+tX_audiodevice_alsa ::tX_audiodevice_alsa()
+    : tX_audiodevice()
+    , pcm_handle(NULL) {}
+
+void tX_audiodevice_alsa ::play(int16_t* buffer) {
+    int underrun_ctr = 0;
+    snd_pcm_sframes_t pcmreturn;
+
 #ifdef USE_ALSA_MEMCPY
-       pcmreturn = snd_pcm_writei(pcm_handle, buffer, samples_per_buffer >> 1);
-#else  
-       pcmreturn = snd_pcm_mmap_writei(pcm_handle, buffer, samples_per_buffer >> 1);
+    pcmreturn = snd_pcm_writei(pcm_handle, buffer, samples_per_buffer >> 1);
+#else
+    pcmreturn = snd_pcm_mmap_writei(pcm_handle, buffer, samples_per_buffer >> 1);
 #endif
-       
-       while (pcmreturn==-EPIPE) {
-               snd_pcm_prepare(pcm_handle);
-               
+
+    while (pcmreturn == -EPIPE) {
+        snd_pcm_prepare(pcm_handle);
+
 #ifdef USE_ALSA_MEMCPY
-               pcmreturn = snd_pcm_writei(pcm_handle, buffer, samples_per_buffer >> 1);
-#else  
-               pcmreturn = snd_pcm_mmap_writei(pcm_handle, buffer, samples_per_buffer >> 1);
+        pcmreturn = snd_pcm_writei(pcm_handle, buffer, samples_per_buffer >> 1);
+#else
+        pcmreturn = snd_pcm_mmap_writei(pcm_handle, buffer, samples_per_buffer >> 1);
 #endif
-               underrun_ctr++;
-               if (underrun_ctr>100) {
-                       tX_error("tX_audiodevice_alsa::play() more than 10 EPIPE cycles. Giving up.");
-                       break;
-               }
-               //tX_warning("ALSA: ** buffer underrun **");
-       }
-       
-       if (pcmreturn<0) {
-               printf("snd_pcm_writei says: %s.\n", strerror(-1*pcmreturn));
-       }
+        underrun_ctr++;
+        if (underrun_ctr > 100) {
+            tX_error("tX_audiodevice_alsa::play() more than 10 EPIPE cycles. Giving up.");
+            break;
+        }
+        //tX_warning("ALSA: ** buffer underrun **");
+    }
+
+    if (pcmreturn < 0) {
+        printf("snd_pcm_writei says: %s.\n", strerror(-1 * pcmreturn));
+    }
 }
 
 #endif //USE_ALSA
@@ -354,234 +355,238 @@ void tX_audiodevice_alsa :: play(int16_t *buffer)
 #ifdef USE_PULSE
 #include <pulse/error.h>
 
-void tX_audiodevice_pulse::wrap_stream_started_callback(pa_stream *stream, void *userdata) {
-       tX_audiodevice_pulse *device = (tX_audiodevice_pulse *) userdata;
-       device->stream_started_callback(stream);
+void tX_audiodevice_pulse::wrap_stream_started_callback(pa_stream* stream, void* userdata) {
+    tX_audiodevice_pulse* device = (tX_audiodevice_pulse*)userdata;
+    device->stream_started_callback(stream);
 }
 
-void tX_audiodevice_pulse::wrap_stream_underflow_callback(pa_stream *stream, void *userdata) {
-       tX_audiodevice_pulse *device = (tX_audiodevice_pulse *) userdata;
-       device->stream_underflow_callback(stream);
+void tX_audiodevice_pulse::wrap_stream_underflow_callback(pa_stream* stream, void* userdata) {
+    tX_audiodevice_pulse* device = (tX_audiodevice_pulse*)userdata;
+    device->stream_underflow_callback(stream);
 }
 
-void tX_audiodevice_pulse::wrap_stream_overflow_callback(pa_stream *stream, void *userdata) {
-       tX_audiodevice_pulse *device = (tX_audiodevice_pulse *) userdata;
-       device->stream_overflow_callback(stream);
+void tX_audiodevice_pulse::wrap_stream_overflow_callback(pa_stream* stream, void* userdata) {
+    tX_audiodevice_pulse* device = (tX_audiodevice_pulse*)userdata;
+    device->stream_overflow_callback(stream);
 }
 
-void tX_audiodevice_pulse::wrap_stream_drain_complete_callback(pa_stream *stream, int success, void *userdata) {
-       tX_audiodevice_pulse *device = (tX_audiodevice_pulse *) userdata;
-       device->stream_drain_complete_callback(stream, success);
+void tX_audiodevice_pulse::wrap_stream_drain_complete_callback(pa_stream* stream, int success, void* userdata) {
+    tX_audiodevice_pulse* device = (tX_audiodevice_pulse*)userdata;
+    device->stream_drain_complete_callback(stream, success);
 }
 
-void tX_audiodevice_pulse::wrap_stream_trigger_success_callback(pa_stream *stream, int success, void *userdata) {
-       tX_audiodevice_pulse *device = (tX_audiodevice_pulse *) userdata;
-       device->stream_trigger_success_callback(stream, success);
+void tX_audiodevice_pulse::wrap_stream_trigger_success_callback(pa_stream* stream, int success, void* userdata) {
+    tX_audiodevice_pulse* device = (tX_audiodevice_pulse*)userdata;
+    device->stream_trigger_success_callback(stream, success);
 }
 
-void tX_audiodevice_pulse::wrap_stream_write_callback(pa_stream *stream, size_t length, void *userdata) {
-       tX_audiodevice_pulse *device = (tX_audiodevice_pulse *) userdata;
-       device->stream_write_callback(stream, length);
+void tX_audiodevice_pulse::wrap_stream_write_callback(pa_stream* stream, size_t length, void* userdata) {
+    tX_audiodevice_pulse* device = (tX_audiodevice_pulse*)userdata;
+    device->stream_write_callback(stream, length);
 }
 
-void tX_audiodevice_pulse::wrap_context_state_callback(pa_context *context, void *userdata) {
-       tX_audiodevice_pulse *device = (tX_audiodevice_pulse *) userdata;
-       device->context_state_callback(context);
+void tX_audiodevice_pulse::wrap_context_state_callback(pa_context* context, void* userdata) {
+    tX_audiodevice_pulse* device = (tX_audiodevice_pulse*)userdata;
+    device->context_state_callback(context);
 }
 
-void tX_audiodevice_pulse::context_state_callback(pa_context *context) {
-       pa_context_state_t state;
+void tX_audiodevice_pulse::context_state_callback(pa_context* context) {
+    pa_context_state_t state;
+
+    state = pa_context_get_state(context);
+
+    tX_debug("pulseaudio context state: %i", state);
+    switch (state) {
+    case PA_CONTEXT_UNCONNECTED:
+    case PA_CONTEXT_CONNECTING:
+    case PA_CONTEXT_AUTHORIZING:
+    case PA_CONTEXT_SETTING_NAME:
+        break;
+    case PA_CONTEXT_FAILED:
+    case PA_CONTEXT_TERMINATED:
+        if (!engine->is_stopped()) {
+            tX_error("pulseaudio disconnected");
+        }
+        break;
+
+    case PA_CONTEXT_READY:
+        pa_sample_spec spec = {
+            .format = PA_SAMPLE_S16LE,
+            .rate = 44100,
+            .channels = 2
+        };
 
-       state = pa_context_get_state(context);
+        pa_buffer_attr attr = {
+            .maxlength = (uint32_t)-1,
+            .tlength = (uint32_t)(globals.pulse_buffer_length * 2 * sizeof(int16_t)), // 2 bytes per sample, 2 channels
+            .prebuf = (uint32_t)-1,
+            .minreq = (uint32_t)-1,
+            .fragsize = (uint32_t)-1
+        };
 
-       tX_debug("pulseaudio context state: %i", state);
-       switch (state) {
-               case PA_CONTEXT_UNCONNECTED:
-               case PA_CONTEXT_CONNECTING:
-               case PA_CONTEXT_AUTHORIZING:
-               case PA_CONTEXT_SETTING_NAME:
-                       break;
-               case PA_CONTEXT_FAILED:
-               case PA_CONTEXT_TERMINATED:
-                       if (!engine->is_stopped()) {
-                               tX_error("pulseaudio disconnected");
-                       }
-                       break;
+        pa_stream_flags_t flags = PA_STREAM_ADJUST_LATENCY;
 
-               case PA_CONTEXT_READY:
-                       pa_sample_spec spec = {
-                               .format = PA_SAMPLE_S16LE,
-                               .rate = 44100,
-                               .channels = 2
-                       };
-       
-                       pa_buffer_attr attr = {
-                               .maxlength = (uint32_t) -1,
-                               .tlength = (uint32_t) (globals.pulse_buffer_length * 2 * sizeof(int16_t)), // 2 bytes per sample, 2 channels
-                               .prebuf = (uint32_t) -1,
-                               .minreq = (uint32_t) -1,
-                               .fragsize = (uint32_t) -1
-                       };
+        if ((stream = pa_stream_new(context, "terminatorX", &spec, NULL))) {
+            tX_debug("pulseaudio stream created");
+            //pa_stream_set_started_callback(stream, tX_audiodevice_pulse::wrap_stream_started_callback, this);
+            //pa_stream_set_underflow_callback(stream, tX_audiodevice_pulse::wrap_stream_underflow_callback, this);
+            pa_stream_set_overflow_callback(stream, tX_audiodevice_pulse::wrap_stream_overflow_callback, this);
+            pa_stream_set_write_callback(stream, tX_audiodevice_pulse::wrap_stream_write_callback, this);
 
-                       pa_stream_flags_t flags = PA_STREAM_ADJUST_LATENCY;
-
-                       if ((stream = pa_stream_new(context, "terminatorX", &spec, NULL))) {
-                               tX_debug("pulseaudio stream created");
-                               //pa_stream_set_started_callback(stream, tX_audiodevice_pulse::wrap_stream_started_callback, this);
-                               //pa_stream_set_underflow_callback(stream, tX_audiodevice_pulse::wrap_stream_underflow_callback, this);
-                               pa_stream_set_overflow_callback(stream, tX_audiodevice_pulse::wrap_stream_overflow_callback, this);
-                               pa_stream_set_write_callback(stream, tX_audiodevice_pulse::wrap_stream_write_callback, this);
-
-                               if (pa_stream_connect_playback(stream, NULL, &attr, flags, NULL, NULL) >= 0) {
-                                       // start the playback.
-                                       pa_stream_trigger(stream, tX_audiodevice_pulse::wrap_stream_trigger_success_callback, this);
-                               } else {
-                                       tX_error("Failed to connect pulseaudio stream playback: %s", pa_strerror(pa_context_errno(context)));
-                               }
-                       }       else {
-                               tX_error("Failed to create pulseaudio stream: %s", pa_strerror(pa_context_errno(context)));
-                       }
-                       break;
-       }
-}
-
-void tX_audiodevice_pulse::wrap_context_drain_complete_callback(pa_context *context, void *userdata) {
-       tX_audiodevice_pulse *device = (tX_audiodevice_pulse *) userdata;
-       device->context_drain_complete_callback(context);
-}
-
-void tX_audiodevice_pulse::context_drain_complete_callback(pa_context *context) {
-       pa_context_disconnect(context);
-       is_open = false;
-       pa_mainloop_quit(mainloop, 0);
-}
-
-void tX_audiodevice_pulse::stream_started_callback(pa_stream *stream) {
-       tX_debug("pulseaudio stream started");
-}
-
-void tX_audiodevice_pulse::stream_underflow_callback(pa_stream *stream) {
-       tX_debug("pulseaudio stream underflow");
-}
-
-void tX_audiodevice_pulse::stream_overflow_callback(pa_stream *stream) {
-       tX_debug("pulseaudio stream overflow");
-}
-
-void tX_audiodevice_pulse::stream_trigger_success_callback(pa_stream *stream, int success) {
-       tX_debug("pulseaudio trigger success %i", success);
-}
-
-void tX_audiodevice_pulse::stream_drain_complete_callback(pa_stream *stream, int success) {
-       if (!success) {
-               tX_debug("pulseaudio drain failed %s", pa_strerror(pa_context_errno(context)));
-       } else {
-               pa_operation *operation;
-               pa_stream_disconnect(stream);
-               pa_stream_unref(stream);
-               stream = NULL;
-
-               if (!(operation = pa_context_drain(context, tX_audiodevice_pulse::wrap_context_drain_complete_callback, this))) {
-                       pa_context_disconnect(context);
-                       is_open = false;
-                       pa_mainloop_quit(mainloop, -1);
-               } else {
-                       pa_operation_unref(operation);
-               }
-       }
-}
-
-void tX_audiodevice_pulse::stream_write_callback(pa_stream *stream, size_t length) {
-       size_t sample_length = length/2;
-
-       if (engine->is_stopped()) {
-               tX_debug("pulseaudio write callback trying to disconnect pulseaudio");
-               pa_operation *operation;
-               pa_stream_set_write_callback(stream, NULL, NULL);
-               if (!(operation = pa_stream_drain(stream, tX_audiodevice_pulse::wrap_stream_drain_complete_callback, this))) {
-                       tX_error("pulseaudio failed to initiate drain %s", pa_strerror(pa_context_errno(context)));
-               }
-               pa_operation_unref(operation);
-       } else {
-               unsigned int outbuffer_pos=0;
-               unsigned int sample;
-       
-               int16_t *outbuffer = NULL;
-               size_t outbuffer_bytes = length;
-               pa_stream_begin_write(stream, (void **) &outbuffer, &outbuffer_bytes);
-
-               if (samples_in_overrun_buffer) {
-                       memcpy(outbuffer, overrun_buffer, sizeof(int16_t) * samples_in_overrun_buffer);
-                       outbuffer_pos+=samples_in_overrun_buffer;
-               }
-       
-               while (outbuffer_pos<sample_length) {
-                       int16_t *data=engine->render_cycle();
-
-                       sample = tX_min(vtt_class::samples_in_mix_buffer, (sample_length - outbuffer_pos));
-
-                       memcpy(&outbuffer[outbuffer_pos], data, sizeof(int16_t) * sample);
-                       outbuffer_pos+=sample;
-               
-                       if (sample < vtt_class::samples_in_mix_buffer) {
-                               samples_in_overrun_buffer=vtt_class::samples_in_mix_buffer-sample;
-                               /* There's more data in the mixbuffer... */
-                               memcpy(overrun_buffer, &data[sample], sizeof(int16_t) * samples_in_overrun_buffer);
-                       } else {
-                               samples_in_overrun_buffer=0;
-                       }
-               }
-       
-               if (pa_stream_write(stream, (uint8_t *) outbuffer, length, NULL, 0, PA_SEEK_RELATIVE) < 0) {
-                       tX_error("pulseaudio error writing to stream: %s", pa_strerror(pa_context_errno(context)));
-               }
-               outbuffer = NULL;
-       }
+            if (pa_stream_connect_playback(stream, NULL, &attr, flags, NULL, NULL) >= 0) {
+                // start the playback.
+                pa_stream_trigger(stream, tX_audiodevice_pulse::wrap_stream_trigger_success_callback, this);
+            } else {
+                tX_error("Failed to connect pulseaudio stream playback: %s", pa_strerror(pa_context_errno(context)));
+            }
+        } else {
+            tX_error("Failed to create pulseaudio stream: %s", pa_strerror(pa_context_errno(context)));
+        }
+        break;
+    }
+}
+
+void tX_audiodevice_pulse::wrap_context_drain_complete_callback(pa_context* context, void* userdata) {
+    tX_audiodevice_pulse* device = (tX_audiodevice_pulse*)userdata;
+    device->context_drain_complete_callback(context);
+}
+
+void tX_audiodevice_pulse::context_drain_complete_callback(pa_context* context) {
+    pa_context_disconnect(context);
+    is_open = false;
+    pa_mainloop_quit(mainloop, 0);
+}
+
+void tX_audiodevice_pulse::stream_started_callback(pa_stream* stream) {
+    tX_debug("pulseaudio stream started");
+}
+
+void tX_audiodevice_pulse::stream_underflow_callback(pa_stream* stream) {
+    tX_debug("pulseaudio stream underflow");
+}
+
+void tX_audiodevice_pulse::stream_overflow_callback(pa_stream* stream) {
+    tX_debug("pulseaudio stream overflow");
+}
+
+void tX_audiodevice_pulse::stream_trigger_success_callback(pa_stream* stream, int success) {
+    tX_debug("pulseaudio trigger success %i", success);
+}
+
+void tX_audiodevice_pulse::stream_drain_complete_callback(pa_stream* stream, int success) {
+    if (!success) {
+        tX_debug("pulseaudio drain failed %s", pa_strerror(pa_context_errno(context)));
+    } else {
+        pa_operation* operation;
+        pa_stream_disconnect(stream);
+        pa_stream_unref(stream);
+        stream = NULL;
+
+        if (!(operation = pa_context_drain(context, tX_audiodevice_pulse::wrap_context_drain_complete_callback, this))) {
+            pa_context_disconnect(context);
+            is_open = false;
+            pa_mainloop_quit(mainloop, -1);
+        } else {
+            pa_operation_unref(operation);
+        }
+    }
+}
+
+void tX_audiodevice_pulse::stream_write_callback(pa_stream* stream, size_t length) {
+    size_t sample_length = length / 2;
+
+    if (engine->is_stopped()) {
+        tX_debug("pulseaudio write callback trying to disconnect pulseaudio");
+        pa_operation* operation;
+        pa_stream_set_write_callback(stream, NULL, NULL);
+        if (!(operation = pa_stream_drain(stream, tX_audiodevice_pulse::wrap_stream_drain_complete_callback, this))) {
+            tX_error("pulseaudio failed to initiate drain %s", pa_strerror(pa_context_errno(context)));
+        }
+        pa_operation_unref(operation);
+    } else {
+        unsigned int outbuffer_pos = 0;
+        unsigned int sample;
+
+        int16_t* outbuffer = NULL;
+        size_t outbuffer_bytes = length;
+        pa_stream_begin_write(stream, (void**)&outbuffer, &outbuffer_bytes);
+
+        if (samples_in_overrun_buffer) {
+            memcpy(outbuffer, overrun_buffer, sizeof(int16_t) * samples_in_overrun_buffer);
+            outbuffer_pos += samples_in_overrun_buffer;
+        }
+
+        while (outbuffer_pos < sample_length) {
+            int16_t* data = engine->render_cycle();
+
+            sample = tX_min(vtt_class::samples_in_mix_buffer, (sample_length - outbuffer_pos));
+
+            memcpy(&outbuffer[outbuffer_pos], data, sizeof(int16_t) * sample);
+            outbuffer_pos += sample;
+
+            if (sample < vtt_class::samples_in_mix_buffer) {
+                samples_in_overrun_buffer = vtt_class::samples_in_mix_buffer - sample;
+                /* There's more data in the mixbuffer... */
+                memcpy(overrun_buffer, &data[sample], sizeof(int16_t) * samples_in_overrun_buffer);
+            } else {
+                samples_in_overrun_buffer = 0;
+            }
+        }
+
+        if (pa_stream_write(stream, (uint8_t*)outbuffer, length, NULL, 0, PA_SEEK_RELATIVE) < 0) {
+            tX_error("pulseaudio error writing to stream: %s", pa_strerror(pa_context_errno(context)));
+        }
+        outbuffer = NULL;
+    }
 }
 
 void tX_audiodevice_pulse::start() {
-       overrun_buffer=new int16_t[vtt_class::samples_in_mix_buffer];
-       samples_in_overrun_buffer = 0;
-       int result;
-       
-       tX_debug("handover flow control to pulseaudio");
+    overrun_buffer = new int16_t[vtt_class::samples_in_mix_buffer];
+    samples_in_overrun_buffer = 0;
+    int result;
+
+    tX_debug("handover flow control to pulseaudio");
 
-       while (!engine->is_stopped()) {
-               pa_mainloop_run(mainloop, &result);
-               tX_debug("pulseaudio mainloop has terminated: %i", result);
-       }       
-       
-       delete [] overrun_buffer;
+    while (!engine->is_stopped()) {
+        pa_mainloop_run(mainloop, &result);
+        tX_debug("pulseaudio mainloop has terminated: %i", result);
+    }
+
+    delete[] overrun_buffer;
 }
 
 int tX_audiodevice_pulse::open() {
-       mainloop = pa_mainloop_new();
-       mainloop_api = pa_mainloop_get_api(mainloop);
-       context = pa_context_new(mainloop_api, "terminatorX");
-       pa_context_flags_t flags = PA_CONTEXT_NOFLAGS;
-       pa_context_connect(context, NULL, flags, NULL);
-       pa_context_set_state_callback(context, tX_audiodevice_pulse::wrap_context_state_callback, this);
+    mainloop = pa_mainloop_new();
+    mainloop_api = pa_mainloop_get_api(mainloop);
+    context = pa_context_new(mainloop_api, "terminatorX");
+    pa_context_flags_t flags = PA_CONTEXT_NOFLAGS;
+    pa_context_connect(context, NULL, flags, NULL);
+    pa_context_set_state_callback(context, tX_audiodevice_pulse::wrap_context_state_callback, this);
 
-       sample_rate=44100;
-       tX_debug("pulseaudio opened.");
+    sample_rate = 44100;
+    tX_debug("pulseaudio opened.");
 
-       is_open = true;
-       return 0;
+    is_open = true;
+    return 0;
 }
 
-int tX_audiodevice_pulse :: close() {
-       return 0;
+int tX_audiodevice_pulse ::close() {
+    return 0;
 }
 
-tX_audiodevice_pulse :: tX_audiodevice_pulse() : tX_audiodevice(),
-mainloop(NULL), mainloop_api(NULL), context(NULL), stream(NULL)  {
+tX_audiodevice_pulse ::tX_audiodevice_pulse()
+    : tX_audiodevice()
+    , mainloop(NULL)
+    , mainloop_api(NULL)
+    , context(NULL)
+    , stream(NULL) {
 }
 
-void tX_audiodevice_pulse :: play(int16_t *buffer) {
-       tX_error("tX_audiodevice_pulse::play()");
+void tX_audiodevice_pulse ::play(int16_t* buffer) {
+    tX_error("tX_audiodevice_pulse::play()");
 }
 
-tX_audiodevice_pulse :: ~tX_audiodevice_pulse() {
+tX_audiodevice_pulse ::~tX_audiodevice_pulse() {
 }
 
 #endif //USE_PULSE
@@ -590,182 +595,171 @@ tX_audiodevice_pulse :: ~tX_audiodevice_pulse() {
 
 tX_jack_client tX_jack_client::instance;
 
+bool tX_jack_client::init() {
+    if (!client_initialized) {
+        if ((client = jack_client_open("terminatorX", (jack_options_t)NULL, NULL)) == 0) {
+            tX_error("tX_jack_client() -> failed to connect to jackd.");
+        } else {
+            client_initialized = true;
+            const char** ports;
+
+            /* Setting up jack callbacks... */
+            jack_set_process_callback(client, tX_jack_client::process, NULL);
+            jack_set_sample_rate_callback(client, tX_jack_client::srate, NULL);
+            jack_on_shutdown(client, tX_jack_client::shutdown, NULL);
+
+            /* Creating the port... */
+            left_port = jack_port_register(client, "output_1", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
+            right_port = jack_port_register(client, "output_2", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
+
+            /* Action... */
+            jack_activate(client);
+
+            /* Connect some ports... */
+            if ((ports = jack_get_ports(client, NULL, NULL, JackPortIsPhysical | JackPortIsInput)) == NULL) {
+                tX_error("tX_jack_client() no ports to connect to found. Connect manually.");
+            } else if (ports[0] && ports[1]) {
+                if (jack_connect(client, jack_port_name(left_port), ports[0])) {
+                    tX_error("tX_jack_client() failed to connect left port.");
+                }
+                if (jack_connect(client, jack_port_name(right_port), ports[1])) {
+                    tX_error("tX_jack_client() failed to connect right port.");
+                }
+                free(ports);
+            }
+        }
+    }
 
-bool tX_jack_client::init()
-{
-       if (!client_initialized) {
-               if ((client=jack_client_open("terminatorX", (jack_options_t) NULL, NULL))==0) {
-                       tX_error("tX_jack_client() -> failed to connect to jackd.");
-               } else {
-                       client_initialized = true;
-                       const char **ports;
-                       
-                       /* Setting up jack callbacks... */              
-                       jack_set_process_callback(client, tX_jack_client::process, NULL);
-                       jack_set_sample_rate_callback(client, tX_jack_client::srate, NULL);             
-                       jack_on_shutdown (client, tX_jack_client::shutdown, NULL);
-                       
-                       /* Creating the port... */
-                       left_port = jack_port_register (client, "output_1", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
-                       right_port = jack_port_register (client, "output_2", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
-               
-                       /* Action... */
-                       jack_activate(client);
-                       
-                       /* Connect some ports... */
-                       if ((ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsInput)) == NULL) {
-                               tX_error("tX_jack_client() no ports to connect to found. Connect manually.");
-                       } else if (ports[0] && ports[1]) {
-                               if (jack_connect (client, jack_port_name(left_port), ports[0])) {
-                                       tX_error("tX_jack_client() failed to connect left port.");
-                               }
-                               if (jack_connect (client, jack_port_name(right_port), ports[1])) {
-                                       tX_error("tX_jack_client() failed to connect right port.");
-                               }
-                               free (ports);
-                       }
-               }
-       }
-       
-       return client_initialized;
-}
-
-tX_jack_client::tX_jack_client():device(NULL),jack_shutdown(false),client_initialized(false)
-{
-       jack_set_error_function(tX_jack_client::error);
-}
-
-tX_jack_client::~tX_jack_client()
-{
-       if (client) jack_client_close(client);
-}
-
-void tX_jack_client::error(const char *desc)
-{
-       tX_error("jack error: %s.", desc);
-}
-
-int tX_jack_client::srate(jack_nframes_t nframes, void *arg)
-{
-       tX_error("tX_jack_client::srate() jack changed samplerate - ignored.");
-       return 0;
-}
-
-void tX_jack_client::shutdown(void *arg)
-{
-       tX_error("tX_jack_client::shutdown() jack daemon has shut down. Bad!");
-       instance.jack_shutdown=true;
-}
-
-int tX_jack_client::process(jack_nframes_t nframes, void *arg)
-{
-       return instance.play(nframes);
-       
-       /* Hmm, what to do in such a case? */
-       return 0;
-}
-
-int tX_jack_client::play(jack_nframes_t nframes)
-{
-       jack_default_audio_sample_t *left = (jack_default_audio_sample_t *) jack_port_get_buffer (left_port, nframes);
-       jack_default_audio_sample_t *right = (jack_default_audio_sample_t *) jack_port_get_buffer (right_port, nframes);
-
-       if (device) {
-               device->fill_frames(left, right, nframes);
-       } else {
-               memset(left, 0, sizeof (jack_default_audio_sample_t) * nframes);
-               memset(right, 0, sizeof (jack_default_audio_sample_t) * nframes);
-       }
-       
-       return 0;
-}
-
-int tX_jack_client::get_sample_rate() 
-{
-       return jack_get_sample_rate(client);
+    return client_initialized;
+}
+
+tX_jack_client::tX_jack_client()
+    : device(NULL)
+    , jack_shutdown(false)
+    , client_initialized(false) {
+    jack_set_error_function(tX_jack_client::error);
+}
+
+tX_jack_client::~tX_jack_client() {
+    if (client)
+        jack_client_close(client);
+}
+
+void tX_jack_client::error(const char* desc) {
+    tX_error("jack error: %s.", desc);
+}
+
+int tX_jack_client::srate(jack_nframes_t nframes, void* arg) {
+    tX_error("tX_jack_client::srate() jack changed samplerate - ignored.");
+    return 0;
+}
+
+void tX_jack_client::shutdown(void* arg) {
+    tX_error("tX_jack_client::shutdown() jack daemon has shut down. Bad!");
+    instance.jack_shutdown = true;
+}
+
+int tX_jack_client::process(jack_nframes_t nframes, void* arg) {
+    return instance.play(nframes);
+
+    /* Hmm, what to do in such a case? */
+    return 0;
+}
+
+int tX_jack_client::play(jack_nframes_t nframes) {
+    jack_default_audio_sample_t* left = (jack_default_audio_sample_t*)jack_port_get_buffer(left_port, nframes);
+    jack_default_audio_sample_t* right = (jack_default_audio_sample_t*)jack_port_get_buffer(right_port, nframes);
+
+    if (device) {
+        device->fill_frames(left, right, nframes);
+    } else {
+        memset(left, 0, sizeof(jack_default_audio_sample_t) * nframes);
+        memset(right, 0, sizeof(jack_default_audio_sample_t) * nframes);
+    }
+
+    return 0;
+}
+
+int tX_jack_client::get_sample_rate() {
+    return jack_get_sample_rate(client);
 }
 
 /* tX_audiodevice_jack */
 
-tX_audiodevice_jack::tX_audiodevice_jack():tX_audiodevice()
-{
-       client=NULL;
-}
-
-int tX_audiodevice_jack::open()
-{
-       tX_jack_client *jack_client=tX_jack_client::get_instance();
-       
-       if (jack_client) {
-               if (jack_client->init()) {
-                       sample_rate=jack_client->get_sample_rate();
-                       client=jack_client;
-                       is_open=true;
-                       
-                       return 0;
-               }
-       }
-       
-       return 1;
-}
-
-int tX_audiodevice_jack::close()
-{
-       if (client) {
-               client->set_device(NULL);
-       }
-       
-       is_open=false;  
-       
-       return 0;
-}
-
-void tX_audiodevice_jack::play(int16_t *buffer)
-{
-       tX_error("tX_audiodevice_jack::play()");
-}
-
-void tX_audiodevice_jack::start()
-{
-       overrun_buffer=new f_prec[vtt_class::samples_in_mix_buffer];
-       
-       client->set_device(this);
-       while ((!engine->is_stopped()) && !(client->get_jack_shutdown())) {
-               usleep(100);
-       }       
-       client->set_device(NULL);
-       
-       delete [] overrun_buffer;
-}
-
-void tX_audiodevice_jack::fill_frames(jack_default_audio_sample_t *left, jack_default_audio_sample_t *right, jack_nframes_t nframes)
-{
-       unsigned int outbuffer_pos=0;
-       unsigned int sample;
-       
-       if (samples_in_overrun_buffer) {
-               for (sample=0; ((sample<samples_in_overrun_buffer) && (outbuffer_pos<nframes));) {
-                       left[outbuffer_pos]=overrun_buffer[sample++]/32767.0;
-                       right[outbuffer_pos++]=overrun_buffer[sample++]/32767.0;
-               }
-       }
-       
-       while (outbuffer_pos<nframes) {
-               engine->render_cycle();
-               
-               for (sample=0; ((sample<(unsigned int) vtt_class::samples_in_mix_buffer) && (outbuffer_pos<nframes));) {
-                       left[outbuffer_pos]=vtt_class::mix_buffer[sample++]/32767.0;
-                       right[outbuffer_pos++]=vtt_class::mix_buffer[sample++]/32767.0;
-               }
-               
-               if (sample<(unsigned int) vtt_class::samples_in_mix_buffer) {
-                       samples_in_overrun_buffer=vtt_class::samples_in_mix_buffer-sample;
-                       /* There's more data in the mixbuffer... */
-                       memcpy(overrun_buffer, &vtt_class::mix_buffer[sample], sizeof(f_prec) * samples_in_overrun_buffer);
-               } else {
-                       samples_in_overrun_buffer=0;
-               }
-       }
+tX_audiodevice_jack::tX_audiodevice_jack()
+    : tX_audiodevice() {
+    client = NULL;
+}
+
+int tX_audiodevice_jack::open() {
+    tX_jack_client* jack_client = tX_jack_client::get_instance();
+
+    if (jack_client) {
+        if (jack_client->init()) {
+            sample_rate = jack_client->get_sample_rate();
+            client = jack_client;
+            is_open = true;
+
+            return 0;
+        }
+    }
+
+    return 1;
+}
+
+int tX_audiodevice_jack::close() {
+    if (client) {
+        client->set_device(NULL);
+    }
+
+    is_open = false;
+
+    return 0;
+}
+
+void tX_audiodevice_jack::play(int16_t* buffer) {
+    tX_error("tX_audiodevice_jack::play()");
+}
+
+void tX_audiodevice_jack::start() {
+    overrun_buffer = new f_prec[vtt_class::samples_in_mix_buffer];
+
+    client->set_device(this);
+    while ((!engine->is_stopped()) && !(client->get_jack_shutdown())) {
+        usleep(100);
+    }
+    client->set_device(NULL);
+
+    delete[] overrun_buffer;
+}
+
+void tX_audiodevice_jack::fill_frames(jack_default_audio_sample_t* left, jack_default_audio_sample_t* right, jack_nframes_t nframes) {
+    unsigned int outbuffer_pos = 0;
+    unsigned int sample;
+
+    if (samples_in_overrun_buffer) {
+        for (sample = 0; ((sample < samples_in_overrun_buffer) && (outbuffer_pos < nframes));) {
+            left[outbuffer_pos] = overrun_buffer[sample++] / 32767.0;
+            right[outbuffer_pos++] = overrun_buffer[sample++] / 32767.0;
+        }
+    }
+
+    while (outbuffer_pos < nframes) {
+        engine->render_cycle();
+
+        for (sample = 0; ((sample < (unsigned int)vtt_class::samples_in_mix_buffer) && (outbuffer_pos < nframes));) {
+            left[outbuffer_pos] = vtt_class::mix_buffer[sample++] / 32767.0;
+            right[outbuffer_pos++] = vtt_class::mix_buffer[sample++] / 32767.0;
+        }
+
+        if (sample < (unsigned int)vtt_class::samples_in_mix_buffer) {
+            samples_in_overrun_buffer = vtt_class::samples_in_mix_buffer - sample;
+            /* There's more data in the mixbuffer... */
+            memcpy(overrun_buffer, &vtt_class::mix_buffer[sample], sizeof(f_prec) * samples_in_overrun_buffer);
+        } else {
+            samples_in_overrun_buffer = 0;
+        }
+    }
 }
 
 #endif // USE_JACK
index c3ec7e14dc6bf84af9bd4d4e62fe04e60151c9f4..a73e0b10e14d4fd1216b3d1da0ccdec3ccece16e 100644 (file)
@@ -1,31 +1,31 @@
 /*
     terminatorX - realtime audio scratching software
     Copyright (C) 1999-2021  Alexander König
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
+
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
+
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
     File: tX_audiodevice.h
+
     Description: Header to tX_maingui.cc
-*/    
+*/
 
 #ifndef _h_tx_audiodevice
 #define _h_tx_audiodevice 1
 
-#include "tX_types.h"
-#include "tX_global.h"
 #include "pthread.h"
+#include "tX_global.h"
+#include "tX_types.h"
 #include <config.h>
 
 #include <sys/time.h>
 
 class tX_engine;
 
-class tX_audiodevice
-{
-       protected:
-       int samples_per_buffer;
-       int16_t *sample_buffer[2];
-       int current_buffer;
-       int buffer_pos;
-       int vtt_buffer_size;
-       tX_engine *engine;
-       bool is_open;
-       
-       int sample_rate;
-       tX_audiodevice();
-       
-       public:
-       int get_buffersize() { return samples_per_buffer; } /* call only valid *after* open() */
-       int get_sample_rate() { return sample_rate; }
-       
-       virtual int open()=0;
-       virtual int close()=0;
-       
-       void fill_buffer(int16_t *target_buffer, int16_t *next_target_buffer);
-
-       bool get_is_open() { return is_open; }
-       virtual void start();   
-       virtual void play(int16_t*)=0; /* play blocked */
-       virtual ~tX_audiodevice() {}
-};
+class tX_audiodevice {
+  protected:
+    int samples_per_buffer;
+    int16_t* sample_buffer[2];
+    int current_buffer;
+    int buffer_pos;
+    int vtt_buffer_size;
+    tX_engine* engine;
+    bool is_open;
+
+    int sample_rate;
+    tX_audiodevice();
+
+  public:
+    int get_buffersize() { return samples_per_buffer; } /* call only valid *after* open() */
+    int get_sample_rate() { return sample_rate; }
 
+    virtual int open() = 0;
+    virtual int close() = 0;
+
+    void fill_buffer(int16_t* target_buffer, int16_t* next_target_buffer);
+
+    bool get_is_open() { return is_open; }
+    virtual void start();
+    virtual void play(int16_t*) = 0; /* play blocked */
+    virtual ~tX_audiodevice() {}
+};
 
 #ifdef USE_OSS
 
-class tX_audiodevice_oss : public tX_audiodevice
-{
-       int fd;
-       int blocksize;  
-
-       public:
-       virtual int open();
-       virtual int close();
-       virtual void play(int16_t*);
-       
-       tX_audiodevice_oss();
+class tX_audiodevice_oss : public tX_audiodevice {
+    int fd;
+    int blocksize;
+
+  public:
+    virtual int open();
+    virtual int close();
+    virtual void play(int16_t*);
+
+    tX_audiodevice_oss();
 };
 
 #endif
 
-
 #ifdef USE_ALSA
 
-class tX_audiodevice_alsa : public tX_audiodevice
-{
-       snd_pcm_t *pcm_handle;
-       snd_pcm_uframes_t period_size;
-       
-       public:
-       virtual int open();
-       virtual int close();
-       virtual void play(int16_t*);
-       
-       tX_audiodevice_alsa();
+class tX_audiodevice_alsa : public tX_audiodevice {
+    snd_pcm_t* pcm_handle;
+    snd_pcm_uframes_t period_size;
+
+  public:
+    virtual int open();
+    virtual int close();
+    virtual void play(int16_t*);
+
+    tX_audiodevice_alsa();
 };
 
 #endif
 
 #ifdef USE_PULSE
 
-class tX_audiodevice_pulse : public tX_audiodevice
-{
-       pa_mainloop *mainloop;
-       pa_mainloop_api *mainloop_api;
-       pa_context *context;
-       pa_stream *stream;
-       int16_t *overrun_buffer;
-       unsigned int samples_in_overrun_buffer;
-
-       public:
-       virtual int open();
-       virtual int close();
-       virtual void start();
-       virtual void play(int16_t*);
-
-       tX_audiodevice_pulse();
-       ~tX_audiodevice_pulse();
-       
-       private:
-       // context callbacks
-       static void wrap_context_state_callback(pa_context *context, void *userdata);
-       void context_state_callback(pa_context *context);
-
-       static void wrap_context_drain_complete_callback(pa_context *context, void *userdata);
-       void context_drain_complete_callback(pa_context *context);
-
-       // stream callbacks
-       static void wrap_stream_started_callback(pa_stream *stream, void *userdata);
-       void stream_started_callback(pa_stream *stream);
-
-       static void wrap_stream_underflow_callback(pa_stream *stream, void *userdata);
-       void stream_underflow_callback(pa_stream *stream);
-       
-       static void wrap_stream_overflow_callback(pa_stream *stream, void *userdata);
-       void stream_overflow_callback(pa_stream *stream);
-       
-       static void wrap_stream_drain_complete_callback(pa_stream *stream, int success, void *userdata);
-       void stream_drain_complete_callback(pa_stream *stream, int success);
-
-       static void wrap_stream_trigger_success_callback(pa_stream *stream, int success, void *userdata);
-       void stream_trigger_success_callback(pa_stream *stream, int success);
-
-       static void wrap_stream_write_callback(pa_stream *stream, size_t length, void *userdata);
-       void stream_write_callback(pa_stream *stream, size_t length);
+class tX_audiodevice_pulse : public tX_audiodevice {
+    pa_mainloop* mainloop;
+    pa_mainloop_api* mainloop_api;
+    pa_context* context;
+    pa_stream* stream;
+    int16_t* overrun_buffer;
+    unsigned int samples_in_overrun_buffer;
+
+  public:
+    virtual int open();
+    virtual int close();
+    virtual void start();
+    virtual void play(int16_t*);
+
+    tX_audiodevice_pulse();
+    ~tX_audiodevice_pulse();
+
+  private:
+    // context callbacks
+    static void wrap_context_state_callback(pa_context* context, void* userdata);
+    void context_state_callback(pa_context* context);
+
+    static void wrap_context_drain_complete_callback(pa_context* context, void* userdata);
+    void context_drain_complete_callback(pa_context* context);
+
+    // stream callbacks
+    static void wrap_stream_started_callback(pa_stream* stream, void* userdata);
+    void stream_started_callback(pa_stream* stream);
+
+    static void wrap_stream_underflow_callback(pa_stream* stream, void* userdata);
+    void stream_underflow_callback(pa_stream* stream);
+
+    static void wrap_stream_overflow_callback(pa_stream* stream, void* userdata);
+    void stream_overflow_callback(pa_stream* stream);
+
+    static void wrap_stream_drain_complete_callback(pa_stream* stream, int success, void* userdata);
+    void stream_drain_complete_callback(pa_stream* stream, int success);
+
+    static void wrap_stream_trigger_success_callback(pa_stream* stream, int success, void* userdata);
+    void stream_trigger_success_callback(pa_stream* stream, int success);
+
+    static void wrap_stream_write_callback(pa_stream* stream, size_t length, void* userdata);
+    void stream_write_callback(pa_stream* stream, size_t length);
 };
 
 #endif
@@ -165,50 +159,48 @@ class tX_audiodevice_pulse : public tX_audiodevice
 
 class tX_jack_client;
 
-class tX_audiodevice_jack : public tX_audiodevice
-{
-       private:
-       tX_jack_client *client;
-       jack_default_audio_sample_t *overrun_buffer;
-       unsigned int samples_in_overrun_buffer;
-       
-       public:
-       virtual int open();
-       virtual int close();
-       virtual void play(int16_t*);
-       virtual void start();
-       void fill_frames(jack_default_audio_sample_t *left, jack_default_audio_sample_t *right, jack_nframes_t nframes);
-       
-       tX_audiodevice_jack();  
+class tX_audiodevice_jack : public tX_audiodevice {
+  private:
+    tX_jack_client* client;
+    jack_default_audio_sample_t* overrun_buffer;
+    unsigned int samples_in_overrun_buffer;
+
+  public:
+    virtual int open();
+    virtual int close();
+    virtual void play(int16_t*);
+    virtual void start();
+    void fill_frames(jack_default_audio_sample_t* left, jack_default_audio_sample_t* right, jack_nframes_t nframes);
+
+    tX_audiodevice_jack();
 };
 
-class tX_jack_client
-{
-       public:
-       static tX_jack_client *get_instance() { return &instance; };
-       bool init();
-       ~tX_jack_client();
-       
-       private:
-       tX_jack_client();       
-       static tX_jack_client instance;
-       static void error(const char *desc);
-       static int srate(jack_nframes_t nframes, void *arg);
-       static void shutdown(void *arg);
-       static int process(jack_nframes_t nframes, void *arg);
-       
-       jack_client_t *client;  
-       tX_audiodevice_jack *device;
-       jack_port_t *left_port;
-       jack_port_t *right_port;
-       bool jack_shutdown;
-       bool client_initialized;
-       int play(jack_nframes_t nframes);
-       
-       public:
-       int get_sample_rate();
-       bool get_jack_shutdown() { return jack_shutdown; }
-       void set_device(tX_audiodevice_jack *dev) { device=dev; }
+class tX_jack_client {
+  public:
+    static tX_jack_client* get_instance() { return &instance; };
+    bool init();
+    ~tX_jack_client();
+
+  private:
+    tX_jack_client();
+    static tX_jack_client instance;
+    static void error(const char* desc);
+    static int srate(jack_nframes_t nframes, void* arg);
+    static void shutdown(void* arg);
+    static int process(jack_nframes_t nframes, void* arg);
+
+    jack_client_t* client;
+    tX_audiodevice_jack* device;
+    jack_port_t* left_port;
+    jack_port_t* right_port;
+    bool jack_shutdown;
+    bool client_initialized;
+    int play(jack_nframes_t nframes);
+
+  public:
+    int get_sample_rate();
+    bool get_jack_shutdown() { return jack_shutdown; }
+    void set_device(tX_audiodevice_jack* dev) { device = dev; }
 };
 
 #endif
index 8af5a97feeb1229fbdc3f1f0394be7e336190160..7521aff6ec0644915fdab5109a9719444a3468cf 100644 (file)
 /*
     terminatorX - realtime audio scratching software
     Copyright (C) 1999-2021  Alexander König
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
+
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
+
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
     File: tX_audiofile.cc
-    Description: This implements the new audiofile class. Unlike earlier
-                versions of terminatorX where wav_read.c was evilishly
-                "#ifdef"ed to support multiple loading strategies this new
-                design allows multiple load_*()-methods/strategies at
-                the same time. (e.g. tx can now try to load a wavfile
-                with the builtin routines and if that fails it'll try
-                to load the file through sox (if available)).
-*/   
 
+    Description:
+    This implements the new audiofile class. Unlike earlier
+    versions of terminatorX where wav_read.c was evilishly
+    "#ifdef"ed to support multiple loading strategies this new
+    design allows multiple load_*()-methods/strategies at
+    the same time. (e.g. tx can now try to load a wavfile
+    with the builtin routines and if that fails it'll try
+    to load the file through sox (if available)).
+*/
 
 #include "tX_audiofile.h"
 
-#include <string.h>
-#include <malloc.h>
-#include "wav_file.h"
-#include "tX_loaddlg.h"
 #include "tX_endian.h"
+#include "tX_loaddlg.h"
+#include "wav_file.h"
+#include <malloc.h>
+#include <string.h>
 
 #define __STDC_FORMAT_MACROS
 #include <inttypes.h>
 #include <stdint.h>
 
 #ifdef USE_MAD_INPUT
-#      include <mad.h>
-#      include <sys/types.h>
-#      include <unistd.h>
-#      ifndef _POSIX_MAPPED_FILES
-#              define _POSIX_MAPPED_FILES
-#      endif
-#      include <sys/stat.h>
-#      include <fcntl.h>
-#      include <sys/mman.h>
+#include <mad.h>
+#include <sys/types.h>
+#include <unistd.h>
+#ifndef _POSIX_MAPPED_FILES
+#define _POSIX_MAPPED_FILES
+#endif
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/mman.h>
 #endif
 
 #ifdef USE_VORBIS_INPUT
-#      include <vorbis/codec.h>
-#      include <vorbis/vorbisfile.h>
-#      include <errno.h>
-#      include <sys/stat.h>
-#      include <fcntl.h>
-#      include <sys/mman.h>
+#include <vorbis/codec.h>
+#include <vorbis/vorbisfile.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/mman.h>
 #endif
 
 #ifdef USE_AUDIOFILE_INPUT
-#      include <audiofile.h>
+#include <audiofile.h>
 #endif
 
-tx_audiofile :: tx_audiofile()
-{
-       mem_type=TX_AUDIO_UNDEFINED;
-       file_type=TX_FILE_UNDEFINED;
-       file=NULL;
-       strcpy(filename,"");
-       mem=NULL;
-       no_samples=0;
-       sample_rate=44100;
+tx_audiofile ::tx_audiofile() {
+    mem_type = TX_AUDIO_UNDEFINED;
+    file_type = TX_FILE_UNDEFINED;
+    file = NULL;
+    strcpy(filename, "");
+    mem = NULL;
+    no_samples = 0;
+    sample_rate = 44100;
 }
 
-void tx_audiofile :: figure_file_type()
-{
-       char *ext;
-       
-       ext=strrchr(filename, (int) '.');
-       
-       if (ext) {
-               if (strlen(ext) >3) {
-                       ext++;
-                       if (!strcasecmp("wav", ext)) file_type=TX_FILE_WAV;
-                       else if (!strncasecmp("mp", ext, 2)) file_type=TX_FILE_MPG123;
-                       else if (!strncasecmp("ogg", ext, 2)) file_type=TX_FILE_OGG123;
-               }
-       }
+void tx_audiofile ::figure_file_type() {
+    char* ext;
+
+    ext = strrchr(filename, (int)'.');
+
+    if (ext) {
+        if (strlen(ext) > 3) {
+            ext++;
+            if (!strcasecmp("wav", ext))
+                file_type = TX_FILE_WAV;
+            else if (!strncasecmp("mp", ext, 2))
+                file_type = TX_FILE_MPG123;
+            else if (!strncasecmp("ogg", ext, 2))
+                file_type = TX_FILE_OGG123;
+        }
+    }
 }
 
-tX_audio_error tx_audiofile :: load(char *p_file_name)
-{
-       tX_audio_error load_err=TX_AUDIO_ERR_NOT_SUPPORTED;
-       
-       strcpy(filename, p_file_name);
-       
-       ld_set_progress(0);
-               
-       figure_file_type();
-       
-       if (mem) { free(mem); mem=NULL; }
+tX_audio_error tx_audiofile ::load(char* p_file_name) {
+    tX_audio_error load_err = TX_AUDIO_ERR_NOT_SUPPORTED;
+
+    strcpy(filename, p_file_name);
+
+    ld_set_progress(0);
+
+    figure_file_type();
+
+    if (mem) {
+        free(mem);
+        mem = NULL;
+    }
 
 #ifdef USE_AUDIOFILE_INPUT
-       if ((load_err) && (file_type!=TX_FILE_MPG123) && (file_type!=TX_FILE_OGG123)) {
-               load_err=load_af();
-       }
+    if ((load_err) && (file_type != TX_FILE_MPG123) && (file_type != TX_FILE_OGG123)) {
+        load_err = load_af();
+    }
 #endif
-       
+
 #ifdef USE_BUILTIN_WAV
-       if ((load_err) && (file_type==TX_FILE_WAV)) {
-               load_err=load_wav();    
-//             if (load_err==TX_AUDIO_SUCCESS) return(load_err);
-       }
-#endif 
+    if ((load_err) && (file_type == TX_FILE_WAV)) {
+        load_err = load_wav();
+        //             if (load_err==TX_AUDIO_SUCCESS) return(load_err);
+    }
+#endif
 
 #ifdef USE_MAD_INPUT
-       if ((load_err) && (file_type==TX_FILE_MPG123)) {
-               load_err=load_mad();
-               //if (load_err==TX_AUDIO_SUCCESS) return(load_err);
-       }
-#endif 
-       
+    if ((load_err) && (file_type == TX_FILE_MPG123)) {
+        load_err = load_mad();
+        //if (load_err==TX_AUDIO_SUCCESS) return(load_err);
+    }
+#endif
+
 #ifdef USE_MPG123_INPUT
-       if ((load_err) && (file_type==TX_FILE_MPG123)) {
-               load_err=load_mpg123();
-               //return(load_err);
-       }
-#endif 
+    if ((load_err) && (file_type == TX_FILE_MPG123)) {
+        load_err = load_mpg123();
+        //return(load_err);
+    }
+#endif
 
 #ifdef USE_VORBIS_INPUT
-       if ((load_err) && (file_type==TX_FILE_OGG123)) {
-               load_err=load_vorbis();
-               //if (load_err==TX_AUDIO_SUCCESS) return(load_err);
-       }
+    if ((load_err) && (file_type == TX_FILE_OGG123)) {
+        load_err = load_vorbis();
+        //if (load_err==TX_AUDIO_SUCCESS) return(load_err);
+    }
 #endif
-       
+
 #ifdef USE_OGG123_INPUT
-       if ((load_err) && (file_type==TX_FILE_OGG123)) {
-               load_err=load_ogg123();
-               //return(load_err);
-       }
+    if ((load_err) && (file_type == TX_FILE_OGG123)) {
+        load_err = load_ogg123();
+        //return(load_err);
+    }
 #endif
 
 #ifdef USE_SOX_INPUT
-       if (load_err) {
-               load_err=load_sox();
-       }
-#endif 
-
-       if (!load_err) {
-               tX_debug("tx_audiofile::load() Set samplerate to %i for file %s.", sample_rate, filename);
-       }
-       return(load_err);
+    if (load_err) {
+        load_err = load_sox();
+    }
+#endif
+
+    if (!load_err) {
+        tX_debug("tx_audiofile::load() Set samplerate to %i for file %s.", sample_rate, filename);
+    }
+    return (load_err);
 }
 
-tx_audiofile :: ~tx_audiofile() {
-       if (mem) {
-               free(mem);
-       }
- }
-#ifdef NEED_PIPED 
-
-tX_audio_error tx_audiofile :: load_piped()
-{
-       int16_t *data=NULL;
-       ssize_t allbytes=0;
-       ssize_t prev_bytes;
-       ssize_t bytes=1;
-       unsigned char buffer[SOX_BLOCKSIZE];
-       unsigned char *ptr;
-       
-       /* Irritating the user... */
-       ld_set_progress(0.5);
-       mem_type=TX_AUDIO_LOAD; 
-       
-       while (bytes) {
-               bytes = fread(buffer, 1, SOX_BLOCKSIZE, file);
-               
-               if (bytes>0) {
-                       prev_bytes=allbytes;
-                       allbytes+=bytes;
-                       int16_t *new_data=(int16_t *) realloc(data, allbytes);
-                       //printf("All: %i, Bytes: %i, new: %08x, old: %08x\n", allbytes, bytes, new_data, data);
-                       
-                       if (!new_data) {
-                               pclose(file); file=NULL;
-                               if (data) free(data);
-                               data=NULL;
-                               return TX_AUDIO_ERR_ALLOC;
-                       }
-                       
-                       data=new_data;
-                       ptr=(unsigned char *) data;
-                       memcpy((void *) &ptr[prev_bytes],(void *) buffer, bytes);
-               }
-       }
-       
-       pclose(file); file=NULL;
-       
-       if (!allbytes) {
-               // If we get here we read zero Bytes...
-               if (data) free(data);
-               return TX_AUDIO_ERR_PIPE_READ;
-       }
-       
-       no_samples=allbytes/sizeof(int16_t);
-       mem=data;
-       
-       /* Irritating the user just a little more ;)*/
-       ld_set_progress(1.0);
-       
-       return TX_AUDIO_SUCCESS;
+tx_audiofile ::~tx_audiofile() {
+    if (mem) {
+        free(mem);
+    }
+}
+
+#ifdef NEED_PIPED
+
+tX_audio_error tx_audiofile ::load_piped() {
+    int16_t* data = NULL;
+    ssize_t allbytes = 0;
+    ssize_t prev_bytes;
+    ssize_t bytes = 1;
+    unsigned char buffer[SOX_BLOCKSIZE];
+    unsigned char* ptr;
+
+    /* Irritating the user... */
+    ld_set_progress(0.5);
+    mem_type = TX_AUDIO_LOAD;
+
+    while (bytes) {
+        bytes = fread(buffer, 1, SOX_BLOCKSIZE, file);
+
+        if (bytes > 0) {
+            prev_bytes = allbytes;
+            allbytes += bytes;
+            int16_t* new_data = (int16_t*)realloc(data, allbytes);
+            //printf("All: %i, Bytes: %i, new: %08x, old: %08x\n", allbytes, bytes, new_data, data);
+
+            if (!new_data) {
+                pclose(file);
+                file = NULL;
+                if (data)
+                    free(data);
+                data = NULL;
+                return TX_AUDIO_ERR_ALLOC;
+            }
+
+            data = new_data;
+            ptr = (unsigned char*)data;
+            memcpy((void*)&ptr[prev_bytes], (void*)buffer, bytes);
+        }
+    }
+
+    pclose(file);
+    file = NULL;
+
+    if (!allbytes) {
+        // If we get here we read zero Bytes...
+        if (data)
+            free(data);
+        return TX_AUDIO_ERR_PIPE_READ;
+    }
+
+    no_samples = allbytes / sizeof(int16_t);
+    mem = data;
+
+    /* Irritating the user just a little more ;)*/
+    ld_set_progress(1.0);
+
+    return TX_AUDIO_SUCCESS;
 }
 
 #endif
-       
+
 #ifdef USE_SOX_INPUT
-tX_audio_error tx_audiofile :: load_sox() {
-       tX_debug("tx_audiofile::load_sox()");
-
-       char command[PATH_MAX*2];
-
-       sprintf(command, SOX_STR, filename);
-       file = popen(command, "r");
-       
-       if (!file) return TX_AUDIO_ERR_SOX;
-       
-       return load_piped();
-       
+tX_audio_error tx_audiofile ::load_sox() {
+    tX_debug("tx_audiofile::load_sox()");
+
+    char command[PATH_MAX * 2];
+
+    sprintf(command, SOX_STR, filename);
+    file = popen(command, "r");
+
+    if (!file)
+        return TX_AUDIO_ERR_SOX;
+
+    return load_piped();
 }
-#endif 
+#endif
 
 #ifdef USE_MPG123_INPUT
-tX_audio_error tx_audiofile :: load_mpg123() {
-       tX_debug("tx_audiofile::load_mpg123()");
-       
-       char command[PATH_MAX*2];
-       
-       sprintf(command, MPG123_STR, filename);
-       file = popen(command, "r");
-       
-       if (!file) return TX_AUDIO_ERR_MPG123;
-       
-       return load_piped();
+tX_audio_error tx_audiofile ::load_mpg123() {
+    tX_debug("tx_audiofile::load_mpg123()");
+
+    char command[PATH_MAX * 2];
+
+    sprintf(command, MPG123_STR, filename);
+    file = popen(command, "r");
+
+    if (!file)
+        return TX_AUDIO_ERR_MPG123;
+
+    return load_piped();
 }
-#endif 
+#endif
 
 #ifdef USE_OGG123_INPUT
-tX_audio_error tx_audiofile :: load_ogg123() {
-       tX_debug("tx_audiofile::load_ogg123()");
-       
-       char command[PATH_MAX*2];
+tX_audio_error tx_audiofile ::load_ogg123() {
+    tX_debug("tx_audiofile::load_ogg123()");
+
+    char command[PATH_MAX * 2];
 
-       sprintf(command, OGG123_STR, filename);
-       file = popen(command, "r");
+    sprintf(command, OGG123_STR, filename);
+    file = popen(command, "r");
 
-       if (!file) return TX_AUDIO_ERR_OGG123;
+    if (!file)
+        return TX_AUDIO_ERR_OGG123;
 
-       return load_piped();
+    return load_piped();
 }
 #endif
 
 #ifdef USE_BUILTIN_WAV
-tX_audio_error tx_audiofile :: load_wav() {
-       tX_debug("tx_audiofile::load_wav()");
-       
-       wav_sig wav_in;
-       int16_t *data;
-       int16_t *p;
-       ssize_t allbytes=0;
-       ssize_t bytes=0;
-
-       mem_type=TX_AUDIO_LOAD;
-       
-       if (!init_wav_read(filename, &wav_in))
-       {
-               return(TX_AUDIO_ERR_WAV_NOTFOUND);
-       }
-
-       if (wav_in.depth != 16)
-       {
-               return(TX_AUDIO_ERR_NOT_16BIT);
-       }
-
-       if (wav_in.chans != 1)
-       {
-               return(TX_AUDIO_ERR_NOT_MONO);
-       }
-
-       sample_rate=wav_in.srate;
-       
-       memsize=wav_in.len;
-       data = (int16_t *) malloc (memsize);
-               
-       if (!data)
-       {
-               return(TX_AUDIO_ERR_ALLOC);
-       }
-
-       p=data;
+tX_audio_error tx_audiofile ::load_wav() {
+    tX_debug("tx_audiofile::load_wav()");
+
+    wav_sig wav_in;
+    int16_t* data;
+    int16_t* p;
+    ssize_t allbytes = 0;
+    ssize_t bytes = 0;
+
+    mem_type = TX_AUDIO_LOAD;
+
+    if (!init_wav_read(filename, &wav_in)) {
+        return (TX_AUDIO_ERR_WAV_NOTFOUND);
+    }
+
+    if (wav_in.depth != 16) {
+        return (TX_AUDIO_ERR_NOT_16BIT);
+    }
+
+    if (wav_in.chans != 1) {
+        return (TX_AUDIO_ERR_NOT_MONO);
+    }
+
+    sample_rate = wav_in.srate;
+
+    memsize = wav_in.len;
+    data = (int16_t*)malloc(memsize);
+
+    if (!data) {
+        return (TX_AUDIO_ERR_ALLOC);
+    }
+
+    p = data;
 #ifdef ENABLE_DEBUG_OUTPUT
-       int output=1;
-#endif 
-       while (wav_in.len>allbytes)
-       {       
-               bytes = fread(p, 1, tX_min(1024, wav_in.len-allbytes), wav_in.handle);
+    int output = 1;
+#endif
+    while (wav_in.len > allbytes) {
+        bytes = fread(p, 1, tX_min(1024, wav_in.len - allbytes), wav_in.handle);
 
 #ifdef ENABLE_DEBUG_OUTPUT
-               if (output) { tX_debug("tX_audiofile::load_wav() read %zu Bytes [%04x %04x %04x %04x %04x %04x ..]", bytes, (unsigned int) p[0],  (unsigned int) p[1], (unsigned int) p[2], (unsigned int) p[3], (unsigned int) p[4], (unsigned int) p[5]); }
+        if (output) {
+            tX_debug("tX_audiofile::load_wav() read %zu Bytes [%04x %04x %04x %04x %04x %04x ..]", bytes, (unsigned int)p[0], (unsigned int)p[1], (unsigned int)p[2], (unsigned int)p[3], (unsigned int)p[4], (unsigned int)p[5]);
+        }
 #endif
 
-               if (bytes<=0) {
-                       free(data);
-                       return (TX_AUDIO_ERR_WAV_READ);
-               }
+        if (bytes <= 0) {
+            free(data);
+            return (TX_AUDIO_ERR_WAV_READ);
+        }
 
 #ifdef BIG_ENDIAN_MACHINE
-               swapbuffer(p, bytes/sizeof(int16_t));
-#      ifdef ENABLE_DEBUG_OUTPUT
-               if (output) { tX_debug("tX_audiofile::load_wav() swapped %i Bytes [%04x %04x %04x %04x %04x %04x ..]",
-               bytes, (unsigned int) p[0],  (unsigned int) p[1], (unsigned int) p[2], (unsigned int) p[3], (unsigned int) p[4], (unsigned int) p[5]); }
-#      endif
-#endif         
+        swapbuffer(p, bytes / sizeof(int16_t));
+#ifdef ENABLE_DEBUG_OUTPUT
+        if (output) {
+            tX_debug("tX_audiofile::load_wav() swapped %i Bytes [%04x %04x %04x %04x %04x %04x ..]",
+                bytes, (unsigned int)p[0], (unsigned int)p[1], (unsigned int)p[2], (unsigned int)p[3], (unsigned int)p[4], (unsigned int)p[5]);
+        }
+#endif
+#endif
 
 #ifdef ENABLE_DEBUG_OUTPUT
-               output=0;
+        output = 0;
 #endif
 
-               allbytes+=bytes;
-               
-               ld_set_progress((float) allbytes/(float)wav_in.len);
-               
-               p+=(ssize_t) bytes/sizeof(int16_t);
-       }
-       
-       wav_close(wav_in.handle);
-
-       mem=data;
-       no_samples=memsize/sizeof(int16_t);
-       
-       return (TX_AUDIO_SUCCESS);
+        allbytes += bytes;
+
+        ld_set_progress((float)allbytes / (float)wav_in.len);
+
+        p += (ssize_t)bytes / sizeof(int16_t);
+    }
+
+    wav_close(wav_in.handle);
+
+    mem = data;
+    no_samples = memsize / sizeof(int16_t);
+
+    return (TX_AUDIO_SUCCESS);
 }
 #endif
 
 #ifdef USE_MAD_INPUT
 tX_audio_error tx_audiofile::load_mad() {
-       tX_debug("tx_audiofile::load_mad()");
-       
-       struct stat stat_dat;
-       int fd;
-       int res;
-       void *mp3_file;
-       
-       fd=open(filename, O_RDONLY);
-       if (!fd) return TX_AUDIO_ERR_MAD_OPEN;
-       
-       if (fstat(fd, &stat_dat) == -1 ||
-      stat_dat.st_size == 0) {
-               return TX_AUDIO_ERR_MAD_STAT;
-       }
-       
-       mp3_file = mmap(0, stat_dat.st_size, PROT_READ, MAP_SHARED, fd, 0);
-       
-       if (mp3_file == MAP_FAILED) {
-               return TX_AUDIO_ERR_MAD_MMAP;
-       }
-       
-       res=mad_decode((const unsigned char *) mp3_file, stat_dat.st_size);
-       
-       if (res) {
-               return TX_AUDIO_ERR_MAD_DECODE;
-       }
-       
-       mem_type=TX_AUDIO_LOAD;
-       
-       if (munmap(mp3_file, stat_dat.st_size) == -1) {
-               return TX_AUDIO_ERR_MAD_MUNMAP;
-       }
-       
-       return TX_AUDIO_SUCCESS;
+    tX_debug("tx_audiofile::load_mad()");
+
+    struct stat stat_dat;
+    int fd;
+    int res;
+    void* mp3_file;
+
+    fd = open(filename, O_RDONLY);
+    if (!fd)
+        return TX_AUDIO_ERR_MAD_OPEN;
+
+    if (fstat(fd, &stat_dat) == -1 || stat_dat.st_size == 0) {
+        return TX_AUDIO_ERR_MAD_STAT;
+    }
+
+    mp3_file = mmap(0, stat_dat.st_size, PROT_READ, MAP_SHARED, fd, 0);
+
+    if (mp3_file == MAP_FAILED) {
+        return TX_AUDIO_ERR_MAD_MMAP;
+    }
+
+    res = mad_decode((const unsigned char*)mp3_file, stat_dat.st_size);
+
+    if (res) {
+        return TX_AUDIO_ERR_MAD_DECODE;
+    }
+
+    mem_type = TX_AUDIO_LOAD;
+
+    if (munmap(mp3_file, stat_dat.st_size) == -1) {
+        return TX_AUDIO_ERR_MAD_MUNMAP;
+    }
+
+    return TX_AUDIO_SUCCESS;
 }
 
 #define TX_MAD_BLOCKSIZE 8096
 
 typedef struct {
-       const unsigned char *start;
-       const unsigned char *end;
-       const unsigned char *last_frame;
-       bool first_call;
-       ssize_t size;
-       int16_t *target_buffer;
-       unsigned int target_samples;
-       unsigned int current_sample;
-       unsigned int sample_rate;
-       unsigned int lost_sync_counter;
+    const unsigned char* start;
+    const unsigned char* end;
+    const unsigned char* last_frame;
+    bool first_call;
+    ssize_t size;
+    int16_t* target_buffer;
+    unsigned int target_samples;
+    unsigned int current_sample;
+    unsigned int sample_rate;
+    unsigned int lost_sync_counter;
 } tX_mad_buffer;
 
-const unsigned char *last_current=NULL;
-
-static enum mad_flow tX_mad_input(void *data, struct mad_stream *stream) {
-       tX_mad_buffer *buffer = (tX_mad_buffer *) data;
-       ssize_t bs;
-       unsigned int pos;
-
-       if (buffer->first_call) {
-               bs=tX_min(TX_MAD_BLOCKSIZE, buffer->size);
-               mad_stream_buffer(stream, buffer->start, bs);
-               buffer->first_call=false;
-               return MAD_FLOW_CONTINUE;
-       } else {
-               if (!stream->next_frame) return MAD_FLOW_STOP;
-               
-               pos=stream->next_frame-buffer->start;
-               bs=tX_min(TX_MAD_BLOCKSIZE, buffer->size-pos);
-               //tX_debug("last: %08x, new %08x, bs: %i, pos: %i",  buffer->last_frame, stream->next_frame, bs, pos);
-               
-               mad_stream_buffer(stream, stream->next_frame, bs);
-               if (stream->next_frame==buffer->last_frame) {
-                       //tX_debug("tX_mad_input(): No new frame? Stopping.");
-                       return MAD_FLOW_STOP;
-               }
-               ld_set_progress((float) pos/(float) buffer->size);
-               buffer->last_frame=stream->next_frame;
-
-               return MAD_FLOW_CONTINUE;
-       }
+const unsigned char* last_current = NULL;
+
+static enum mad_flow tX_mad_input(void* data, struct mad_stream* stream) {
+    tX_mad_buffer* buffer = (tX_mad_buffer*)data;
+    ssize_t bs;
+    unsigned int pos;
+
+    if (buffer->first_call) {
+        bs = tX_min(TX_MAD_BLOCKSIZE, buffer->size);
+        mad_stream_buffer(stream, buffer->start, bs);
+        buffer->first_call = false;
+        return MAD_FLOW_CONTINUE;
+    } else {
+        if (!stream->next_frame)
+            return MAD_FLOW_STOP;
+
+        pos = stream->next_frame - buffer->start;
+        bs = tX_min(TX_MAD_BLOCKSIZE, buffer->size - pos);
+        //tX_debug("last: %08x, new %08x, bs: %i, pos: %i",  buffer->last_frame, stream->next_frame, bs, pos);
+
+        mad_stream_buffer(stream, stream->next_frame, bs);
+        if (stream->next_frame == buffer->last_frame) {
+            //tX_debug("tX_mad_input(): No new frame? Stopping.");
+            return MAD_FLOW_STOP;
+        }
+        ld_set_progress((float)pos / (float)buffer->size);
+        buffer->last_frame = stream->next_frame;
+
+        return MAD_FLOW_CONTINUE;
+    }
 }
 
-static enum mad_flow tX_mad_error(void *data, struct mad_stream *stream, struct mad_frame *frame) {
-       tX_mad_buffer *buffer = (tX_mad_buffer *) data;
-       if (MAD_RECOVERABLE(stream->error)) {
-               if ((stream->error==MAD_ERROR_LOSTSYNC) && (buffer->lost_sync_counter<3)) {
-                       /* Ignore at least two sync errors to not annoy people
+static enum mad_flow tX_mad_error(void* data, struct mad_stream* stream, struct mad_frame* frame) {
+    tX_mad_buffer* buffer = (tX_mad_buffer*)data;
+    if (MAD_RECOVERABLE(stream->error)) {
+        if ((stream->error == MAD_ERROR_LOSTSYNC) && (buffer->lost_sync_counter < 3)) {
+            /* Ignore at least two sync errors to not annoy people
                           about ID3 tags.
                        */
-                       buffer->lost_sync_counter++;
-                       return MAD_FLOW_CONTINUE;
-               }
-               tX_warning("mad reported stream error (%i) '%s'.", stream->error, mad_stream_errorstr(stream));
-               return MAD_FLOW_CONTINUE;
-       }
-       tX_error("mad reported fatal stream error (%i) '%s'.", stream->error, mad_stream_errorstr(stream));
-       return MAD_FLOW_STOP;
+            buffer->lost_sync_counter++;
+            return MAD_FLOW_CONTINUE;
+        }
+        tX_warning("mad reported stream error (%i) '%s'.", stream->error, mad_stream_errorstr(stream));
+        return MAD_FLOW_CONTINUE;
+    }
+    tX_error("mad reported fatal stream error (%i) '%s'.", stream->error, mad_stream_errorstr(stream));
+    return MAD_FLOW_STOP;
 }
 
 /* From minimad.c of mad */
 static inline signed int scale(mad_fixed_t sample) {
-//#ifdef BIG_ENDIAN_MACHINE
-//     swap32_inline(&sample);
-//#endif
-  /* round */
-  sample += (1L << (MAD_F_FRACBITS - 16));
-
-  /* clip */
-  if (sample >= MAD_F_ONE)
-    sample = MAD_F_ONE - 1;
-  else if (sample < -MAD_F_ONE)
-    sample = -MAD_F_ONE;
-
-  /* quantize */
-  return sample >> (MAD_F_FRACBITS + 1 - 16);
+    //#ifdef BIG_ENDIAN_MACHINE
+    // swap32_inline(&sample);
+    //#endif
+    /* round */
+    sample += (1L << (MAD_F_FRACBITS - 16));
+
+    /* clip */
+    if (sample >= MAD_F_ONE)
+        sample = MAD_F_ONE - 1;
+    else if (sample < -MAD_F_ONE)
+        sample = -MAD_F_ONE;
+
+    /* quantize */
+    return sample >> (MAD_F_FRACBITS + 1 - 16);
 }
 
-static enum mad_flow tX_mad_output(void *data, struct mad_header const *header, struct mad_pcm *pcm) {
-       tX_mad_buffer *buffer=(tX_mad_buffer *) data;
-       unsigned int nchannels, nsamples;
-       mad_fixed_t const *left_ch, *right_ch;  
-
-       nchannels = pcm->channels;
-       nsamples  = pcm->length;
-       left_ch   = pcm->samples[0];
-       right_ch  = pcm->samples[1];
-       buffer->sample_rate = pcm->samplerate;
-       
-       buffer->target_samples+=nsamples;
-
-       buffer->target_buffer=(int16_t *) realloc(buffer->target_buffer, buffer->target_samples<<1);
-       if (!buffer->target_buffer) { 
-                       tX_error("tX_mad_output(): Failed allocating sample memory!\n");
-                       return MAD_FLOW_STOP;
-       }
-               
-       while (nsamples--) {
-               signed int sample;
-
-               if (nchannels==1) {
-                       sample=scale(*left_ch++);
-               } else {
-                       double sample_l=(double) (*left_ch++);
-                       double sample_r=(double) (*right_ch++); 
-                       double res=(sample_l+sample_r)/2.0;
-                       mad_fixed_t mad_res=(mad_fixed_t) res;
-                       
-                       sample=scale(mad_res);
-               }
-               
-               buffer->target_buffer[buffer->current_sample]=sample;
-               buffer->current_sample++;
-       }
-
-       return MAD_FLOW_CONTINUE;
+static enum mad_flow tX_mad_output(void* data, struct mad_header const* header, struct mad_pcm* pcm) {
+    tX_mad_buffer* buffer = (tX_mad_buffer*)data;
+    unsigned int nchannels, nsamples;
+    mad_fixed_t const *left_ch, *right_ch;
+
+    nchannels = pcm->channels;
+    nsamples = pcm->length;
+    left_ch = pcm->samples[0];
+    right_ch = pcm->samples[1];
+    buffer->sample_rate = pcm->samplerate;
+
+    buffer->target_samples += nsamples;
+
+    buffer->target_buffer = (int16_t*)realloc(buffer->target_buffer, buffer->target_samples << 1);
+    if (!buffer->target_buffer) {
+        tX_error("tX_mad_output(): Failed allocating sample memory!\n");
+        return MAD_FLOW_STOP;
+    }
+
+    while (nsamples--) {
+        signed int sample;
+
+        if (nchannels == 1) {
+            sample = scale(*left_ch++);
+        } else {
+            double sample_l = (double)(*left_ch++);
+            double sample_r = (double)(*right_ch++);
+            double res = (sample_l + sample_r) / 2.0;
+            mad_fixed_t mad_res = (mad_fixed_t)res;
+
+            sample = scale(mad_res);
+        }
+
+        buffer->target_buffer[buffer->current_sample] = sample;
+        buffer->current_sample++;
+    }
+
+    return MAD_FLOW_CONTINUE;
 }
 
-int tx_audiofile::mad_decode(unsigned char const *start, unsigned long length) {
-       tX_mad_buffer buffer;
-       struct mad_decoder decoder;
-       int result;
-
-       buffer.start  = start;
-       buffer.end = &start[length];
-       buffer.last_frame = NULL;
-       buffer.size = length;
-       buffer.target_buffer = NULL;
-       buffer.target_samples = 0;
-       buffer.current_sample = 0;
-       buffer.first_call=true;
-       buffer.sample_rate=0;
-       buffer.lost_sync_counter=0;
-
-       tX_debug("tx_audiofile::mad_decode() - start %016" PRIxPTR ", length %zu", (uintptr_t) buffer.start, buffer.size);
-       /* configure input, output, and error functions */
-
-       mad_decoder_init(&decoder, &buffer, tX_mad_input, NULL, NULL, tX_mad_output, tX_mad_error, NULL);
-       result = mad_decoder_run(&decoder, MAD_DECODER_MODE_SYNC);
-
-       if (!result) {
-               this->mem=buffer.target_buffer;
-               this->no_samples=buffer.target_samples;
-       } else {
-               if (buffer.target_buffer) free(buffer.target_buffer);
-       }
-       
-       /* release the decoder */
-       mad_decoder_finish(&decoder);  
-
-       sample_rate=buffer.sample_rate;
-  return result;
+int tx_audiofile::mad_decode(unsigned char const* start, unsigned long length) {
+    tX_mad_buffer buffer;
+    struct mad_decoder decoder;
+    int result;
+
+    buffer.start = start;
+    buffer.end = &start[length];
+    buffer.last_frame = NULL;
+    buffer.size = length;
+    buffer.target_buffer = NULL;
+    buffer.target_samples = 0;
+    buffer.current_sample = 0;
+    buffer.first_call = true;
+    buffer.sample_rate = 0;
+    buffer.lost_sync_counter = 0;
+
+    tX_debug("tx_audiofile::mad_decode() - start %016" PRIxPTR ", length %zu", (uintptr_t)buffer.start, buffer.size);
+    /* configure input, output, and error functions */
+
+    mad_decoder_init(&decoder, &buffer, tX_mad_input, NULL, NULL, tX_mad_output, tX_mad_error, NULL);
+    result = mad_decoder_run(&decoder, MAD_DECODER_MODE_SYNC);
+
+    if (!result) {
+        this->mem = buffer.target_buffer;
+        this->no_samples = buffer.target_samples;
+    } else {
+        if (buffer.target_buffer)
+            free(buffer.target_buffer);
+    }
+
+    /* release the decoder */
+    mad_decoder_finish(&decoder);
+
+    sample_rate = buffer.sample_rate;
+    return result;
 }
 
 #endif
@@ -549,148 +558,150 @@ long tX_ogg_file_read;
 
 #ifdef USE_VORBIS_INPUT
 typedef struct {
-  size_t (*read_func) (void *, size_t, size_t, FILE *);
-  int  (*seek_func) (void *, long, int);
-  int (*close_func) (FILE *);
-  long (*tell_func) (FILE *);
+    size_t (*read_func)(void*, size_t, size_t, FILE*);
+    int (*seek_func)(void*, long, int);
+    int (*close_func)(FILE*);
+    long (*tell_func)(FILE*);
 } tX_ov_callbacks;
 
-int ogg_seek(void *ptr, long offset, int whence) {
-       /* ogg shall not seek ! */
-       return -1;
-       errno=EBADF;
+int ogg_seek(voidptr, long offset, int whence) {
+    /* ogg shall not seek ! */
+    return -1;
+    errno = EBADF;
 }
 
-size_t ogg_read(void  *ptr, size_t size, size_t nmemb, FILE *stream) {
-       size_t ret_val;
-       ret_val=fread(ptr, size, nmemb, stream);
-       if (ret_val>0) {
-               tX_ogg_file_read+=ret_val*size;
-               ld_set_progress((double) tX_ogg_file_read/(double) tX_ogg_file_size);   
-       }
-       return ret_val;
+size_t ogg_read(void* ptr, size_t size, size_t nmemb, FILE* stream) {
+    size_t ret_val;
+    ret_val = fread(ptr, size, nmemb, stream);
+    if (ret_val > 0) {
+        tX_ogg_file_read += ret_val * size;
+        ld_set_progress((double)tX_ogg_file_read / (double)tX_ogg_file_size);
+    }
+    return ret_val;
 }
 
 #define VORBIS_BUFF_SIZE 4096 /*recommended*/
 
 tX_audio_error tx_audiofile::load_vorbis() {
-       tX_debug("tx_audiofile::load_vorbis()");
-       
-       /*  VORBIS Callbacks */
-       ov_callbacks org_callbacks;
-       /* evil casting - to make g++ shut up */
-       tX_ov_callbacks *callbacks=(tX_ov_callbacks *) &org_callbacks;
-       
-       /* buffer */
-       char pcmout[VORBIS_BUFF_SIZE];
-       OggVorbis_File vf;
-       bool eof=false;
-       int current_section=0;
-       unsigned int i;
-       struct stat stat_dat;
-               
-       callbacks->read_func=ogg_read;
-       callbacks->seek_func=ogg_seek;
-       callbacks->close_func=fclose;
-       callbacks->tell_func=ftell;
-       
-       file=fopen(filename, "r");
-       if (!file) {
-               return TX_AUDIO_ERR_WAV_NOTFOUND;               
-       }
-       
-       if (fstat(fileno(file), &stat_dat)  == -1 || stat_dat.st_size == 0) {
-               return TX_AUDIO_ERR_MAD_STAT;
-       }
-       
-       tX_ogg_file_size=stat_dat.st_size;
-       tX_ogg_file_read=0;
-       
-       int res=ov_open_callbacks((void *) file, &vf, NULL, 0, org_callbacks);
-       if (res<0) {
-               fclose(file); 
-               file=NULL;
-               return TX_AUDIO_ERR_VORBIS_OPEN;                
-       }
-       
-       vorbis_info *vi=ov_info(&vf,-1);
-       sample_rate=vi->rate;
-
-       unsigned int channels=vi->channels;     
-       unsigned int samples_read=0;
-       unsigned int mono_samples;
-       int16_t* data=NULL;
-       size_t bytes=0;
-       
-       while((!eof) && (!current_section)) {
+    tX_debug("tx_audiofile::load_vorbis()");
+
+    /*  VORBIS Callbacks */
+    ov_callbacks org_callbacks;
+    /* evil casting - to make g++ shut up */
+    tX_ov_callbacks* callbacks = (tX_ov_callbacks*)&org_callbacks;
+
+    /* buffer */
+    char pcmout[VORBIS_BUFF_SIZE];
+    OggVorbis_File vf;
+    bool eof = false;
+    int current_section = 0;
+    unsigned int i;
+    struct stat stat_dat;
+
+    callbacks->read_func = ogg_read;
+    callbacks->seek_func = ogg_seek;
+    callbacks->close_func = fclose;
+    callbacks->tell_func = ftell;
+
+    file = fopen(filename, "r");
+    if (!file) {
+        return TX_AUDIO_ERR_WAV_NOTFOUND;
+    }
+
+    if (fstat(fileno(file), &stat_dat) == -1 || stat_dat.st_size == 0) {
+        return TX_AUDIO_ERR_MAD_STAT;
+    }
+
+    tX_ogg_file_size = stat_dat.st_size;
+    tX_ogg_file_read = 0;
+
+    int res = ov_open_callbacks((void*)file, &vf, NULL, 0, org_callbacks);
+    if (res < 0) {
+        fclose(file);
+        file = NULL;
+        return TX_AUDIO_ERR_VORBIS_OPEN;
+    }
+
+    vorbis_info* vi = ov_info(&vf, -1);
+    sample_rate = vi->rate;
+
+    unsigned int channels = vi->channels;
+    unsigned int samples_read = 0;
+    unsigned int mono_samples;
+    int16_t* data = NULL;
+    size_t bytes = 0;
+
+    while ((!eof) && (!current_section)) {
 #ifdef BIG_ENDIAN_MACHINE
-#      define ENDIANP 1
+#define ENDIANP 1
 #else
-#      define ENDIANP 0                
+#define ENDIANP 0
 #endif
-               long ret=ov_read(&vf,pcmout,VORBIS_BUFF_SIZE,ENDIANP,2,1,&current_section);
-               if (ret == 0) {
-                       eof=true;
-               } else if (ret < 0) {
-                 /* ignore stream errors */
-               } else {
-                       int16_t *new_data;
-                       bytes+=ret;
-                       new_data=(int16_t *) realloc(data, bytes/channels);
-                       if (!new_data) {
-                               if (data) free(data);
-                               return TX_AUDIO_ERR_ALLOC;\r
-                       }
-                       
-                       data=new_data;
-                       int16_t *src=(int16_t *) &pcmout;
-                       
-                       switch (channels) {
-                               case 1:
-                                       mono_samples=ret/2;
-                                       for (i=0; i<mono_samples; i++) {
-                                               data[samples_read+i]=src[i];
-                                       }
-                                       break;
-                                       
-                               case 2:
-                                       mono_samples=ret/4;
-                                       for (i=0; i<mono_samples; i++) {
-                                               double l_value, r_value;
-                                               l_value=src[i*2];
-                                               r_value=src[i*2+1];
-                                               data[samples_read+i]=(int16_t) ((l_value+r_value)/2.0);
-                                       }
-                                       break;
-                                       
-                               default:
-                                       mono_samples=(ret/2)/channels;
-                                       for (i=0; i<mono_samples; i++) {
-                                               double value=0.0;
-                               
-                                               for (unsigned int c=0; c<channels; c++) {
-                                                       value+=(double) src[i*channels+c];
-                                               }
-                                               value/=(double) channels;
-                                               data[samples_read+i]=(int16_t) value;
-                                       }               
-                       }
-                       samples_read+=mono_samples;
-               }
-    }
-       
-       ov_clear(&vf);
-       
-       mem=(int16_t *) data;
-       no_samples=samples_read;
-       
-       if (no_samples==0) {
-               if (mem) free(mem);
-               mem=NULL;
-               return TX_AUDIO_ERR_VORBIS_NODATA;
-       }
-       
-       return TX_AUDIO_SUCCESS;
+        long ret = ov_read(&vf, pcmout, VORBIS_BUFF_SIZE, ENDIANP, 2, 1, &current_section);
+        if (ret == 0) {
+            eof = true;
+        } else if (ret < 0) {
+            /* ignore stream errors */
+        } else {
+            int16_t* new_data;
+            bytes += ret;
+            new_data = (int16_t*)realloc(data, bytes / channels);
+            if (!new_data) {
+                if (data)
+                    free(data);
+                return TX_AUDIO_ERR_ALLOC;
+            }
+
+            data = new_data;
+            int16_t* src = (int16_t*)&pcmout;
+
+            switch (channels) {
+            case 1:
+                mono_samples = ret / 2;
+                for (i = 0; i < mono_samples; i++) {
+                    data[samples_read + i] = src[i];
+                }
+                break;
+
+            case 2:
+                mono_samples = ret / 4;
+                for (i = 0; i < mono_samples; i++) {
+                    double l_value, r_value;
+                    l_value = src[i * 2];
+                    r_value = src[i * 2 + 1];
+                    data[samples_read + i] = (int16_t)((l_value + r_value) / 2.0);
+                }
+                break;
+
+            default:
+                mono_samples = (ret / 2) / channels;
+                for (i = 0; i < mono_samples; i++) {
+                    double value = 0.0;
+
+                    for (unsigned int c = 0; c < channels; c++) {
+                        value += (double)src[i * channels + c];
+                    }
+                    value /= (double)channels;
+                    data[samples_read + i] = (int16_t)value;
+                }
+            }
+            samples_read += mono_samples;
+        }
+    }
+
+    ov_clear(&vf);
+
+    mem = (int16_t*)data;
+    no_samples = samples_read;
+
+    if (no_samples == 0) {
+        if (mem)
+            free(mem);
+        mem = NULL;
+        return TX_AUDIO_ERR_VORBIS_NODATA;
+    }
+
+    return TX_AUDIO_SUCCESS;
 }
 #endif
 
@@ -698,57 +709,60 @@ tX_audio_error tx_audiofile::load_vorbis() {
 #define TX_AF_SAMPLES_PER_BLOCK 2048
 
 tX_audio_error tx_audiofile::load_af() {
-       tX_debug("tx_audiofile::load_af()");
-       
-       AFfilehandle af_file;
-       AFframecount    all_frames, frames_read=0, current_frames=1;
-       int16_t *data=NULL;
-       
-       af_file = afOpenFile(filename, "r", NULL);
-       if (af_file==AF_NULL_FILEHANDLE) {
-               return TX_AUDIO_ERR_AF_OPEN;
-       }
-       
-       all_frames=afGetFrameCount(af_file, AF_DEFAULT_TRACK);
-       sample_rate=(unsigned int) afGetRate(af_file, AF_DEFAULT_TRACK);
-       afSetVirtualChannels(af_file, AF_DEFAULT_TRACK, 1);
-       afSetVirtualSampleFormat(af_file, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16); // 2 == 16 Bit?
+    tX_debug("tx_audiofile::load_af()");
+
+    AFfilehandle af_file;
+    AFframecount all_frames, frames_read = 0, current_frames = 1;
+    int16_t* data = NULL;
+
+    af_file = afOpenFile(filename, "r", NULL);
+    if (af_file == AF_NULL_FILEHANDLE) {
+        return TX_AUDIO_ERR_AF_OPEN;
+    }
+
+    all_frames = afGetFrameCount(af_file, AF_DEFAULT_TRACK);
+    sample_rate = (unsigned int)afGetRate(af_file, AF_DEFAULT_TRACK);
+    afSetVirtualChannels(af_file, AF_DEFAULT_TRACK, 1);
+    afSetVirtualSampleFormat(af_file, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16); // 2 == 16 Bit?
 #ifdef BIG_ENDIAN_MACHINE
-       afSetVirtualByteOrder(af_file, AF_DEFAULT_TRACK, AF_BYTEORDER_BIGENDIAN);
+    afSetVirtualByteOrder(af_file, AF_DEFAULT_TRACK, AF_BYTEORDER_BIGENDIAN);
 #else
-       afSetVirtualByteOrder(af_file, AF_DEFAULT_TRACK, AF_BYTEORDER_LITTLEENDIAN);
+    afSetVirtualByteOrder(af_file, AF_DEFAULT_TRACK, AF_BYTEORDER_LITTLEENDIAN);
 #endif
-       
-       while (current_frames) {
-               int16_t *new_data;
-               
-               new_data=(int16_t*) realloc(data, (frames_read+TX_AF_SAMPLES_PER_BLOCK)*2);
-               if (!new_data) {
-                       if (data) free(data);
-                       afCloseFile(af_file);
-                       return TX_AUDIO_ERR_ALLOC;
-               }
-               data=new_data;
-               current_frames=afReadFrames(af_file,AF_DEFAULT_TRACK,(void *) &data[frames_read],TX_AF_SAMPLES_PER_BLOCK);
-               frames_read+=current_frames;
-               ld_set_progress(((double) frames_read)/((double) all_frames));
-       }
-       afCloseFile(af_file);
-       
-       if (!frames_read) {
-               if (data) free(data);
-               return TX_AUDIO_ERR_AF_NODATA;
-       }
-       
-       /* shorten to the actually read size of samples */
-       if (!realloc(data, frames_read*2)) {
-                       if (data) free(data);
-                       return TX_AUDIO_ERR_ALLOC;
-       }
-       
-       mem=data;
-       no_samples=frames_read;
-       
-       return TX_AUDIO_SUCCESS;
+
+    while (current_frames) {
+        int16_t* new_data;
+
+        new_data = (int16_t*)realloc(data, (frames_read + TX_AF_SAMPLES_PER_BLOCK) * 2);
+        if (!new_data) {
+            if (data)
+                free(data);
+            afCloseFile(af_file);
+            return TX_AUDIO_ERR_ALLOC;
+        }
+        data = new_data;
+        current_frames = afReadFrames(af_file, AF_DEFAULT_TRACK, (void*)&data[frames_read], TX_AF_SAMPLES_PER_BLOCK);
+        frames_read += current_frames;
+        ld_set_progress(((double)frames_read) / ((double)all_frames));
+    }
+    afCloseFile(af_file);
+
+    if (!frames_read) {
+        if (data)
+            free(data);
+        return TX_AUDIO_ERR_AF_NODATA;
+    }
+
+    /* shorten to the actually read size of samples */
+    if (!realloc(data, frames_read * 2)) {
+        if (data)
+            free(data);
+        return TX_AUDIO_ERR_ALLOC;
+    }
+
+    mem = data;
+    no_samples = frames_read;
+
+    return TX_AUDIO_SUCCESS;
 }
 #endif
index 89cee95c90b74bf98db51d14137c2d2dd319ae27..29f8561595fd466a3fc8587bb38d2608240a8456 100644 (file)
@@ -1,24 +1,24 @@
 /*
     terminatorX - realtime audio scratching software
     Copyright (C) 1999-2021  Alexander König
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
+
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
+
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
     File: tX_audiofile.h
+
     Description: Header to audiofile.cc
-*/   
+*/
 
 #ifndef _h_tx_audiofile
 #define _h_tx_audiofile 1
@@ -57,104 +57,103 @@ but mpg321 doesn't support -m yet.
 #endif /* USE_OGG123_INPUT */
 
 enum tX_audio_error {
-       TX_AUDIO_SUCCESS,
-       TX_AUDIO_ERR_ALLOC,
-       TX_AUDIO_ERR_PIPE_READ,
-       TX_AUDIO_ERR_SOX,
-       TX_AUDIO_ERR_MPG123,
-       TX_AUDIO_ERR_WAV_NOTFOUND,
-       TX_AUDIO_ERR_NOT_16BIT,
-       TX_AUDIO_ERR_NOT_MONO,
-       TX_AUDIO_ERR_WAV_READ,
-       TX_AUDIO_ERR_NOT_SUPPORTED,
-       TX_AUDIO_ERR_OGG123,
-       TX_AUDIO_ERR_MAD_OPEN,
-       TX_AUDIO_ERR_MAD_STAT,
-       TX_AUDIO_ERR_MAD_DECODE,
-       TX_AUDIO_ERR_MAD_MMAP,
-       TX_AUDIO_ERR_MAD_MUNMAP,
-       TX_AUDIO_ERR_VORBIS_OPEN,
-       TX_AUDIO_ERR_VORBIS_NODATA,
-       TX_AUDIO_ERR_AF_OPEN,
-       TX_AUDIO_ERR_AF_NODATA  
+    TX_AUDIO_SUCCESS,
+    TX_AUDIO_ERR_ALLOC,
+    TX_AUDIO_ERR_PIPE_READ,
+    TX_AUDIO_ERR_SOX,
+    TX_AUDIO_ERR_MPG123,
+    TX_AUDIO_ERR_WAV_NOTFOUND,
+    TX_AUDIO_ERR_NOT_16BIT,
+    TX_AUDIO_ERR_NOT_MONO,
+    TX_AUDIO_ERR_WAV_READ,
+    TX_AUDIO_ERR_NOT_SUPPORTED,
+    TX_AUDIO_ERR_OGG123,
+    TX_AUDIO_ERR_MAD_OPEN,
+    TX_AUDIO_ERR_MAD_STAT,
+    TX_AUDIO_ERR_MAD_DECODE,
+    TX_AUDIO_ERR_MAD_MMAP,
+    TX_AUDIO_ERR_MAD_MUNMAP,
+    TX_AUDIO_ERR_VORBIS_OPEN,
+    TX_AUDIO_ERR_VORBIS_NODATA,
+    TX_AUDIO_ERR_AF_OPEN,
+    TX_AUDIO_ERR_AF_NODATA
 };
 
 enum tX_audio_storage_type {
-       TX_AUDIO_UNDEFINED,
-       TX_AUDIO_MMAP,
-       TX_AUDIO_LOAD
+    TX_AUDIO_UNDEFINED,
+    TX_AUDIO_MMAP,
+    TX_AUDIO_LOAD
 };
 
 enum tX_audio_file_type {
-       TX_FILE_UNDEFINED,
-       TX_FILE_WAV,
-       TX_FILE_MPG123,
-       TX_FILE_OGG123
+    TX_FILE_UNDEFINED,
+    TX_FILE_WAV,
+    TX_FILE_MPG123,
+    TX_FILE_OGG123
 };
 
-#include <limits.h>
 #include "tX_types.h"
+#include <limits.h>
 #include <stdio.h>
 
-class tx_audiofile
-{
-       private:
-       tX_audio_storage_type mem_type;
-       tX_audio_file_type file_type;
-       
-       FILE *file;
-       char filename[PATH_MAX];
-       int16_t *mem;
-       size_t memsize;
-       long no_samples;        
-       unsigned int sample_rate; //in HZ       
+class tx_audiofile {
+  private:
+    tX_audio_storage_type mem_type;
+    tX_audio_file_type file_type;
+
+    FILE* file;
+    char filename[PATH_MAX];
+    int16_t* mem;
+    size_t memsize;
+    long no_samples;
+    unsigned int sample_rate; //in HZ
 
 #ifdef USE_BUILTIN_WAV
-       tX_audio_error load_wav();
+    tX_audio_error load_wav();
 #endif
-       
-#ifdef USE_SOX_INPUT   
-       tX_audio_error load_sox();
-#define NEED_PIPED 1   
+
+#ifdef USE_SOX_INPUT
+    tX_audio_error load_sox();
+#define NEED_PIPED 1
 #endif
 
 #ifdef USE_AUDIOFILE_INPUT
-       tX_audio_error load_af();
+    tX_audio_error load_af();
 #endif
 
 #ifdef USE_MAD_INPUT
-       tX_audio_error load_mad();
-       int mad_decode(unsigned char const *start, unsigned long length);       
+    tX_audio_error load_mad();
+    int mad_decode(unsigned char const* start, unsigned long length);
 #endif
 
-#ifdef USE_MPG123_INPUT        
-       tX_audio_error load_mpg123();
-#define NEED_PIPED 1   
+#ifdef USE_MPG123_INPUT
+    tX_audio_error load_mpg123();
+#define NEED_PIPED 1
 #endif
 
 #ifdef USE_VORBIS_INPUT
-       tX_audio_error load_vorbis();
+    tX_audio_error load_vorbis();
 #endif
 
 #ifdef USE_OGG123_INPUT
-       tX_audio_error load_ogg123();
+    tX_audio_error load_ogg123();
 #define NEED_PIPED 1
 #endif
 
 #ifdef NEED_PIPED
-       tX_audio_error load_piped();
+    tX_audio_error load_piped();
 #endif
-       void figure_file_type();
-       
-       public:
-       tx_audiofile();
-       unsigned int get_sample_rate() { return sample_rate; }
-       
-       tX_audio_error load(char *p_file_name);
-       int16_t *get_buffer() { return mem; };
-       long get_no_samples() { return no_samples; };
-       
-       ~tx_audiofile();
+    void figure_file_type();
+
+  public:
+    tx_audiofile();
+    unsigned int get_sample_rate() { return sample_rate; }
+
+    tX_audio_error load(char* p_file_name);
+    int16_t* get_buffer() { return mem; };
+    long get_no_samples() { return no_samples; };
+
+    ~tx_audiofile();
 };
 
 #endif
index aa476edeb0b76b1095edff27823ffe1061213c37..66067f6f2fa8e98c1de90b3b5f7cf8d9899f276e 100644 (file)
@@ -1,70 +1,69 @@
 /*
     terminatorX - realtime audio scratching software
     Copyright (C) 1999-2021  Alexander König
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
+
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
+
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
     File: tX_capabilities.cc
+
     Description: Aquire CAP_SYS_NICE through Linux' capabilities.
-*/    
-#include <sys/types.h>
+*/
 #include "tX_capabilities.h"
 #include "tX_global.h"
 #include <errno.h>
 #include <string.h>
+#include <sys/types.h>
 
 #ifdef USE_CAPABILITIES
 
-bool have_nice_capability()
-{
-       cap_t caps;
-       cap_flag_value_t cap;
-
-       caps=cap_get_proc();
-       
-       if (!caps) {
-               tX_error("have_nice_capability(): failed to get caps: %s.", strerror(errno));
-               return false;
-       }
-
-       cap_get_flag(caps, CAP_SYS_NICE, CAP_EFFECTIVE, &cap);
-       
-       if (cap==CAP_CLEAR) {
-               return false;
-       }
-       
-       return true;
+bool have_nice_capability() {
+    cap_t caps;
+    cap_flag_value_t cap;
+
+    caps = cap_get_proc();
+
+    if (!caps) {
+        tX_error("have_nice_capability(): failed to get caps: %s.", strerror(errno));
+        return false;
+    }
+
+    cap_get_flag(caps, CAP_SYS_NICE, CAP_EFFECTIVE, &cap);
+
+    if (cap == CAP_CLEAR) {
+        return false;
+    }
+
+    return true;
 }
 
 void set_nice_capability(cap_flag_t cap_flag) {
-       cap_t caps;
-       const unsigned caps_size = 1;
-       cap_value_t cap_list[] = { CAP_SYS_NICE };
-       
-       caps=cap_get_proc();
-       
-       if (!caps) {
-               tX_error("set_capabilities(): failed to get caps: %s.", strerror(errno));
-               return;
-       }
-       
-       cap_set_flag(caps, cap_flag, caps_size, cap_list , CAP_SET);
-       
-       if (cap_set_proc(caps))  {
-               tX_error("set_capabilities(): failed to set caps: %s.", strerror(errno));
-       }
+    cap_t caps;
+    const unsigned caps_size = 1;
+    cap_value_t cap_list[] = { CAP_SYS_NICE };
+
+    caps = cap_get_proc();
+
+    if (!caps) {
+        tX_error("set_capabilities(): failed to get caps: %s.", strerror(errno));
+        return;
+    }
+
+    cap_set_flag(caps, cap_flag, caps_size, cap_list, CAP_SET);
+
+    if (cap_set_proc(caps)) {
+        tX_error("set_capabilities(): failed to set caps: %s.", strerror(errno));
+    }
 }
 
 #endif // USE_CAPABILITIES
index b0cd43c1dd87b7e81e2cba0476082f6526284283..2104aecfdc6c95713b4e28627b32d74532fcccd2 100644 (file)
@@ -1,22 +1,22 @@
 /*
     terminatorX - realtime audio scratching software
     Copyright (C) 1999-2021  Alexander König
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
+
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
+
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
     File: tX_capabilities.h
+
     Description: Aquire CAP_SYS_NICE through Linux' capabilities.
 */
 
index 2855355c8122cde0f5a8c946afdd251437297fff..39d20fbd1c12d9534adb1d6ac96ee5eb3f9a85cb 100644 (file)
 /*
     terminatorX - realtime audio scratching software
     Copyright (C) 1999-2021  Alexander König
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
+
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
+
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
     File: tX_dial.ch
-    Description: Implements the dial widget - this widget is based on the 
+
+    Description: Implements the dial widget - this widget is based on the
     gtk_dial example from the gtk+ tutorial which is
     Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
-*/    
+*/
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
+#include "tX_knobloader.h"
+#include <gtk/gtk.h>
 #include <math.h>
 #include <stdio.h>
-#include <gtk/gtk.h>
-#include "tX_knobloader.h"
 
 #include "tX_dial.h"
 
-#define SCROLL_DELAY_LENGTH  300
+#define SCROLL_DELAY_LENGTH 300
 #define TX_DIAL_DEFAULT_SIZE 100
 
 /* Forward declarations */
 
-static void gtk_tx_dial_class_init             (GtkTxDialClass *klass);
-static void gtk_tx_dial_init                   (GtkTxDial *tx_dial);
-static void gtk_tx_dial_destroy                        (GtkWidget *widget);
-static void gtk_tx_dial_realize                        (GtkWidget *widget);
-
-static void gtk_tx_dial_get_preferred_width (GtkWidget *widget, gint *minimal_height, gint *natural_height);
-static void gtk_tx_dial_get_preferred_height (GtkWidget *widget, gint *minimal_height, gint *natural_height);
-static void gtk_tx_dial_size_allocate  (GtkWidget *widget, GtkAllocation *allocation);
-static gboolean gtk_tx_dial_draw               (GtkWidget *widget, cairo_t* cairo);
-static gint gtk_tx_dial_button_press   (GtkWidget *widget, GdkEventButton *event);
-static gint gtk_tx_dial_button_release (GtkWidget *widget, GdkEventButton *event);
-static gint gtk_tx_dial_motion_notify  (GtkWidget *widget, GdkEventMotion *event);
-static void gtk_tx_dial_update_mouse   (GtkTxDial *tx_dial, gint x, gint y);
-static void gtk_tx_dial_update                 (GtkTxDial *tx_dial);
-static void gtk_tx_dial_adjustment_changed                     (GtkAdjustment *adjustment, gpointer data);
-static void gtk_tx_dial_adjustment_value_changed       (GtkAdjustment *adjustment, gpointer data);
+static void gtk_tx_dial_class_init(GtkTxDialClass* klass);
+static void gtk_tx_dial_init(GtkTxDial* tx_dial);
+static void gtk_tx_dial_destroy(GtkWidget* widget);
+static void gtk_tx_dial_realize(GtkWidget* widget);
+
+static void gtk_tx_dial_get_preferred_width(GtkWidget* widget, gint* minimal_height, gint* natural_height);
+static void gtk_tx_dial_get_preferred_height(GtkWidget* widget, gint* minimal_height, gint* natural_height);
+static void gtk_tx_dial_size_allocate(GtkWidget* widget, GtkAllocation* allocation);
+static gboolean gtk_tx_dial_draw(GtkWidget* widget, cairo_t* cairo);
+static gint gtk_tx_dial_button_press(GtkWidget* widget, GdkEventButton* event);
+static gint gtk_tx_dial_button_release(GtkWidget* widget, GdkEventButton* event);
+static gint gtk_tx_dial_motion_notify(GtkWidget* widget, GdkEventMotion* event);
+static void gtk_tx_dial_update_mouse(GtkTxDial* tx_dial, gint x, gint y);
+static void gtk_tx_dial_update(GtkTxDial* tx_dial);
+static void gtk_tx_dial_adjustment_changed(GtkAdjustment* adjustment, gpointer data);
+static void gtk_tx_dial_adjustment_value_changed(GtkAdjustment* adjustment, gpointer data);
 
 /* Local data */
 
-static GtkWidgetClass *parent_class = NULL;
+static GtkWidgetClass* parent_class = NULL;
+
+#define calc_image(f, i)                                                                    \
+    ;                                                                                       \
+    i = (gint)((f - tx_dial->old_lower) / (tx_dial->old_range) * ((float)TX_MAX_KNOB_PIX)); \
+    if (i > TX_MAX_KNOB_PIX)                                                                \
+        i = TX_MAX_KNOB_PIX;                                                                \
+    else if (i < 0)                                                                         \
+        i = 0;
+
+GType gtk_tx_dial_get_type() {
+    static GType tx_dial_type = 0;
+
+    if (!tx_dial_type) {
+        static const GTypeInfo tx_dial_info = {
+            sizeof(GtkTxDialClass),
+            NULL,
+            NULL,
+            (GClassInitFunc)gtk_tx_dial_class_init,
+            NULL,
+            NULL,
+            sizeof(GtkTxDial),
+            0,
+            (GInstanceInitFunc)gtk_tx_dial_init,
+        };
+
+        tx_dial_type = g_type_register_static(GTK_TYPE_WIDGET, "GtkTxDial", &tx_dial_info, 0);
+    }
+
+    return tx_dial_type;
+}
 
-#define calc_image(f,i); i=(gint) ((f - tx_dial->old_lower)/(tx_dial->old_range) * ((float) TX_MAX_KNOB_PIX)); if(i>TX_MAX_KNOB_PIX) i=TX_MAX_KNOB_PIX; else if (i<0) i=0;
+static void gtk_tx_dial_class_init(GtkTxDialClass* class) {
+    GtkWidgetClass* widget_class;
 
-GType gtk_tx_dial_get_type ()
-{
-       static GType tx_dial_type = 0;
+    widget_class = (GtkWidgetClass*)class;
 
-       if (!tx_dial_type) {
-               static const GTypeInfo tx_dial_info = {
-                       sizeof (GtkTxDialClass),
-                       NULL,
-                       NULL,
-                       (GClassInitFunc) gtk_tx_dial_class_init, 
-                       NULL,
-                       NULL,
-                       sizeof (GtkTxDial),
-               0,
-                       (GInstanceInitFunc) gtk_tx_dial_init,
-               };
+    parent_class = (GtkWidgetClass*)g_type_class_peek(gtk_widget_get_type());
 
-               tx_dial_type = g_type_register_static(GTK_TYPE_WIDGET, "GtkTxDial", &tx_dial_info, 0);
-    }
-       
-       return tx_dial_type;
+    widget_class->destroy = gtk_tx_dial_destroy;
+
+    widget_class->realize = gtk_tx_dial_realize;
+    widget_class->draw = gtk_tx_dial_draw;
+    widget_class->get_preferred_height = gtk_tx_dial_get_preferred_height;
+    widget_class->get_preferred_width = gtk_tx_dial_get_preferred_width;
+    widget_class->size_allocate = gtk_tx_dial_size_allocate;
+    widget_class->button_press_event = gtk_tx_dial_button_press;
+    widget_class->button_release_event = gtk_tx_dial_button_release;
+    widget_class->motion_notify_event = gtk_tx_dial_motion_notify;
 }
 
-static void gtk_tx_dial_class_init (GtkTxDialClass *class)
-{
-       GtkWidgetClass *widget_class;
+static void gtk_tx_dial_init(GtkTxDial* tx_dial) {
+    tx_dial->button = 0;
 
-       widget_class = (GtkWidgetClass*) class;
+    tx_dial->old_value = 0.0;
+    tx_dial->old_lower = 0.0;
+    tx_dial->old_upper = 0.0;
+    tx_dial->old_range = 0.0; // Dangerous!
 
-       parent_class = (GtkWidgetClass*) g_type_class_peek (gtk_widget_get_type ());
+    tx_dial->old_image = 0;
 
-       widget_class->destroy = gtk_tx_dial_destroy;
+    tx_dial->yofs = 0;
+    tx_dial->xofs = 0;
 
-       widget_class->realize = gtk_tx_dial_realize;
-       widget_class->draw = gtk_tx_dial_draw;
-       widget_class->get_preferred_height = gtk_tx_dial_get_preferred_height;
-       widget_class->get_preferred_width = gtk_tx_dial_get_preferred_width;
-       widget_class->size_allocate = gtk_tx_dial_size_allocate;
-       widget_class->button_press_event = gtk_tx_dial_button_press;
-       widget_class->button_release_event = gtk_tx_dial_button_release;
-       widget_class->motion_notify_event = gtk_tx_dial_motion_notify;
+    tx_dial->adjustment = NULL;
 }
 
-static void gtk_tx_dial_init (GtkTxDial *tx_dial)
-{
-       tx_dial->button = 0;
+GtkWidget* gtk_tx_dial_new(GtkAdjustment* adjustment) {
+    GtkTxDial* tx_dial;
 
-       tx_dial->old_value = 0.0;
-       tx_dial->old_lower = 0.0;
-       tx_dial->old_upper = 0.0;
-       tx_dial->old_range = 0.0; // Dangerous!
+    tx_dial = (GtkTxDial*)g_object_new(gtk_tx_dial_get_type(), NULL);
 
-       tx_dial->old_image = 0;
+    if (!adjustment) {
+        adjustment = (GtkAdjustment*)gtk_adjustment_new(0.0, 0.0, 0.0,
+            0.0, 0.0, 0.0);
+    }
 
-       tx_dial->yofs=0;
-       tx_dial->xofs=0;
+    gtk_tx_dial_set_adjustment(tx_dial, adjustment);
+    g_object_ref(G_OBJECT(tx_dial->adjustment));
 
-       tx_dial->adjustment = NULL;
+    return GTK_WIDGET(tx_dial);
 }
 
-GtkWidget* gtk_tx_dial_new (GtkAdjustment *adjustment)
-{
-       GtkTxDial *tx_dial;
-       
-       tx_dial = (GtkTxDial *) g_object_new(gtk_tx_dial_get_type(), NULL);
-       
-       if (!adjustment) {
-               adjustment = (GtkAdjustment*) gtk_adjustment_new (0.0, 0.0, 0.0,
-                                         0.0, 0.0, 0.0);
-       }
-
-       gtk_tx_dial_set_adjustment (tx_dial, adjustment);
-       g_object_ref (G_OBJECT (tx_dial->adjustment));
-
-       return GTK_WIDGET (tx_dial);
-}
+static void gtk_tx_dial_destroy(GtkWidget* widget) {
+    GtkTxDial* tx_dial;
+
+    g_return_if_fail(widget != NULL);
+    g_return_if_fail(GTK_IS_TX_DIAL(widget));
 
-static void gtk_tx_dial_destroy (GtkWidget *widget)
-{
-       GtkTxDial *tx_dial;
+    tx_dial = GTK_TX_DIAL(widget);
 
-       g_return_if_fail (widget != NULL);
-       g_return_if_fail (GTK_IS_TX_DIAL (widget));
-       
-       tx_dial = GTK_TX_DIAL (widget);
+    if (tx_dial->adjustment)
+        g_object_unref(G_OBJECT(tx_dial->adjustment));
 
-       if (tx_dial->adjustment)
-               g_object_unref (G_OBJECT (tx_dial->adjustment));
-       
-       if (GTK_WIDGET_CLASS (parent_class)->destroy)
-               (*GTK_WIDGET_CLASS (parent_class)->destroy) (widget);
+    if (GTK_WIDGET_CLASS(parent_class)->destroy)
+        (*GTK_WIDGET_CLASS(parent_class)->destroy)(widget);
 }
 
-GtkAdjustment* gtk_tx_dial_get_adjustment (GtkTxDial *tx_dial)
-{
-       g_return_val_if_fail (tx_dial != NULL, NULL);
-       g_return_val_if_fail (GTK_IS_TX_DIAL (tx_dial), NULL);
-       
-       return tx_dial->adjustment;
+GtkAdjustment* gtk_tx_dial_get_adjustment(GtkTxDial* tx_dial) {
+    g_return_val_if_fail(tx_dial != NULL, NULL);
+    g_return_val_if_fail(GTK_IS_TX_DIAL(tx_dial), NULL);
+
+    return tx_dial->adjustment;
 }
 
-void gtk_tx_dial_set_adjustment (GtkTxDial *tx_dial, GtkAdjustment *adjustment)
-{
-       g_return_if_fail (tx_dial != NULL);
-       g_return_if_fail (GTK_IS_TX_DIAL (tx_dial));
-       
-       if (tx_dial->adjustment) {
-               g_signal_handlers_disconnect_matched(G_OBJECT(tx_dial->adjustment),
-                       G_SIGNAL_MATCH_DATA, 0, 0, 0, 0,
-                       (gpointer) tx_dial);
-               g_object_unref (G_OBJECT (tx_dial->adjustment));
-       }
-       
-       tx_dial->adjustment = adjustment;
-       g_object_ref (G_OBJECT (tx_dial->adjustment));
-
-       g_signal_connect (G_OBJECT (adjustment), "changed",
-                         (GCallback) gtk_tx_dial_adjustment_changed,
-                         (gpointer) tx_dial);
-       g_signal_connect (G_OBJECT (adjustment), "value_changed",
-                         (GCallback) gtk_tx_dial_adjustment_value_changed,
-                         (gpointer) tx_dial);
-
-       tx_dial->old_value = gtk_adjustment_get_value(adjustment);
-       tx_dial->old_lower = gtk_adjustment_get_lower(adjustment);
-       tx_dial->old_upper = gtk_adjustment_get_upper(adjustment);
-       tx_dial->old_range = gtk_adjustment_get_upper(adjustment) - gtk_adjustment_get_lower(adjustment);
-
-       calc_image(gtk_adjustment_get_value(adjustment),tx_dial->old_image);
-
-       gtk_tx_dial_update (tx_dial);
+void gtk_tx_dial_set_adjustment(GtkTxDial* tx_dial, GtkAdjustment* adjustment) {
+    g_return_if_fail(tx_dial != NULL);
+    g_return_if_fail(GTK_IS_TX_DIAL(tx_dial));
+
+    if (tx_dial->adjustment) {
+        g_signal_handlers_disconnect_matched(G_OBJECT(tx_dial->adjustment),
+            G_SIGNAL_MATCH_DATA, 0, 0, 0, 0,
+            (gpointer)tx_dial);
+        g_object_unref(G_OBJECT(tx_dial->adjustment));
+    }
+
+    tx_dial->adjustment = adjustment;
+    g_object_ref(G_OBJECT(tx_dial->adjustment));
+
+    g_signal_connect(G_OBJECT(adjustment), "changed",
+        (GCallback)gtk_tx_dial_adjustment_changed,
+        (gpointer)tx_dial);
+    g_signal_connect(G_OBJECT(adjustment), "value_changed",
+        (GCallback)gtk_tx_dial_adjustment_value_changed,
+        (gpointer)tx_dial);
+
+    tx_dial->old_value = gtk_adjustment_get_value(adjustment);
+    tx_dial->old_lower = gtk_adjustment_get_lower(adjustment);
+    tx_dial->old_upper = gtk_adjustment_get_upper(adjustment);
+    tx_dial->old_range = gtk_adjustment_get_upper(adjustment) - gtk_adjustment_get_lower(adjustment);
+
+    calc_image(gtk_adjustment_get_value(adjustment), tx_dial->old_image);
+
+    gtk_tx_dial_update(tx_dial);
 }
 
-static void gtk_tx_dial_realize (GtkWidget *widget)
-{
-       GdkWindowAttr attributes;
-       gint attributes_mask;
-       
-       g_return_if_fail (widget != NULL);
-       g_return_if_fail (GTK_IS_TX_DIAL (widget));
-       
-       gtk_widget_set_realized(widget, TRUE);
-       
-       GtkAllocation allocation;
-       gtk_widget_get_allocation(widget, &allocation);
-       attributes.x = allocation.x;
-       attributes.y = allocation.y;
-       attributes.width = allocation.width;
-       attributes.height = allocation.height;
-       attributes.wclass = GDK_INPUT_OUTPUT;
-       attributes.window_type = GDK_WINDOW_CHILD;
-       attributes.event_mask = gtk_widget_get_events (widget) | 
-               GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | 
-               GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK |
-               GDK_POINTER_MOTION_HINT_MASK;
-       attributes.visual = gtk_widget_get_visual (widget);
-               
-       attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
-       gtk_widget_set_window(widget, gdk_window_new(gtk_widget_get_parent_window(widget), &attributes, attributes_mask));
-       
-       gdk_window_set_user_data (gtk_widget_get_window(widget), widget);
+static void gtk_tx_dial_realize(GtkWidget* widget) {
+    GdkWindowAttr attributes;
+    gint attributes_mask;
+
+    g_return_if_fail(widget != NULL);
+    g_return_if_fail(GTK_IS_TX_DIAL(widget));
+
+    gtk_widget_set_realized(widget, TRUE);
+
+    GtkAllocation allocation;
+    gtk_widget_get_allocation(widget, &allocation);
+    attributes.x = allocation.x;
+    attributes.y = allocation.y;
+    attributes.width = allocation.width;
+    attributes.height = allocation.height;
+    attributes.wclass = GDK_INPUT_OUTPUT;
+    attributes.window_type = GDK_WINDOW_CHILD;
+    attributes.event_mask = gtk_widget_get_events(widget) | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK;
+    attributes.visual = gtk_widget_get_visual(widget);
+
+    attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
+    gtk_widget_set_window(widget, gdk_window_new(gtk_widget_get_parent_window(widget), &attributes, attributes_mask));
+
+    gdk_window_set_user_data(gtk_widget_get_window(widget), widget);
 }
 
-static void gtk_tx_dial_get_preferred_width (GtkWidget *widget, gint *minimal_width, gint *natural_width) {
-       *minimal_width = *natural_width = tX_knob_size;
+static void gtk_tx_dial_get_preferred_width(GtkWidget* widget, gint* minimal_width, gint* natural_width) {
+    *minimal_width = *natural_width = tX_knob_size;
 }
-static void gtk_tx_dial_get_preferred_height (GtkWidget *widget, gint *minimal_height, gint *natural_height) {
-       *minimal_height = *natural_height = tX_knob_size;
+static void gtk_tx_dial_get_preferred_height(GtkWidget* widget, gint* minimal_height, gint* natural_height) {
+    *minimal_height = *natural_height = tX_knob_size;
 }
 
-static void gtk_tx_dial_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
-{
-       GtkTxDial *tx_dial;
-       
-       g_return_if_fail (widget != NULL);
-       g_return_if_fail (GTK_IS_TX_DIAL (widget));
-       g_return_if_fail (allocation != NULL);
-       
-       gtk_widget_set_allocation(widget, allocation);
-       tx_dial = GTK_TX_DIAL (widget);
-       
-       if (gtk_widget_get_realized (widget)) {
-               gdk_window_move_resize (gtk_widget_get_window(widget),
-                                 allocation->x, allocation->y,
-                                 allocation->width, allocation->height);
-               
-               tx_dial->xofs=(allocation->width-tX_knob_size)/2;
-               tx_dial->yofs=(allocation->height-tX_knob_size)/2;
-       }
+static void gtk_tx_dial_size_allocate(GtkWidget* widget, GtkAllocation* allocation) {
+    GtkTxDial* tx_dial;
+
+    g_return_if_fail(widget != NULL);
+    g_return_if_fail(GTK_IS_TX_DIAL(widget));
+    g_return_if_fail(allocation != NULL);
+
+    gtk_widget_set_allocation(widget, allocation);
+    tx_dial = GTK_TX_DIAL(widget);
+
+    if (gtk_widget_get_realized(widget)) {
+        gdk_window_move_resize(gtk_widget_get_window(widget),
+            allocation->x, allocation->y,
+            allocation->width, allocation->height);
+
+        tx_dial->xofs = (allocation->width - tX_knob_size) / 2;
+        tx_dial->yofs = (allocation->height - tX_knob_size) / 2;
+    }
 }
 
-gboolean gtk_tx_dial_draw (GtkWidget *widget, cairo_t *cr)
-{
-       GtkTxDial *tx_dial;
-       
-       g_return_val_if_fail (widget != NULL, FALSE);
-       g_return_val_if_fail (GTK_IS_TX_DIAL (widget), FALSE);
-       
-       tx_dial = GTK_TX_DIAL (widget);
-       
-       if (gtk_widget_is_drawable (widget)) {
-               gdk_cairo_set_source_pixbuf (cr, knob_pixmaps[tx_dial->old_image], 0, 0);
-               cairo_paint (cr);
-       }                
-                 
-       return FALSE;
+gboolean gtk_tx_dial_draw(GtkWidget* widget, cairo_t* cr) {
+    GtkTxDial* tx_dial;
+
+    g_return_val_if_fail(widget != NULL, FALSE);
+    g_return_val_if_fail(GTK_IS_TX_DIAL(widget), FALSE);
+
+    tx_dial = GTK_TX_DIAL(widget);
+
+    if (gtk_widget_is_drawable(widget)) {
+        gdk_cairo_set_source_pixbuf(cr, knob_pixmaps[tx_dial->old_image], 0, 0);
+        cairo_paint(cr);
+    }
+
+    return FALSE;
 }
 
-static gint gtk_tx_dial_button_press (GtkWidget *widget, GdkEventButton *event)
-{
-       GtkTxDial *tx_dial;
-       
-       g_return_val_if_fail (widget != NULL, FALSE);
-       g_return_val_if_fail (GTK_IS_TX_DIAL (widget), FALSE);
-       g_return_val_if_fail (event != NULL, FALSE);
-       
-       tx_dial = GTK_TX_DIAL (widget);
-       
-       tx_dial->x = event->x;
-       tx_dial->y = event->y;    
-       
-       if (!tx_dial->button) {
-               gtk_grab_add (widget);
-               tx_dial->button = event->button;
-       }
-       
-       return FALSE;
+static gint gtk_tx_dial_button_press(GtkWidget* widget, GdkEventButton* event) {
+    GtkTxDial* tx_dial;
+
+    g_return_val_if_fail(widget != NULL, FALSE);
+    g_return_val_if_fail(GTK_IS_TX_DIAL(widget), FALSE);
+    g_return_val_if_fail(event != NULL, FALSE);
+
+    tx_dial = GTK_TX_DIAL(widget);
+
+    tx_dial->x = event->x;
+    tx_dial->y = event->y;
+
+    if (!tx_dial->button) {
+        gtk_grab_add(widget);
+        tx_dial->button = event->button;
+    }
+
+    return FALSE;
 }
 
-static gint gtk_tx_dial_button_release (GtkWidget *widget, GdkEventButton *event)
-{
-       GtkTxDial *tx_dial;
-       
-       g_return_val_if_fail (widget != NULL, FALSE);
-       g_return_val_if_fail (GTK_IS_TX_DIAL (widget), FALSE);
-       g_return_val_if_fail (event != NULL, FALSE);
-       
-       tx_dial = GTK_TX_DIAL (widget);
-       
-       if (tx_dial->button == event->button) {
-               gtk_grab_remove (widget);
-               tx_dial->button = 0;
-       }
-       
-       return FALSE;
+static gint gtk_tx_dial_button_release(GtkWidget* widget, GdkEventButton* event) {
+    GtkTxDial* tx_dial;
+
+    g_return_val_if_fail(widget != NULL, FALSE);
+    g_return_val_if_fail(GTK_IS_TX_DIAL(widget), FALSE);
+    g_return_val_if_fail(event != NULL, FALSE);
+
+    tx_dial = GTK_TX_DIAL(widget);
+
+    if (tx_dial->button == event->button) {
+        gtk_grab_remove(widget);
+        tx_dial->button = 0;
+    }
+
+    return FALSE;
 }
 
-static gint gtk_tx_dial_motion_notify (GtkWidget *widget, GdkEventMotion *event)
-{
-       GtkTxDial *tx_dial;
-       GdkModifierType mods;
-       gint x, y, mask;
-       
-       g_return_val_if_fail (widget != NULL, FALSE);
-       g_return_val_if_fail (GTK_IS_TX_DIAL (widget), FALSE);
-       g_return_val_if_fail (event != NULL, FALSE);
-       
-       tx_dial = GTK_TX_DIAL (widget);
-       
-       if (tx_dial->button != 0) {
-               x = event->x;
-               y = event->y;
-               
-               if (event->is_hint || (event->window != gtk_widget_get_window(widget)))
-                       gdk_window_get_device_position(gtk_widget_get_window(widget), event->device, &x, &y, &mods);
-               
-               switch (tx_dial->button) {
-                       case 1:
-                               mask = GDK_BUTTON1_MASK;
-                               break;
-                       case 2:
-                               mask = GDK_BUTTON2_MASK;
-                               break;
-                       case 3:
-                               mask = GDK_BUTTON3_MASK;
-                               break;
-                       default:
-                               mask = 0;
-               }
-               
-               if (mods & mask)
-                       gtk_tx_dial_update_mouse (tx_dial, x,y);
-       }
-       
-       return FALSE;
+static gint gtk_tx_dial_motion_notify(GtkWidget* widget, GdkEventMotion* event) {
+    GtkTxDial* tx_dial;
+    GdkModifierType mods;
+    gint x, y, mask;
+
+    g_return_val_if_fail(widget != NULL, FALSE);
+    g_return_val_if_fail(GTK_IS_TX_DIAL(widget), FALSE);
+    g_return_val_if_fail(event != NULL, FALSE);
+
+    tx_dial = GTK_TX_DIAL(widget);
+
+    if (tx_dial->button != 0) {
+        x = event->x;
+        y = event->y;
+
+        if (event->is_hint || (event->window != gtk_widget_get_window(widget)))
+            gdk_window_get_device_position(gtk_widget_get_window(widget), event->device, &x, &y, &mods);
+
+        switch (tx_dial->button) {
+        case 1:
+            mask = GDK_BUTTON1_MASK;
+            break;
+        case 2:
+            mask = GDK_BUTTON2_MASK;
+            break;
+        case 3:
+            mask = GDK_BUTTON3_MASK;
+            break;
+        default:
+            mask = 0;
+        }
+
+        if (mods & mask)
+            gtk_tx_dial_update_mouse(tx_dial, x, y);
+    }
+
+    return FALSE;
 }
 
-static void gtk_tx_dial_update_mouse (GtkTxDial *tx_dial, gint x, gint y)
-{
-       gdouble dx, dy, d;
-       gfloat old_value, new_value;
-
-       g_return_if_fail (tx_dial != NULL);
-       g_return_if_fail (GTK_IS_TX_DIAL (tx_dial));
-       
-       dx=x-tx_dial->x;
-       dy=tx_dial->y-y;
-       tx_dial->x=x;
-       tx_dial->y=y;
-       
-       d=dx+dy;
-       d/=200.0;
-       
-       old_value=gtk_adjustment_get_value(tx_dial->adjustment);    
-       new_value=old_value + d*tx_dial->old_range;
-       
-       if (new_value>tx_dial->old_upper) 
-               new_value=tx_dial->old_upper;
-       else if (new_value<tx_dial->old_lower) 
-               new_value=tx_dial->old_lower;
-       
-       gtk_adjustment_set_value(tx_dial->adjustment, new_value);
+static void gtk_tx_dial_update_mouse(GtkTxDial* tx_dial, gint x, gint y) {
+    gdouble dx, dy, d;
+    gfloat old_value, new_value;
+
+    g_return_if_fail(tx_dial != NULL);
+    g_return_if_fail(GTK_IS_TX_DIAL(tx_dial));
+
+    dx = x - tx_dial->x;
+    dy = tx_dial->y - y;
+    tx_dial->x = x;
+    tx_dial->y = y;
+
+    d = dx + dy;
+    d /= 200.0;
+
+    old_value = gtk_adjustment_get_value(tx_dial->adjustment);
+    new_value = old_value + d * tx_dial->old_range;
+
+    if (new_value > tx_dial->old_upper)
+        new_value = tx_dial->old_upper;
+    else if (new_value < tx_dial->old_lower)
+        new_value = tx_dial->old_lower;
+
+    gtk_adjustment_set_value(tx_dial->adjustment, new_value);
 }
 
-static void gtk_tx_dial_update (GtkTxDial *tx_dial)
-{
-       gfloat new_value;
-       gint image;
-       
-       g_return_if_fail (tx_dial != NULL);
-       g_return_if_fail (GTK_IS_TX_DIAL (tx_dial));
-       
-       new_value = gtk_adjustment_get_value(tx_dial->adjustment);
-       
-       if (new_value < gtk_adjustment_get_lower(tx_dial->adjustment))
-               new_value = gtk_adjustment_get_lower(tx_dial->adjustment);
-       
-       if (new_value > gtk_adjustment_get_upper(tx_dial->adjustment))
-               new_value = gtk_adjustment_get_upper(tx_dial->adjustment);
-       
-       if (new_value != gtk_adjustment_get_value(tx_dial->adjustment)) {
-               gtk_adjustment_set_value(tx_dial->adjustment, new_value);
-       }
-       
-       calc_image(new_value, image);
-       
-       if (image!=tx_dial->old_image) {
-               tx_dial->old_image=image;
-               gtk_widget_queue_draw(GTK_WIDGET(tx_dial));
-       }
+static void gtk_tx_dial_update(GtkTxDial* tx_dial) {
+    gfloat new_value;
+    gint image;
+
+    g_return_if_fail(tx_dial != NULL);
+    g_return_if_fail(GTK_IS_TX_DIAL(tx_dial));
+
+    new_value = gtk_adjustment_get_value(tx_dial->adjustment);
+
+    if (new_value < gtk_adjustment_get_lower(tx_dial->adjustment))
+        new_value = gtk_adjustment_get_lower(tx_dial->adjustment);
+
+    if (new_value > gtk_adjustment_get_upper(tx_dial->adjustment))
+        new_value = gtk_adjustment_get_upper(tx_dial->adjustment);
+
+    if (new_value != gtk_adjustment_get_value(tx_dial->adjustment)) {
+        gtk_adjustment_set_value(tx_dial->adjustment, new_value);
+    }
+
+    calc_image(new_value, image);
+
+    if (image != tx_dial->old_image) {
+        tx_dial->old_image = image;
+        gtk_widget_queue_draw(GTK_WIDGET(tx_dial));
+    }
 }
 
-static void gtk_tx_dial_adjustment_changed (GtkAdjustment *adjustment,
-                             gpointer       data)
-{
-       GtkTxDial *tx_dial;
-       
-       g_return_if_fail (adjustment != NULL);
-       g_return_if_fail (data != NULL);
-       
-       tx_dial = GTK_TX_DIAL (data);
-       
-       if ((tx_dial->old_value != gtk_adjustment_get_value(adjustment)) ||
-               (tx_dial->old_lower != gtk_adjustment_get_lower(adjustment)) ||
-               (tx_dial->old_upper != gtk_adjustment_get_upper(adjustment))) {
-               tx_dial->old_value = gtk_adjustment_get_value(adjustment);
-               tx_dial->old_lower = gtk_adjustment_get_lower(adjustment);
-               tx_dial->old_upper = gtk_adjustment_get_upper(adjustment);
-               tx_dial->old_range = gtk_adjustment_get_upper(adjustment)-gtk_adjustment_get_lower(adjustment);
-               
-               gtk_tx_dial_update (tx_dial);
-       }
+static void gtk_tx_dial_adjustment_changed(GtkAdjustment* adjustment,
+    gpointer data) {
+    GtkTxDial* tx_dial;
+
+    g_return_if_fail(adjustment != NULL);
+    g_return_if_fail(data != NULL);
+
+    tx_dial = GTK_TX_DIAL(data);
+
+    if ((tx_dial->old_value != gtk_adjustment_get_value(adjustment)) || (tx_dial->old_lower != gtk_adjustment_get_lower(adjustment)) || (tx_dial->old_upper != gtk_adjustment_get_upper(adjustment))) {
+        tx_dial->old_value = gtk_adjustment_get_value(adjustment);
+        tx_dial->old_lower = gtk_adjustment_get_lower(adjustment);
+        tx_dial->old_upper = gtk_adjustment_get_upper(adjustment);
+        tx_dial->old_range = gtk_adjustment_get_upper(adjustment) - gtk_adjustment_get_lower(adjustment);
+
+        gtk_tx_dial_update(tx_dial);
+    }
 }
 
-static void gtk_tx_dial_adjustment_value_changed (GtkAdjustment *adjustment, gpointer data)
-{
-       GtkTxDial *tx_dial;
-       
-       g_return_if_fail (adjustment != NULL);
-       g_return_if_fail (data != NULL);
-       
-       tx_dial = GTK_TX_DIAL (data);
-       
-       if (tx_dial->old_value != gtk_adjustment_get_value(adjustment)) {
-               gtk_tx_dial_update (tx_dial);
-               tx_dial->old_value = gtk_adjustment_get_value(adjustment);
-       }
+static void gtk_tx_dial_adjustment_value_changed(GtkAdjustment* adjustment, gpointer data) {
+    GtkTxDial* tx_dial;
+
+    g_return_if_fail(adjustment != NULL);
+    g_return_if_fail(data != NULL);
+
+    tx_dial = GTK_TX_DIAL(data);
+
+    if (tx_dial->old_value != gtk_adjustment_get_value(adjustment)) {
+        gtk_tx_dial_update(tx_dial);
+        tx_dial->old_value = gtk_adjustment_get_value(adjustment);
+    }
 }
index af5a2ffd7053592c148fdcf9e969ea9f6c2ab236..16acaa00f2de5160be578632f63effe11d145298 100644 (file)
@@ -1,26 +1,26 @@
 /*
     terminatorX - realtime audio scratching software
     Copyright (C) 1999-2021  Alexander König
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
+
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
+
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
     File: tX_dial.h
+
     Description: Header to tX_dial.c - this widget is based on the gtk_dial
     example from the gtk+ tutorial which is
     Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
-*/    
+*/
 
 #ifndef __GTK_TX_DIAL_H__
 #define __GTK_TX_DIAL_H__
 extern "C" {
 #endif /* __cplusplus */
 
-#define GTK_TX_DIAL(obj)              G_TYPE_CHECK_INSTANCE_CAST (obj, gtk_tx_dial_get_type (), GtkTxDial)
-#define GTK_TX_DIAL_CLASS(klass)  GTK_CHECK_CLASS_CAST (klass, gtk_tx_dial_get_type (), GtkTxDialClass)
-#define GTK_IS_TX_DIAL(obj)       G_TYPE_CHECK_INSTANCE_TYPE (obj, gtk_tx_dial_get_type ())
+#define GTK_TX_DIAL(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, gtk_tx_dial_get_type(), GtkTxDial)
+#define GTK_TX_DIAL_CLASS(klass) GTK_CHECK_CLASS_CAST(klass, gtk_tx_dial_get_type(), GtkTxDialClass)
+#define GTK_IS_TX_DIAL(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, gtk_tx_dial_get_type())
 
-typedef struct _GtkTxDial        GtkTxDial;
-typedef struct _GtkTxDialClass   GtkTxDialClass;
+typedef struct _GtkTxDial GtkTxDial;
+typedef struct _GtkTxDialClass GtkTxDialClass;
 
 struct _GtkTxDial {
-       GtkWidget widget;
-       
-       /* Button currently pressed or 0 if none */
-       guint8 button;
-       
-       /* Old values from adjustment stored so we know when something changes */
-       gfloat old_value;
-       gfloat old_lower;
-       gfloat old_upper;
-       gfloat old_range;
-       
-       /* The adjustment object that stores the data for this tx_dial */
-       GtkAdjustment *adjustment;
-       
-       gint x, y;
-       gint xofs, yofs;
-       
-       gint old_image;
+    GtkWidget widget;
+
+    /* Button currently pressed or 0 if none */
+    guint8 button;
+
+    /* Old values from adjustment stored so we know when something changes */
+    gfloat old_value;
+    gfloat old_lower;
+    gfloat old_upper;
+    gfloat old_range;
+
+    /* The adjustment object that stores the data for this tx_dial */
+    GtkAdjustment* adjustment;
+
+    gint x, y;
+    gint xofs, yofs;
+
+    gint old_image;
 };
 
 struct _GtkTxDialClass {
-       GtkWidgetClass parent_class;
+    GtkWidgetClass parent_class;
 };
 
-GtkWidget* gtk_tx_dial_new (GtkAdjustment *adjustment);
-GType gtk_tx_dial_get_type (void);
-GtkAdjustment* gtk_tx_dial_get_adjustment (GtkTxDial *tx_dial);
+GtkWidget* gtk_tx_dial_new(GtkAdjustment* adjustment);
+GType gtk_tx_dial_get_type(void);
+GtkAdjustment* gtk_tx_dial_get_adjustment(GtkTxDial* tx_dial);
 
-void gtk_tx_dial_set_adjustment (GtkTxDial *tx_dial, GtkAdjustment *adjustment);
+void gtk_tx_dial_set_adjustment(GtkTxDial* tx_dial, GtkAdjustment* adjustment);
 
 #ifdef __cplusplus
 }
index 4181b366e59dbef2e95809fa2cc40c1fcd7e2ba7..3fcd140a870781b3e820a75772c85b316e9fe27f 100644 (file)
 /*
     terminatorX - realtime audio scratching software
     Copyright (C) 1999-2021  Alexander König
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
+
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
+
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
     File: tX_dialog.cc
+
     Description: Contains the implementation of the Options and About
-                Dialogs. (And some really ugly "WE WANT TO 
+                Dialogs. (And some really ugly "WE WANT TO
                 TYPE LESS" macros)
-*/    
+*/
 
+#include "tX_dialog.h"
 #include "config.h"
-#include "tX_types.h"
 #include "tX_global.h"
-#include "tX_dialog.h"
-#include <gtk/gtk.h>
-#include <string.h>
-#include <gdk/gdk.h>
+#include "tX_types.h"
 #include "tX_ui_interface.h"
 #include "tX_ui_support.h"
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <string.h>
 
-#include "tX_widget.h"
 #include "tX_flash.h"
+#include "tX_widget.h"
 
 #include "license.c"
+#include "tX_engine.h"
 #include "tX_maingui.h"
-#include "version.h"
 #include "tX_vtt.h"
+#include "version.h"
 #include <dirent.h>
-#include "tX_engine.h"
 
 #include "icons/tX_dialog_resources.c"
 
 #ifdef USE_SCHEDULER
-#include <sched.h>
 #include <pthread.h>
+#include <sched.h>
 #endif
 
 #ifdef USE_JACK
 extern void jack_check();
 #endif
 
-extern char *logo_xpm[];
-GtkWidget *opt_dialog;
-int opt_hidden=0;
-
-static GtkWidget *last_alsa_device_widget=NULL;
-
-void apply_options(GtkWidget *dialog) {
-       /* Audio */
-       if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "alsa_driver")))) {
-               globals.audiodevice_type=ALSA;
-       } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "oss_driver")))) {
-               globals.audiodevice_type=OSS;
-       } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "jack_driver")))) {
-               globals.audiodevice_type=JACK;
-       } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "pulse_driver")))) {
-               globals.audiodevice_type=PULSE;
-       }
-       globals.use_realtime=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "use_realtime")));
-       
-       /* Audio: OSS */
-       char *oss_device = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "oss_audio_device")));
-       if (oss_device) {
-               strcpy(globals.oss_device, oss_device);
-       }
-       globals.oss_buff_no=(int) gtk_spin_button_get_value(GTK_SPIN_BUTTON(lookup_widget(dialog, "oss_buffers")));
-       globals.oss_buff_size=(int) gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "oss_buffersize")));
-       globals.oss_samplerate=atoi(gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "oss_samplerate"))));
-       
-       /* Audio: ALSA */
-       char *alsa_device = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "alsa_audio_device")));
-       if (alsa_device) {
-               strcpy(globals.alsa_device_id, alsa_device);
-       }
-       globals.alsa_buffer_time=(int) gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "alsa_buffer_time")));
-       globals.alsa_buffer_time*=1000;
-       globals.alsa_period_time=(int) gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "alsa_period_time")));
-       globals.alsa_period_time*=1000;
-       globals.alsa_samplerate=atoi(gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "alsa_samplerate")))); 
-       globals.alsa_free_hwstats=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "alsa_free_hwstats")));
-       globals.pulse_buffer_length=(int) gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "pulse_buffer_size")));
-
-       /* TODO: JACK
-       */
-       
-       globals.mouse_speed=gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "mouse_speed")));
-       globals.sense_cycles=(int) gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "stop_sense_cycles")));
-       globals.vtt_inertia=gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "vtt_inertia")));
-       
-       /* User Interface */ 
-       globals.show_nag=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "startup_nagbox")))==TRUE);
-       globals.tooltips=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "mainwin_tooltips")))==TRUE);
-       globals.filename_length=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(lookup_widget(dialog, "filename_length")));
-//     if (globals.tooltips) gtk_tooltips_enable(gui_tooltips);
-//     else gtk_tooltips_disable(gui_tooltips);
-//     TODO: Disable Tooltips no longer possible?
-
-       if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_text_only")))) {
-               globals.button_type=BUTTON_TYPE_TEXT;
-       } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_icon_only")))) {
-               globals.button_type=BUTTON_TYPE_ICON;
-       } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_text_and_icon")))) {
-               globals.button_type=BUTTON_TYPE_BOTH;
-       }
-       
-       globals.update_delay=(int) gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "update_delay")));
-       globals.update_idle=(int) gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "update_idle")));
-       globals.flash_response=gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "vumeter_decay")));
-
-       if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "override_knob_size")))) {
-               globals.knob_size_override=gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "knob_size")));
-       } else {
-               globals.knob_size_override = 0;
-       }
-
-       globals.wav_display_history=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "wav_display_history")))==TRUE);
-       globals.title_bar_alpha=gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "title_bar_alpha")));
-
-       /* Audio Colors */
-       
-       strcpy(globals.wav_display_bg_focus, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_bg_focus")), "Color"));
-       strcpy(globals.wav_display_bg_no_focus, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_bg_no_focus")), "Color"));
-       strcpy(globals.wav_display_fg_focus, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_fg_focus")), "Color"));
-       strcpy(globals.wav_display_fg_no_focus, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_fg_no_focus")), "Color"));
-       strcpy(globals.wav_display_cursor, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_cursor")), "Color"));
-       strcpy(globals.wav_display_cursor_mute, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_cursor_mute")), "Color"));
-       globals.wav_use_vtt_color=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "wav_use_vtt_color")))==TRUE);
-
-       /* VU Colors */ 
-       strcpy(globals.vu_meter_bg, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "vu_meter_bg")), "Color"));
-       strcpy(globals.vu_meter_loud, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "vu_meter_loud")), "Color"));
-       strcpy(globals.vu_meter_normal, (char *) g_object_get_data(G_OBJECT(lookup_widget(dialog, "vu_meter_normal")), "Color"));
-
-       globals.vu_meter_border_intensity=gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "vu_meter_border_intensity")));
-       
-       /* Misc */
-       strcpy(globals.file_editor, gtk_entry_get_text(GTK_ENTRY(lookup_widget(dialog, "soundfile_editor"))));
-       strcpy(globals.lrdf_path, gtk_entry_get_text(GTK_ENTRY(lookup_widget(dialog, "ladspa_rdf_path"))));
-       globals.compress_set_files=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "compress_set_files")))==TRUE);        
-       globals.prelis=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "prelisten_enabled")))==TRUE);
-       globals.restore_midi_connections=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "reconnect_enabled")))==TRUE);
-       globals.quit_confirm=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "quit_confirm")))==TRUE);
-       globals.verbose_plugin_loading=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "verbose_plugin_loading")))==TRUE);
-       globals.force_nonrt_plugins=(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "force_nonrt_plugins")))==TRUE);
-       
-       /* update colors */
-       std::list<vtt_class *>::iterator vtt;
-       
-       for (vtt=vtt_class::main_list.begin(); vtt!=vtt_class::main_list.end(); vtt++) {
-               gtk_tx_update_colors(GTK_TX((*vtt)->gui.display), (*vtt)->get_color());
-               gtk_widget_queue_draw((*vtt)->gui.display);
-               gtk_tx_flash_update_colors(GTK_TX_FLASH((*vtt)->gui.flash));
-               gtk_widget_queue_draw((*vtt)->gui.flash);
-               update_vtt_css((*vtt), (*vtt)->get_color());
-       }
-       
-       gtk_tx_flash_update_colors(GTK_TX_FLASH(main_flash));
-       gtk_widget_queue_draw(main_flash);
-       
-#ifdef USE_JACK
-       jack_check();
-#endif 
-}
-
+extern char* logo_xpm[];
+GtkWidget* opt_dialog;
+int opt_hidden = 0;
+
+static GtkWidget* last_alsa_device_widget = NULL;
+
+void apply_options(GtkWidget* dialog) {
+    /* Audio */
+    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "alsa_driver")))) {
+        globals.audiodevice_type = ALSA;
+    } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "oss_driver")))) {
+        globals.audiodevice_type = OSS;
+    } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "jack_driver")))) {
+        globals.audiodevice_type = JACK;
+    } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "pulse_driver")))) {
+        globals.audiodevice_type = PULSE;
+    }
+    globals.use_realtime = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "use_realtime")));
 
-#define WID_DYN TRUE, TRUE, 0
-#define WID_FIX FALSE, FALSE, 0
+    /* Audio: OSS */
+    char* oss_device = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "oss_audio_device")));
+    if (oss_device) {
+        strcpy(globals.oss_device, oss_device);
+    }
+    globals.oss_buff_no = (int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(lookup_widget(dialog, "oss_buffers")));
+    globals.oss_buff_size = (int)gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "oss_buffersize")));
+    globals.oss_samplerate = atoi(gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "oss_samplerate"))));
+
+    /* Audio: ALSA */
+    char* alsa_device = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "alsa_audio_device")));
+    if (alsa_device) {
+        strcpy(globals.alsa_device_id, alsa_device);
+    }
+    globals.alsa_buffer_time = (int)gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "alsa_buffer_time")));
+    globals.alsa_buffer_time *= 1000;
+    globals.alsa_period_time = (int)gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "alsa_period_time")));
+    globals.alsa_period_time *= 1000;
+    globals.alsa_samplerate = atoi(gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "alsa_samplerate"))));
+    globals.alsa_free_hwstats = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "alsa_free_hwstats")));
+    globals.pulse_buffer_length = (int)gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "pulse_buffer_size")));
+
+    /* TODO: JACK
+       */
 
-#define my_new_subsec(s); \
-       separator=gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); \
-       gtk_box_pack_start(GTK_BOX(vbox), separator, WID_DYN);\
-       gtk_widget_show(separator); \
-       label=gtk_label_new(s); \
-       gtk_widget_set_halign(label, GTK_ALIGN_START); \
-       gtk_box_pack_start(GTK_BOX(vbox), label, WID_DYN); \
-       gtk_widget_show(label); 
+    globals.mouse_speed = gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "mouse_speed")));
+    globals.sense_cycles = (int)gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "stop_sense_cycles")));
+    globals.vtt_inertia = gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "vtt_inertia")));
+
+    /* User Interface */
+    globals.show_nag = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "startup_nagbox"))) == TRUE);
+    globals.tooltips = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "mainwin_tooltips"))) == TRUE);
+    globals.filename_length = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(lookup_widget(dialog, "filename_length")));
+    // if (globals.tooltips) gtk_tooltips_enable(gui_tooltips);
+    // else gtk_tooltips_disable(gui_tooltips);
+    // TODO: Disable Tooltips no longer possible?
+
+    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_text_only")))) {
+        globals.button_type = BUTTON_TYPE_TEXT;
+    } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_icon_only")))) {
+        globals.button_type = BUTTON_TYPE_ICON;
+    } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_text_and_icon")))) {
+        globals.button_type = BUTTON_TYPE_BOTH;
+    }
 
-#define my_new_button(btn, s); \
-       btn=gtk_button_new_with_label(s); \
-       gtk_box_pack_start(GTK_BOX(aa), btn, WID_DYN); \
-       gtk_widget_show(btn);
-       
+    globals.update_delay = (int)gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "update_delay")));
+    globals.update_idle = (int)gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "update_idle")));
+    globals.flash_response = gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "vumeter_decay")));
 
-#define begin_box(); box=gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
+    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "override_knob_size")))) {
+        globals.knob_size_override = gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "knob_size")));
+    } else {
+        globals.knob_size_override = 0;
+    }
 
-#define begin_hom_box(); box=gtk_hbox_new(TRUE, 5);
+    globals.wav_display_history = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "wav_display_history"))) == TRUE);
+    globals.title_bar_alpha = gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "title_bar_alpha")));
+
+    /* Audio Colors */
+
+    strcpy(globals.wav_display_bg_focus, (char*)g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_bg_focus")), "Color"));
+    strcpy(globals.wav_display_bg_no_focus, (char*)g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_bg_no_focus")), "Color"));
+    strcpy(globals.wav_display_fg_focus, (char*)g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_fg_focus")), "Color"));
+    strcpy(globals.wav_display_fg_no_focus, (char*)g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_fg_no_focus")), "Color"));
+    strcpy(globals.wav_display_cursor, (char*)g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_cursor")), "Color"));
+    strcpy(globals.wav_display_cursor_mute, (char*)g_object_get_data(G_OBJECT(lookup_widget(dialog, "wav_display_cursor_mute")), "Color"));
+    globals.wav_use_vtt_color = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "wav_use_vtt_color"))) == TRUE);
+
+    /* VU Colors */
+    strcpy(globals.vu_meter_bg, (char*)g_object_get_data(G_OBJECT(lookup_widget(dialog, "vu_meter_bg")), "Color"));
+    strcpy(globals.vu_meter_loud, (char*)g_object_get_data(G_OBJECT(lookup_widget(dialog, "vu_meter_loud")), "Color"));
+    strcpy(globals.vu_meter_normal, (char*)g_object_get_data(G_OBJECT(lookup_widget(dialog, "vu_meter_normal")), "Color"));
+
+    globals.vu_meter_border_intensity = gtk_range_get_value(GTK_RANGE(lookup_widget(dialog, "vu_meter_border_intensity")));
+
+    /* Misc */
+    strcpy(globals.file_editor, gtk_entry_get_text(GTK_ENTRY(lookup_widget(dialog, "soundfile_editor"))));
+    strcpy(globals.lrdf_path, gtk_entry_get_text(GTK_ENTRY(lookup_widget(dialog, "ladspa_rdf_path"))));
+    globals.compress_set_files = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "compress_set_files"))) == TRUE);
+    globals.prelis = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "prelisten_enabled"))) == TRUE);
+    globals.restore_midi_connections = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "reconnect_enabled"))) == TRUE);
+    globals.quit_confirm = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "quit_confirm"))) == TRUE);
+    globals.verbose_plugin_loading = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "verbose_plugin_loading"))) == TRUE);
+    globals.force_nonrt_plugins = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "force_nonrt_plugins"))) == TRUE);
+
+    /* update colors */
+    std::list<vtt_class*>::iterator vtt;
+
+    for (vtt = vtt_class::main_list.begin(); vtt != vtt_class::main_list.end(); vtt++) {
+        gtk_tx_update_colors(GTK_TX((*vtt)->gui.display), (*vtt)->get_color());
+        gtk_widget_queue_draw((*vtt)->gui.display);
+        gtk_tx_flash_update_colors(GTK_TX_FLASH((*vtt)->gui.flash));
+        gtk_widget_queue_draw((*vtt)->gui.flash);
+        update_vtt_css((*vtt), (*vtt)->get_color());
+    }
 
-#define end_box(); gtk_box_pack_start(GTK_BOX(vbox), box, WID_DYN); \
-       gtk_widget_show(box);
+    gtk_tx_flash_update_colors(GTK_TX_FLASH(main_flash));
+    gtk_widget_queue_draw(main_flash);
 
-#define add_widget_dyn(wid); gtk_box_pack_start(GTK_BOX(box), wid, WID_DYN);\
-       gtk_widget_show(wid);
-       
-#define add_widget_fix(wid); gtk_box_pack_start(GTK_BOX(box), wid, WID_FIX);\
-       gtk_widget_show(wid);
+#ifdef USE_JACK
+    jack_check();
+#endif
+}
 
-#define add_expl(s); label=gtk_label_new(s); \
-       add_widget_fix(label);
+#define WID_DYN TRUE, TRUE, 0
+#define WID_FIX FALSE, FALSE, 0
 
-#define add_expl_dyn(s); label=gtk_label_new(s); \
-       add_widget_dyn(label);
+#define my_new_subsec(s)                                       \
+    ;                                                          \
+    separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); \
+    gtk_box_pack_start(GTK_BOX(vbox), separator, WID_DYN);     \
+    gtk_widget_show(separator);                                \
+    label = gtk_label_new(s);                                  \
+    gtk_widget_set_halign(label, GTK_ALIGN_START);             \
+    gtk_box_pack_start(GTK_BOX(vbox), label, WID_DYN);         \
+    gtk_widget_show(label);
+
+#define my_new_button(btn, s)                      \
+    ;                                              \
+    btn = gtk_button_new_with_label(s);            \
+    gtk_box_pack_start(GTK_BOX(aa), btn, WID_DYN); \
+    gtk_widget_show(btn);
+
+#define begin_box() \
+    ;               \
+    box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
+
+#define begin_hom_box() \
+    ;                   \
+    box = gtk_hbox_new(TRUE, 5);
+
+#define end_box()                                    \
+    ;                                                \
+    gtk_box_pack_start(GTK_BOX(vbox), box, WID_DYN); \
+    gtk_widget_show(box);
+
+#define add_widget_dyn(wid)                         \
+    ;                                               \
+    gtk_box_pack_start(GTK_BOX(box), wid, WID_DYN); \
+    gtk_widget_show(wid);
+
+#define add_widget_fix(wid)                         \
+    ;                                               \
+    gtk_box_pack_start(GTK_BOX(box), wid, WID_FIX); \
+    gtk_widget_show(wid);
+
+#define add_expl(s)           \
+    ;                         \
+    label = gtk_label_new(s); \
+    add_widget_fix(label);
+
+#define add_expl_dyn(s)       \
+    ;                         \
+    label = gtk_label_new(s); \
+    add_widget_dyn(label);
 
 #ifdef USE_ALSA
-void append_alsa_device_list(GtkComboBoxText *combo, char *current) {
-       FILE *file;
-       char buffer[PATH_MAX+1];
-       int ctr = 0;
-       
-       if ((file = fopen("/proc/asound/pcm", "r"))) {
-               while(fgets(buffer, PATH_MAX, file)) {
-                       buffer[PATH_MAX]=0;
-                       if (strlen(buffer)) buffer[strlen(buffer)-1]=0;
-                       if(strstr(buffer, "playback")) {
-                               char foo[PATH_MAX];
-                               char tmp[PATH_MAX*2];
-                               memset(foo, 0, PATH_MAX);
-                               int card;
-                               int device;
-                               sscanf(buffer, "%i-%i: %1024c", &card, &device, foo);
-                               sprintf(tmp, "hw:%i,%i# %s", card, device, foo);
-                               
-                               gtk_combo_box_text_append_text(combo, strdup(tmp));
-                               
-                               if (strcmp(tmp, current) == 0) {
-                                       gtk_combo_box_set_active(GTK_COMBO_BOX(combo), ctr);
-                               }
-                               ctr++;
-                                       
-                       }
-               }
-               fclose(file);
-       }
+void append_alsa_device_list(GtkComboBoxText* combo, char* current) {
+    FILE* file;
+    char buffer[PATH_MAX + 1];
+    int ctr = 0;
+
+    if ((file = fopen("/proc/asound/pcm", "r"))) {
+        while (fgets(buffer, PATH_MAX, file)) {
+            buffer[PATH_MAX] = 0;
+            if (strlen(buffer))
+                buffer[strlen(buffer) - 1] = 0;
+            if (strstr(buffer, "playback")) {
+                char foo[PATH_MAX];
+                char tmp[PATH_MAX * 2];
+                memset(foo, 0, PATH_MAX);
+                int card;
+                int device;
+
+                sscanf(buffer, "%i-%i: %1024c", &card, &device, foo);
+                sprintf(tmp, "hw:%i,%i# %s", card, device, foo);
+
+                gtk_combo_box_text_append_text(combo, strdup(tmp));
+
+                if (strcmp(tmp, current) == 0) {
+                    gtk_combo_box_set_active(GTK_COMBO_BOX(combo), ctr);
+                }
+                ctr++;
+            }
+        }
+        fclose(file);
+    }
 }
 #else
-void append_alsa_device_list(GtkComboBoxText *combo, char* current) {
+void append_alsa_device_list(GtkComboBoxTextcombo, char* current) {
 }
 #endif
 
-
-int oss_select_dsp_only(const struct dirent *entry){
-       return (strstr(entry->d_name, "dsp")!=0);
+int oss_select_dsp_only(const struct dirent* entry) {
+    return (strstr(entry->d_name, "dsp") != 0);
 }
 
-void append_oss_device_list(GtkComboBoxText *combo, char *current) {
-    struct dirent **namelist;
-    int n,i;
+void append_oss_device_list(GtkComboBoxText* combo, char* current) {
+    struct dirent** namelist;
+    int n, i;
     n = scandir("/dev", &namelist, oss_select_dsp_only, alphasort);
 
-    if (n>0) {
-    for (i=0; i<n; i++) {
-       char buffer[PATH_MAX];
-       snprintf(buffer, sizeof(buffer), "/dev/%s", namelist[i]->d_name);
-       free(namelist[i]);
-
-       gtk_combo_box_text_append_text(combo, strdup(buffer));
-       if (strcmp(buffer, current)==0) {
-           gtk_combo_box_set_active(GTK_COMBO_BOX(combo), i);
-       }
-       }
+    if (n > 0) {
+        for (i = 0; i < n; i++) {
+            char buffer[PATH_MAX];
+            snprintf(buffer, sizeof(buffer), "/dev/%s", namelist[i]->d_name);
+            free(namelist[i]);
+
+            gtk_combo_box_text_append_text(combo, strdup(buffer));
+            if (strcmp(buffer, current) == 0) {
+                gtk_combo_box_set_active(GTK_COMBO_BOX(combo), i);
+            }
+        }
     }
 }
 
-
-void append_sampling_rates_list(GtkComboBoxText *combo, int current) {
-
-       gtk_combo_box_text_append_text(combo,  "22000");
-       gtk_combo_box_text_append_text(combo,  "32000");
-       gtk_combo_box_text_append_text(combo,  "44100");
-       gtk_combo_box_text_append_text(combo,  "48000");
-       switch (current) {
-               case 22000:
-                       gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
-                       break;
-               case 32000:
-                       gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 1);
-                       break;
-               case 44100:
-                       gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 2);
-                       break;
-               case 48000:
-               default:
-                       gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 3);
-       }
+void append_sampling_rates_list(GtkComboBoxText* combo, int current) {
+
+    gtk_combo_box_text_append_text(combo, "22000");
+    gtk_combo_box_text_append_text(combo, "32000");
+    gtk_combo_box_text_append_text(combo, "44100");
+    gtk_combo_box_text_append_text(combo, "48000");
+    switch (current) {
+    case 22000:
+        gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
+        break;
+    case 32000:
+        gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 1);
+        break;
+    case 44100:
+        gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 2);
+        break;
+    case 48000:
+    default:
+        gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 3);
+    }
 }
 
 #define MAX_COLORS 10
-char *colors[MAX_COLORS]={ NULL };
-
-#define set_color_button(s,g); \
-       sprintf(tmp, "<span foreground=\"%s\"><b>%s</b></span>", s, s);\
-       gtk_label_set_markup(GTK_LABEL(gtk_container_get_children(GTK_CONTAINER(lookup_widget(dialog, g)))->data), tmp);\
-       strcpy(colors[ctr], s);\
-       g_object_set_data(G_OBJECT(lookup_widget(dialog, g)), "Color", colors[ctr]);\
-       ctr++;
-
-
-void init_tx_options(GtkWidget *dialog) {
-       char tmp[256];
-       
-       if (colors[0]==NULL) {
-               for (int i=0; i<MAX_COLORS; i++) {
-                       colors[i]=new char[8];
-                       colors[i][0]=0;
-               }
-       }
-       
-       /* Audio */
-       switch (globals.audiodevice_type) {             
-               case ALSA: gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "alsa_driver")), 1);
-                       break;
-               
-               case JACK: gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "jack_driver")), 1);
-                       break;
-
-               case PULSE: gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "pulse_driver")), 1);
-                       break;
-
-               case OSS: 
-               default:
-                       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "oss_driver")), 1);
-                       break;
-       }
-
-       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "use_realtime")), globals.use_realtime);
+char* colors[MAX_COLORS] = { NULL };
+
+#define set_color_button(s, g)                                                                                       \
+    ;                                                                                                                \
+    sprintf(tmp, "<span foreground=\"%s\"><b>%s</b></span>", s, s);                                                  \
+    gtk_label_set_markup(GTK_LABEL(gtk_container_get_children(GTK_CONTAINER(lookup_widget(dialog, g)))->data), tmp); \
+    strcpy(colors[ctr], s);                                                                                          \
+    g_object_set_data(G_OBJECT(lookup_widget(dialog, g)), "Color", colors[ctr]);                                     \
+    ctr++;
+
+void init_tx_options(GtkWidget* dialog) {
+    char tmp[256];
+
+    if (colors[0] == NULL) {
+        for (int i = 0; i < MAX_COLORS; i++) {
+            colors[i] = new char[8];
+            colors[i][0] = 0;
+        }
+    }
+
+    /* Audio */
+    switch (globals.audiodevice_type) {
+    case ALSA:
+        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "alsa_driver")), 1);
+        break;
+
+    case JACK:
+        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "jack_driver")), 1);
+        break;
+
+    case PULSE:
+        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "pulse_driver")), 1);
+        break;
+
+    case OSS:
+    default:
+        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "oss_driver")), 1);
+        break;
+    }
+
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "use_realtime")), globals.use_realtime);
 
 #ifndef USE_CAPABILITIES
-       /* rt's not configurable without capabilities. */
-       gtk_widget_hide(lookup_widget(dialog, "use_realtime"));
-       gtk_widget_hide(lookup_widget(dialog, "use_realtime_label"));   
+    /* rt's not configurable without capabilities. */
+    gtk_widget_hide(lookup_widget(dialog, "use_realtime"));
+    gtk_widget_hide(lookup_widget(dialog, "use_realtime_label"));
 #endif
-       
+
 #ifndef USE_OSS
-       gtk_widget_set_sensitive(lookup_widget(dialog, "oss_driver"), 0);
-       gtk_widget_set_sensitive(lookup_widget(dialog, "oss_audio_device"), 0);
-       gtk_widget_set_sensitive(lookup_widget(dialog, "oss_buffers"), 0);
-       gtk_widget_set_sensitive(lookup_widget(dialog, "oss_buffersize"), 0);
-       gtk_widget_set_sensitive(lookup_widget(dialog, "oss_samplerate"), 0);
+    gtk_widget_set_sensitive(lookup_widget(dialog, "oss_driver"), 0);
+    gtk_widget_set_sensitive(lookup_widget(dialog, "oss_audio_device"), 0);
+    gtk_widget_set_sensitive(lookup_widget(dialog, "oss_buffers"), 0);
+    gtk_widget_set_sensitive(lookup_widget(dialog, "oss_buffersize"), 0);
+    gtk_widget_set_sensitive(lookup_widget(dialog, "oss_samplerate"), 0);
 #endif
-       
+
 #ifndef USE_ALSA
-       gtk_widget_set_sensitive(lookup_widget(dialog, "alsa_driver"), 0);      
-        gtk_widget_set_sensitive(lookup_widget(dialog, "alsa_audio_device"), 0);
-        gtk_widget_set_sensitive(lookup_widget(dialog, "alsa_samplerate"), 0);
-        gtk_widget_set_sensitive(lookup_widget(dialog, "alsa_period_time"), 0);
-        gtk_widget_set_sensitive(lookup_widget(dialog, "alsa_buffer_time"), 0);
-        gtk_widget_set_sensitive(lookup_widget(dialog, "alsa_free_hwstats"), 0);
+    gtk_widget_set_sensitive(lookup_widget(dialog, "alsa_driver"), 0);
+    gtk_widget_set_sensitive(lookup_widget(dialog, "alsa_audio_device"), 0);
+    gtk_widget_set_sensitive(lookup_widget(dialog, "alsa_samplerate"), 0);
+    gtk_widget_set_sensitive(lookup_widget(dialog, "alsa_period_time"), 0);
+    gtk_widget_set_sensitive(lookup_widget(dialog, "alsa_buffer_time"), 0);
+    gtk_widget_set_sensitive(lookup_widget(dialog, "alsa_free_hwstats"), 0);
 #endif
-       
+
 #ifndef USE_JACK
-       gtk_widget_set_sensitive(lookup_widget(dialog, "jack_driver"), 0);
-#endif 
+    gtk_widget_set_sensitive(lookup_widget(dialog, "jack_driver"), 0);
+#endif
 
 #ifndef USE_PULSE
-       gtk_widget_set_sensitive(lookup_widget(dialog, "pulse_driver"), 0);
-       gtk_widget_set_sensitive(lookup_widget(dialog, "pulse_buffer_size"), 0);
+    gtk_widget_set_sensitive(lookup_widget(dialog, "pulse_driver"), 0);
+    gtk_widget_set_sensitive(lookup_widget(dialog, "pulse_buffer_size"), 0);
 #endif
-       
-       /* Audio: OSS */
-       append_oss_device_list(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "oss_audio_device")), globals.oss_device);
-
-       gtk_spin_button_set_value(GTK_SPIN_BUTTON(lookup_widget(dialog, "oss_buffers")), globals.oss_buff_no);
-       gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "oss_buffersize")), globals.oss_buff_size);
-       gtk_widget_set_tooltip_text(lookup_widget(dialog, "oss_buffersize"), "Set the size of the kernel level audio buffers. On slower systems you might have to increase this value (if you hear \"clicks\" or drop-outs). Lower values mean lower latency though."); 
-       append_sampling_rates_list(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "oss_samplerate")), globals.oss_samplerate);
-       
-       /* Audio: ALSA */
-       GtkComboBoxText *combo=GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "alsa_audio_device"));
-       last_alsa_device_widget=NULL;
-       
-       append_alsa_device_list(GTK_COMBO_BOX_TEXT(combo), globals.alsa_device_id);
-
-       gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "alsa_buffer_time")), globals.alsa_buffer_time/1000);
-       gtk_widget_set_tooltip_text(lookup_widget(dialog, "alsa_buffer_time"), "Sets the size of the ALSA ring buffer. On slower systems you might have to increase this value (if you hear \"clicks\" or drop-outs). Lower values mean lower latency though.");        
-       gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "alsa_period_time")), globals.alsa_period_time/1000);
-       gtk_widget_set_tooltip_text(lookup_widget(dialog, "alsa_period_time"), "The ALSA period time determines how much audio data will be written to the device at once. It is recommended to set this value to a half or a third of the ALSA buffer time."); 
-
-       append_sampling_rates_list(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "alsa_samplerate")), globals.alsa_samplerate);
-       
-       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "alsa_free_hwstats")), globals.alsa_free_hwstats);
-       
-       gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "pulse_buffer_size")), globals.pulse_buffer_length);
-       gtk_widget_set_tooltip_text(lookup_widget(dialog, "pulse_buffer_size"), "Sets the requested buffer size for PulseAudio in samples (per channel). Lower values should result in lower latency, however PulseAudio may override this setting.");  
-
-       gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "mouse_speed")), globals.mouse_speed);
-       gtk_widget_set_tooltip_text(lookup_widget(dialog, "mouse_speed"), "The speed of your mouse in scratch mode. Use negative values to invert motion.");
-       
-       gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "stop_sense_cycles")), globals.sense_cycles);
-       gtk_widget_set_tooltip_text(lookup_widget(dialog, "stop_sense_cycles"),"If there is no \"motion-event\" for x cycles, where x is the number of cycles you select here, terminatorX assumes mouse motion has stopped. For smaller buffer sizes (=> shorter cycle times) you might have to increase this value"); 
-
-       gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "vtt_inertia")), globals.vtt_inertia);
-       gtk_widget_set_tooltip_text(lookup_widget(dialog, "vtt_inertia"),"This value defines how fast the turntables will adapt to the speed input - the higher this value, the longer it will take the turntable to actually reach the target speed.");        
-
-       gtk_spin_button_set_value(GTK_SPIN_BUTTON(lookup_widget(dialog, "filename_length")), globals.filename_length);
-
-       /* User Interface */ 
-       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "startup_nagbox")), globals.show_nag);
-       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "mainwin_tooltips")), globals.tooltips);
-       
-       switch (globals.button_type) {
-               case BUTTON_TYPE_TEXT:
-                       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_text_only")), 1);
-                       break;
-               
-               case BUTTON_TYPE_ICON:
-                       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_icon_only")), 1);
-                       break;
-               
-               case BUTTON_TYPE_BOTH:
-               default:
-                       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_text_and_icon")), 1);
-       }
-       
-       gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "update_delay")), globals.update_delay);
-       gtk_widget_set_tooltip_text(lookup_widget(dialog, "update_delay"), "How often to update the slow widgets.");    
-       gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "update_idle")), globals.update_idle);
-       gtk_widget_set_tooltip_text(lookup_widget(dialog, "update_idle"), "The update thread will idle for the selcted amount of milliseconds. If you want to have a more responsive display update reduce this value - if you have performance problems increase this value.");        
-       gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "vumeter_decay")), globals.flash_response);
-       gtk_widget_set_tooltip_text(lookup_widget(dialog, "vumeter_decay"), "Defines how fast the maximum values of the VU meters should be decayed."); 
-
-
-       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "override_knob_size")), globals.knob_size_override > 0);
-       if (globals.knob_size_override) {
-               gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "knob_size")), globals.knob_size_override);
-       } else {
-               gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "knob_size")), 48);
-       }
-       
-       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "wav_display_history")), globals.wav_display_history);
-       gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "title_bar_alpha")), globals.title_bar_alpha);
-
-       /* Audio Colors */
-       int ctr=0;
-       
-       set_color_button(globals.wav_display_bg_focus, "wav_display_bg_focus");
-       set_color_button(globals.wav_display_bg_no_focus, "wav_display_bg_no_focus");
-       set_color_button(globals.wav_display_fg_focus, "wav_display_fg_focus");
-       set_color_button(globals.wav_display_fg_no_focus, "wav_display_fg_no_focus");
-       set_color_button(globals.wav_display_cursor, "wav_display_cursor");
-       set_color_button(globals.wav_display_cursor_mute, "wav_display_cursor_mute");
-       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "wav_use_vtt_color")), globals.wav_use_vtt_color);
-       
-       /* VU Colors */
-       set_color_button(globals.vu_meter_bg, "vu_meter_bg");
-       set_color_button(globals.vu_meter_loud, "vu_meter_loud");
-       set_color_button(globals.vu_meter_normal, "vu_meter_normal");
-       
-       gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "vu_meter_border_intensity")), globals.vu_meter_border_intensity);
-       
-       /* Misc */
-       gtk_entry_set_text(GTK_ENTRY(lookup_widget(dialog, "soundfile_editor")), globals.file_editor);
-       gtk_entry_set_text(GTK_ENTRY(lookup_widget(dialog, "ladspa_rdf_path")), globals.lrdf_path);
-       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "compress_set_files")), globals.compress_set_files);
-       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "prelisten_enabled")), globals.prelis);
-       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "reconnect_enabled")), globals.restore_midi_connections);
-       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "quit_confirm")), globals.quit_confirm);
-       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "force_nonrt_plugins")), globals.force_nonrt_plugins);     
-       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "verbose_plugin_loading")), globals.verbose_plugin_loading);       
+
+    /* Audio: OSS */
+    append_oss_device_list(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "oss_audio_device")), globals.oss_device);
+
+    gtk_spin_button_set_value(GTK_SPIN_BUTTON(lookup_widget(dialog, "oss_buffers")), globals.oss_buff_no);
+    gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "oss_buffersize")), globals.oss_buff_size);
+    gtk_widget_set_tooltip_text(lookup_widget(dialog, "oss_buffersize"), "Set the size of the kernel level audio buffers. On slower systems you might have to increase this value (if you hear \"clicks\" or drop-outs). Lower values mean lower latency though.");
+    append_sampling_rates_list(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "oss_samplerate")), globals.oss_samplerate);
+
+    /* Audio: ALSA */
+    GtkComboBoxText* combo = GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "alsa_audio_device"));
+    last_alsa_device_widget = NULL;
+
+    append_alsa_device_list(GTK_COMBO_BOX_TEXT(combo), globals.alsa_device_id);
+
+    gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "alsa_buffer_time")), globals.alsa_buffer_time / 1000);
+    gtk_widget_set_tooltip_text(lookup_widget(dialog, "alsa_buffer_time"), "Sets the size of the ALSA ring buffer. On slower systems you might have to increase this value (if you hear \"clicks\" or drop-outs). Lower values mean lower latency though.");
+    gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "alsa_period_time")), globals.alsa_period_time / 1000);
+    gtk_widget_set_tooltip_text(lookup_widget(dialog, "alsa_period_time"), "The ALSA period time determines how much audio data will be written to the device at once. It is recommended to set this value to a half or a third of the ALSA buffer time.");
+
+    append_sampling_rates_list(GTK_COMBO_BOX_TEXT(lookup_widget(dialog, "alsa_samplerate")), globals.alsa_samplerate);
+
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "alsa_free_hwstats")), globals.alsa_free_hwstats);
+
+    gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "pulse_buffer_size")), globals.pulse_buffer_length);
+    gtk_widget_set_tooltip_text(lookup_widget(dialog, "pulse_buffer_size"), "Sets the requested buffer size for PulseAudio in samples (per channel). Lower values should result in lower latency, however PulseAudio may override this setting.");
+
+    gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "mouse_speed")), globals.mouse_speed);
+    gtk_widget_set_tooltip_text(lookup_widget(dialog, "mouse_speed"), "The speed of your mouse in scratch mode. Use negative values to invert motion.");
+
+    gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "stop_sense_cycles")), globals.sense_cycles);
+    gtk_widget_set_tooltip_text(lookup_widget(dialog, "stop_sense_cycles"), "If there is no \"motion-event\" for x cycles, where x is the number of cycles you select here, terminatorX assumes mouse motion has stopped. For smaller buffer sizes (=> shorter cycle times) you might have to increase this value");
+
+    gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "vtt_inertia")), globals.vtt_inertia);
+    gtk_widget_set_tooltip_text(lookup_widget(dialog, "vtt_inertia"), "This value defines how fast the turntables will adapt to the speed input - the higher this value, the longer it will take the turntable to actually reach the target speed.");
+
+    gtk_spin_button_set_value(GTK_SPIN_BUTTON(lookup_widget(dialog, "filename_length")), globals.filename_length);
+
+    /* User Interface */
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "startup_nagbox")), globals.show_nag);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "mainwin_tooltips")), globals.tooltips);
+
+    switch (globals.button_type) {
+    case BUTTON_TYPE_TEXT:
+        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_text_only")), 1);
+        break;
+
+    case BUTTON_TYPE_ICON:
+        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_icon_only")), 1);
+        break;
+
+    case BUTTON_TYPE_BOTH:
+    default:
+        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "buttons_text_and_icon")), 1);
+    }
+
+    gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "update_delay")), globals.update_delay);
+    gtk_widget_set_tooltip_text(lookup_widget(dialog, "update_delay"), "How often to update the slow widgets.");
+    gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "update_idle")), globals.update_idle);
+    gtk_widget_set_tooltip_text(lookup_widget(dialog, "update_idle"), "The update thread will idle for the selcted amount of milliseconds. If you want to have a more responsive display update reduce this value - if you have performance problems increase this value.");
+    gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "vumeter_decay")), globals.flash_response);
+    gtk_widget_set_tooltip_text(lookup_widget(dialog, "vumeter_decay"), "Defines how fast the maximum values of the VU meters should be decayed.");
+
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "override_knob_size")), globals.knob_size_override > 0);
+    if (globals.knob_size_override) {
+        gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "knob_size")), globals.knob_size_override);
+    } else {
+        gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "knob_size")), 48);
+    }
+
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "wav_display_history")), globals.wav_display_history);
+    gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "title_bar_alpha")), globals.title_bar_alpha);
+
+    /* Audio Colors */
+    int ctr = 0;
+
+    set_color_button(globals.wav_display_bg_focus, "wav_display_bg_focus");
+    set_color_button(globals.wav_display_bg_no_focus, "wav_display_bg_no_focus");
+    set_color_button(globals.wav_display_fg_focus, "wav_display_fg_focus");
+    set_color_button(globals.wav_display_fg_no_focus, "wav_display_fg_no_focus");
+    set_color_button(globals.wav_display_cursor, "wav_display_cursor");
+    set_color_button(globals.wav_display_cursor_mute, "wav_display_cursor_mute");
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "wav_use_vtt_color")), globals.wav_use_vtt_color);
+
+    /* VU Colors */
+    set_color_button(globals.vu_meter_bg, "vu_meter_bg");
+    set_color_button(globals.vu_meter_loud, "vu_meter_loud");
+    set_color_button(globals.vu_meter_normal, "vu_meter_normal");
+
+    gtk_range_set_value(GTK_RANGE(lookup_widget(dialog, "vu_meter_border_intensity")), globals.vu_meter_border_intensity);
+
+    /* Misc */
+    gtk_entry_set_text(GTK_ENTRY(lookup_widget(dialog, "soundfile_editor")), globals.file_editor);
+    gtk_entry_set_text(GTK_ENTRY(lookup_widget(dialog, "ladspa_rdf_path")), globals.lrdf_path);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "compress_set_files")), globals.compress_set_files);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "prelisten_enabled")), globals.prelis);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "reconnect_enabled")), globals.restore_midi_connections);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "quit_confirm")), globals.quit_confirm);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "force_nonrt_plugins")), globals.force_nonrt_plugins);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog, "verbose_plugin_loading")), globals.verbose_plugin_loading);
 }
 
-void create_options()
-{
-       opt_dialog=create_tx_options(GTK_WINDOW(main_window));
-       tX_set_icon(opt_dialog);
-       init_tx_options(opt_dialog);
-       gtk_widget_show(opt_dialog);
+void create_options() {
+    opt_dialog = create_tx_options(GTK_WINDOW(main_window));
+    tX_set_icon(opt_dialog);
+    init_tx_options(opt_dialog);
+    gtk_widget_show(opt_dialog);
 }
 
-void display_options()
-{
-       if (opt_dialog) {
-               gdk_window_raise(gtk_widget_get_window(opt_dialog));    
-       } else {
-               create_options();
-       }
+void display_options() {
+    if (opt_dialog) {
+        gdk_window_raise(gtk_widget_get_window(opt_dialog));
+    } else {
+        create_options();
+    }
 }
 
-GtkWidget *about=NULL;
+GtkWidget* about = NULL;
 
-void raise_about()
-{
-       if (about) gdk_window_raise(gtk_widget_get_window(about));
+void raise_about() {
+    if (about)
+        gdk_window_raise(gtk_widget_get_window(about));
 }
 
-
-void destroy_about()
-{
-       if (about) {    
-               gtk_widget_destroy(about);
-               about=NULL;
-       }
+void destroy_about() {
+    if (about) {
+        gtk_widget_destroy(about);
+        about = NULL;
+    }
 }
 
-#define add_about_wid(wid); gtk_box_pack_start(GTK_BOX(box), wid, WID_DYN); \
-       gtk_widget_show(wid);
-
-#define add_about_wid_fix(wid); gtk_box_pack_start(GTK_BOX(box), wid, WID_FIX); \
-       gtk_widget_show(wid);
-
-void show_about(int nag)
-{
-       GtkWidget *window;
-       GtkWidget *btn;
-       GtkWidget *box;
-       GtkWidget *label;
-       GtkWidget *sep;
-       GtkWidget *text;
-       GtkWidget *scroll;
-       GtkWidget *iwid;
-       GtkWidget *expander;
-       
-       /* Only raise the window if it's already open... */
-       if (about)  {
-               gdk_window_raise(gtk_widget_get_window(about));
-               return;
-       }
-       
-       /* Create the window... */
-       window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-       gtk_container_set_border_width(GTK_CONTAINER(window), 5);
-       gtk_window_set_title(GTK_WINDOW(window), "terminatorX - About");
-       gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
-       gtk_window_set_modal(GTK_WINDOW(window), TRUE);
-       gtk_window_set_resizable(GTK_WINDOW(window), nag ? TRUE: FALSE);
-
-       GdkPixbuf *image=gdk_pixbuf_new_from_xpm_data((const char **)logo_xpm);
-       iwid = gtk_image_new_from_pixbuf(image);
-       
-       if (nag) {
-               GtkWidget *box=gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
-               GtkWidget *box2=gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
-               GtkWidget *label;
-               
-               gtk_container_add(GTK_CONTAINER(window), box);
-               gtk_box_pack_start(GTK_BOX(box), iwid, WID_FIX);
-               gtk_box_pack_start(GTK_BOX(box), box2, WID_FIX);
-               
-               label=gtk_label_new(PACKAGE " release " VERSION);
-               gtk_box_pack_start(GTK_BOX(box2), label, WID_DYN);
-               gtk_widget_set_halign(label, GTK_ALIGN_START);
-               gtk_widget_show(label);
-
-               label=gtk_label_new("Copyright (C) 1999-2021 by Alexander König");
-               gtk_box_pack_start(GTK_BOX(box2), label, WID_DYN);
-               gtk_widget_set_halign(label, GTK_ALIGN_END);
-               gtk_widget_show(label);
-               
-               gtk_widget_show(box2);
-               gtk_widget_show(box);
-               gtk_widget_show(iwid);
-
-               gtk_window_set_decorated(GTK_WINDOW(window), FALSE);            
-               gtk_widget_show(window);
-       } else {
-               box=gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
-               add_about_wid_fix(iwid);
-               
-               sep=gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
-               add_about_wid_fix(sep);
-               
-               label=gtk_label_new("This is " PACKAGE " release " VERSION ".\nCopyright (C) 1999-2021 by Alexander König <alex@lisas.de>");
-
-               gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
-               add_about_wid_fix(label);
-
-               sep=gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
-               add_about_wid_fix(sep);
-
-               expander = gtk_expander_new("Build info");
-               GtkWidget *exbox=gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
-               gtk_container_add(GTK_CONTAINER(expander), exbox);
-               gtk_widget_show(exbox);
-
-               label=gtk_label_new("Compilation flags: "
+#define add_about_wid(wid)                          \
+    ;                                               \
+    gtk_box_pack_start(GTK_BOX(box), wid, WID_DYN); \
+    gtk_widget_show(wid);
+
+#define add_about_wid_fix(wid)                      \
+    ;                                               \
+    gtk_box_pack_start(GTK_BOX(box), wid, WID_FIX); \
+    gtk_widget_show(wid);
+
+void show_about(int nag) {
+    GtkWidget* window;
+    GtkWidget* btn;
+    GtkWidget* box;
+    GtkWidget* label;
+    GtkWidget* sep;
+    GtkWidget* text;
+    GtkWidget* scroll;
+    GtkWidget* iwid;
+    GtkWidget* expander;
+
+    /* Only raise the window if it's already open... */
+    if (about) {
+        gdk_window_raise(gtk_widget_get_window(about));
+        return;
+    }
+
+    /* Create the window... */
+    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+    gtk_container_set_border_width(GTK_CONTAINER(window), 5);
+    gtk_window_set_title(GTK_WINDOW(window), "terminatorX - About");
+    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
+    gtk_window_set_modal(GTK_WINDOW(window), TRUE);
+    gtk_window_set_resizable(GTK_WINDOW(window), nag ? TRUE : FALSE);
+
+    GdkPixbuf* image = gdk_pixbuf_new_from_xpm_data((const char**)logo_xpm);
+    iwid = gtk_image_new_from_pixbuf(image);
+
+    if (nag) {
+        GtkWidget* box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
+        GtkWidget* box2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
+        GtkWidget* label;
+
+        gtk_container_add(GTK_CONTAINER(window), box);
+        gtk_box_pack_start(GTK_BOX(box), iwid, WID_FIX);
+        gtk_box_pack_start(GTK_BOX(box), box2, WID_FIX);
+
+        label = gtk_label_new(PACKAGE " release " VERSION);
+        gtk_box_pack_start(GTK_BOX(box2), label, WID_DYN);
+        gtk_widget_set_halign(label, GTK_ALIGN_START);
+        gtk_widget_show(label);
+
+        label = gtk_label_new("Copyright (C) 1999-2021 by Alexander König");
+        gtk_box_pack_start(GTK_BOX(box2), label, WID_DYN);
+        gtk_widget_set_halign(label, GTK_ALIGN_END);
+        gtk_widget_show(label);
+
+        gtk_widget_show(box2);
+        gtk_widget_show(box);
+        gtk_widget_show(iwid);
+
+        gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
+        gtk_widget_show(window);
+    } else {
+        box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
+        add_about_wid_fix(iwid);
+
+        sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
+        add_about_wid_fix(sep);
+
+        label = gtk_label_new("This is " PACKAGE " release " VERSION ".\nCopyright (C) 1999-2021 by Alexander König <alex@lisas.de>");
+
+        gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
+        add_about_wid_fix(label);
+
+        sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
+        add_about_wid_fix(sep);
+
+        expander = gtk_expander_new("Build info");
+        GtkWidget* exbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
+        gtk_container_add(GTK_CONTAINER(expander), exbox);
+        gtk_widget_show(exbox);
+
+        label = gtk_label_new("Compilation flags: "
 #ifdef USE_SOX_INPUT
-               " [sox]"
+                              " [sox]"
 #endif
 #ifdef USE_MPG123_INPUT
-               " [mpg123]"
+                              " [mpg123]"
 #endif
 #ifdef USE_OGG123_INPUT
-               " [ogg123]"
+                              " [ogg123]"
 #endif
 #ifdef USE_MAD_INPUT
-               " [mad]"
+                              " [mad]"
 #endif
 #ifdef USE_VORBIS_INPUT
-               " [vorbis]"
+                              " [vorbis]"
 #endif
 #ifdef USE_AUDIOFILE_INPUT
-               " [audiofile]"
+                              " [audiofile]"
 #endif
-               "\n"
+                              "\n"
 #ifdef USE_ALSA_MIDI_IN
-               " [midi]"
+                              " [midi]"
 #endif
 #ifdef USE_OSS
-               " [oss]"
+                              " [oss]"
 #endif
 #ifdef USE_ALSA
-               " [alsa]"
+                              " [alsa]"
 #endif
 #ifdef USE_JACK
-               " [jack]"
+                              " [jack]"
 #endif
 #ifdef USE_PULSE
-               " [pulse]"
+                              " [pulse]"
 #endif
 #ifdef USE_LRDF
-               " [lrdf]"
+                              " [lrdf]"
 #endif
 #ifdef USE_SCHEDULER
-               " [rt]"
+                              " [rt]"
 #endif
 #ifdef USE_CAPABILITIES
-               " [cap]"
+                              " [cap]"
 #endif
-               "");
-       
-               gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
-               gtk_widget_set_size_request(label, 640, -1);
-               gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
-               gtk_container_add(GTK_CONTAINER(exbox), label);
-               gtk_widget_show(label);
-               add_about_wid_fix(expander);
-
-#ifdef         USE_SCHEDULER
-               sep=gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
-               gtk_widget_show(sep);
-               gtk_container_add(GTK_CONTAINER(exbox), sep);
-
-               char buffer[4096];
-               
-               int policy=-1;
-               struct sched_param parm;
-               
-               pthread_getschedparam(tX_engine::get_instance()->get_thread_id(), &policy, &parm);
-               char prio_str[32]="";
-               bool s_enabled = false;
-               
-               switch (policy) {
-                       case SCHED_OTHER:
-                               strcpy(prio_str, "SCHED_OTHER");
-                               break;
-                       
-                       case SCHED_RR:
-                               strcpy(prio_str, "SCHED_RR");
-                               break;
-                       
-                       case SCHED_FIFO:
-                               strcpy(prio_str, "SCHED_FIFO");
-                               s_enabled = true;
-                               break;
-                       
-                       default:
-                               sprintf(prio_str, "UNKNOWN (%i)", policy);
-               }
-               
-               sprintf(buffer, "Audio engine scheduling policy: %s.\nScheduling with realtime priority is %s.", prio_str, s_enabled ? "enabled" : "disabled");
-
-               label=gtk_label_new(buffer);
-
-               gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
-               gtk_widget_show(label);
-               gtk_container_add(GTK_CONTAINER(exbox), label);
+                              "");
+
+        gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
+        gtk_widget_set_size_request(label, 640, -1);
+        gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
+        gtk_container_add(GTK_CONTAINER(exbox), label);
+        gtk_widget_show(label);
+        add_about_wid_fix(expander);
+
+#ifdef USE_SCHEDULER
+        sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
+        gtk_widget_show(sep);
+        gtk_container_add(GTK_CONTAINER(exbox), sep);
+
+        char buffer[4096];
+
+        int policy = -1;
+        struct sched_param parm;
+
+        pthread_getschedparam(tX_engine::get_instance()->get_thread_id(), &policy, &parm);
+        char prio_str[32] = "";
+        bool s_enabled = false;
+
+        switch (policy) {
+        case SCHED_OTHER:
+            strcpy(prio_str, "SCHED_OTHER");
+            break;
+
+        case SCHED_RR:
+            strcpy(prio_str, "SCHED_RR");
+            break;
+
+        case SCHED_FIFO:
+            strcpy(prio_str, "SCHED_FIFO");
+            s_enabled = true;
+            break;
+
+        default:
+            sprintf(prio_str, "UNKNOWN (%i)", policy);
+        }
+
+        sprintf(buffer, "Audio engine scheduling policy: %s.\nScheduling with realtime priority is %s.", prio_str, s_enabled ? "enabled" : "disabled");
+
+        label = gtk_label_new(buffer);
+
+        gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
+        gtk_widget_show(label);
+        gtk_container_add(GTK_CONTAINER(exbox), label);
 #endif
 
-               sep=gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
-               add_about_wid_fix(sep);
-
-               expander = gtk_expander_new("License (GPL V2):");
-
-               add_about_wid_fix(expander);
-
-               GtkTextIter iter;
-               GtkTextBuffer *tbuffer;
-
-               text=gtk_text_view_new();
-               tbuffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
-               gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_NONE);
-               gtk_text_view_set_editable(GTK_TEXT_VIEW(text), false);
-               gtk_text_buffer_get_iter_at_offset (tbuffer, &iter, 0);
-               
-               scroll=gtk_scrolled_window_new (NULL, NULL);
-        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
-               gtk_container_add (GTK_CONTAINER (scroll), text);
-               gtk_text_buffer_create_tag (tbuffer, "courier", "family", "courier", NULL);
-               
-               gtk_text_buffer_insert_with_tags_by_name(tbuffer, &iter, license, -1, "courier", NULL);
-               gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 5);
-               gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 5);
-               gtk_widget_set_size_request(GTK_WIDGET(scroll), 640, 200);
-               gtk_widget_show(text);          
-               
-               gtk_container_add(GTK_CONTAINER(expander), scroll);
-               gtk_widget_show(scroll);                
-               
-               sep=gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
-               add_about_wid_fix(sep);
-
-               btn=gtk_button_new_with_label("Close");
-               add_about_wid_fix(btn);
-
-               gtk_container_add(GTK_CONTAINER(window), box);
-               gtk_widget_show(box);
-               
-               g_signal_connect(G_OBJECT(btn), "clicked", (GCallback) destroy_about, NULL);            
-               g_signal_connect(G_OBJECT(window), "delete-event", (GCallback) destroy_about, NULL);            
-       }
-       gtk_widget_show(window);        
-       tX_set_icon(window);
-       
-       while (gtk_events_pending()) gtk_main_iteration();
-               
-       about=window;
+        sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
+        add_about_wid_fix(sep);
+
+        expander = gtk_expander_new("License (GPL V2):");
+
+        add_about_wid_fix(expander);
+
+        GtkTextIter iter;
+        GtkTextBuffer* tbuffer;
+
+        text = gtk_text_view_new();
+        tbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
+        gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_NONE);
+        gtk_text_view_set_editable(GTK_TEXT_VIEW(text), false);
+        gtk_text_buffer_get_iter_at_offset(tbuffer, &iter, 0);
+
+        scroll = gtk_scrolled_window_new(NULL, NULL);
+        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+        gtk_container_add(GTK_CONTAINER(scroll), text);
+        gtk_text_buffer_create_tag(tbuffer, "courier", "family", "courier", NULL);
+
+        gtk_text_buffer_insert_with_tags_by_name(tbuffer, &iter, license, -1, "courier", NULL);
+        gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 5);
+        gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 5);
+        gtk_widget_set_size_request(GTK_WIDGET(scroll), 640, 200);
+        gtk_widget_show(text);
+
+        gtk_container_add(GTK_CONTAINER(expander), scroll);
+        gtk_widget_show(scroll);
+
+        sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
+        add_about_wid_fix(sep);
+
+        btn = gtk_button_new_with_label("Close");
+        add_about_wid_fix(btn);
+
+        gtk_container_add(GTK_CONTAINER(window), box);
+        gtk_widget_show(box);
+
+        g_signal_connect(G_OBJECT(btn), "clicked", (GCallback)destroy_about, NULL);
+        g_signal_connect(G_OBJECT(window), "delete-event", (GCallback)destroy_about, NULL);
+    }
+    gtk_widget_show(window);
+    tX_set_icon(window);
+
+    while (gtk_events_pending())
+        gtk_main_iteration();
+
+    about = window;
 }
 
-static GdkPixbuf *tX_window_icon=NULL;
-
-void tX_set_icon(GtkWidget *widget)
-{      
-       if (!tX_window_icon) {
-               GError *error = NULL;
-               g_resource_new_from_data(g_bytes_new_static(tX_dialog_resource_data.data, sizeof(tX_dialog_resource_data.data)), &error);
-               if (error) {
-                   tX_error("Error accesing tX_dialog resources: %s", error->message);
-               }
-               tX_window_icon=gdk_pixbuf_new_from_resource("/org/terminatorX/tX_dialog/../../icons/terminatorX.png", &error);
-               if (error) {
-                   tX_error("Error rendering tX icon: %s", error->message);
-               }
-       }
-
-       gtk_window_set_icon(GTK_WINDOW(widget), tX_window_icon);
+static GdkPixbuf* tX_window_icon = NULL;
+
+void tX_set_icon(GtkWidget* widget) {
+    if (!tX_window_icon) {
+        GError* error = NULL;
+        g_resource_new_from_data(g_bytes_new_static(tX_dialog_resource_data.data, sizeof(tX_dialog_resource_data.data)), &error);
+        if (error) {
+            tX_error("Error accesing tX_dialog resources: %s", error->message);
+        }
+        tX_window_icon = gdk_pixbuf_new_from_resource("/org/terminatorX/tX_dialog/../../icons/terminatorX.png", &error);
+        if (error) {
+            tX_error("Error rendering tX icon: %s", error->message);
+        }
+    }
+
+    gtk_window_set_icon(GTK_WINDOW(widget), tX_window_icon);
 }
index 05d8c39f57deff94dfd7ecc31635f2738c4d32fd..9dc06619ad3bcdc73ee0588124caa617be57aa1c 100644 (file)
@@ -1,35 +1,35 @@
 /*
     terminatorX - realtime audio scratching software
     Copyright (C) 1999-2021  Alexander König
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
+
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
+
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
     File: tX_dialog.h
+
     Description: Header to tX_dialog.c
-*/    
+*/
 
 #ifndef _H_TX_DIALOG_
 #define _H_TX_DIALOG_
 //#include <gdk/gdk.h>
 #include <gtk/gtk.h>
-extern GtkWidget *opt_dialog;
+extern GtkWidgetopt_dialog;
 
 extern void display_options();
 extern void show_about(int nag);
 extern void destroy_about();
-extern void init_tx_options(GtkWidget *dialog);
-extern void tX_set_icon(GtkWidget *widget);
-extern void apply_options(GtkWidget *);
+extern void init_tx_options(GtkWidgetdialog);
+extern void tX_set_icon(GtkWidgetwidget);
+extern void apply_options(GtkWidget*);
 #endif
index 9cdfd925ba2ec7d99496aa8e53fea4a59a9eacc4..8503e9b547d27f413a28301e6661fba3a36c18ee 100644 (file)
@@ -1,52 +1,52 @@
 /*
     terminatorX - realtime audio scratching software
     Copyright (C) 1999-2021  Alexander König
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
+
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
+
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
     File: tX_endian.c
+
     Description: swap byte order for big endian systems/audiohardware.
-*/    
+*/
 
 #include "tX_endian.h"
 #include "tX_global.h"
 
 #ifdef WORDS_BIGENDIAN
 
-void swap16(int16_t * val) {
-       int8_t temp;
-       int8_t *p;
-       
-       p=(int8_t *) val;
-       temp=p[0];
-       p[0]=p[1];
-       p[1]=temp;
+void swap16(int16_t* val) {
+    int8_t temp;
+    int8_t* p;
+
+    p = (int8_t*)val;
+    temp = p[0];
+    p[0] = p[1];
+    p[1] = temp;
 }
 
-void swap32(int32_t * val) {
-       int8_t temp;
-       int8_t *p;
-       
-       p=(int8_t *) val;
-       temp=p[0];
-       p[0]=p[3];
-       p[3]=temp;
-       
-       temp=p[1];
-       p[1]=p[2];
-       p[2]=temp;
+void swap32(int32_t* val) {
+    int8_t temp;
+    int8_t* p;
+
+    p = (int8_t*)val;
+    temp = p[0];
+    p[0] = p[3];
+    p[3] = temp;
+
+    temp = p[1];
+    p[1] = p[2];
+    p[2] = temp;
 }
 
 #endif
index 4d20be00e5dee873b5aa92f6aec48f437e111511..d09209604018f27c17cc8c73e4df53c501c19aa3 100644 (file)
@@ -1,65 +1,65 @@
 /*
     terminatorX - realtime audio scratching software
     Copyright (C) 1999-2021  Alexander König
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
+
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
+
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
     File: tX_endian.h
+
     Description: header to tX_endian.c
-*/    
+*/
 
 #ifndef _H_TX_ENDIAN_
 #define _H_TX_ENDIAN_
 
 #ifdef HAVE_CONFIG_H
-#      include <config.h>
-#      ifdef WORDS_BIGENDIAN
-#              define BIG_ENDIAN_MACHINE 1
-#      else
-#              undef BIG_ENDIAN_MACHINE
-#      endif
+#include <config.h>
+#ifdef WORDS_BIGENDIAN
+#define BIG_ENDIAN_MACHINE 1
+#else
+#undef BIG_ENDIAN_MACHINE
+#endif
 #endif
 
 #ifdef WORDS_BIGENDIAN
-#      include "tX_types.h"
-#      include <unistd.h>
-#define swapbuffer(b, s) swab((void *) b, (void *) b, (ssize_t) s<<1)
-
-static inline void swap32_inline(int32_t *val) {
-       int8_t temp;
-       int8_t *p=(int8_t *) val;
-       
-       temp=p[0];
-       p[0]=p[3];
-       p[3]=temp;
-       
-       temp=p[1];
-       p[1]=p[2];
-       p[2]=temp;      
+#include "tX_types.h"
+#include <unistd.h>
+#define swapbuffer(b, s) swab((void*)b, (void*)b, (ssize_t)s << 1)
+
+static inline void swap32_inline(int32_tval) {
+    int8_t temp;
+    int8_t* p = (int8_t*)val;
+
+    temp = p[0];
+    p[0] = p[3];
+    p[3] = temp;
+
+    temp = p[1];
+    p[1] = p[2];
+    p[2] = temp;
 }
 
-#      ifdef __cplusplus
+#ifdef __cplusplus
 extern "C" {
-#      endif /* __cplusplus */
+#endif /* __cplusplus */
+
+extern void swap16(int16_t* val);
+extern void swap32(int32_t* val);
 
-extern void swap16(int16_t * val);
-extern void swap32(int32_t * val);
-       
-#      ifdef __cplusplus
+#ifdef __cplusplus
 }
-#      endif /* __cplusplus */
+#endif /* __cplusplus */
 
 #endif /* WORDS_BIGENDIAN */
 
index c29b34d42313ee21886e18c35573b230df33e4a3..9db4b7516675e73834cfeb4f1cf01abebec9c22c 100644 (file)
 /*
     terminatorX - realtime audio scratching software
     Copyright (C) 1999-2021  Alexander König
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
+
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
+
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
     File: tX_engine.c
+
     Description: Contains the code that does the real "Scratching
-                business": XInput, DGA, Mouse and Keyboardgrabbing
+                business": XInput, DGA, Mouse and Keyboardgrabbing
                 etc.
-*/    
+*/
 
-#include <config.h>
-#include "tX_types.h"
 #include "tX_engine.h"
 #include "tX_audiodevice.h"
-#include "tX_mouse.h"
-#include "tX_vtt.h"
-#include <pthread.h>
-#include <gtk/gtk.h>
-#include <gdk/gdkprivate.h>
-#include "tX_maingui.h"
+#include "tX_capabilities.h"
 #include "tX_global.h"
+#include "tX_maingui.h"
+#include "tX_mouse.h"
+#include "tX_sequencer.h"
 #include "tX_tape.h"
+#include "tX_types.h"
+#include "tX_vtt.h"
 #include "tX_widget.h"
 #include <config.h>
-#include "tX_sequencer.h"
 #include <errno.h>
+#include <gdk/gdkprivate.h>
+#include <gtk/gtk.h>
+#include <pthread.h>
 #include <sched.h>
-#include "tX_capabilities.h"
 
-#include <sys/time.h>
 #include <sys/resource.h>
+#include <sys/time.h>
+
+tX_engine* tX_engine::engine = NULL;
 
-tX_engine *tX_engine::engine=NULL;
+tX_engine* tX_engine::get_instance() {
+    if (!engine) {
+        engine = new tX_engine();
+    }
 
-tX_engine *tX_engine::get_instance() {
-       if (!engine) {
-               engine=new tX_engine();
-       }
-       
-       return engine;
+    return engine;
 }
 
 int16_t* tX_engine::render_cycle() {
-       /* Forward the sequencer... */
-       sequencer.step();
-
-       /* Render the next block... */
-       int16_t *data=vtt_class::render_all_turntables();
-       
-       /* Record the audio if necessary... */
-       if (is_recording()) tape->eat(data);
-       
-       return  data;
+    /* Forward the sequencer... */
+    sequencer.step();
+
+    /* Render the next block... */
+    int16_t* data = vtt_class::render_all_turntables();
+
+    /* Record the audio if necessary... */
+    if (is_recording())
+        tape->eat(data);
+
+    return data;
 }
 
 void tX_engine::loop() {
-       while (!thread_terminate) {
-               /* Waiting for the trigger */
-               pthread_mutex_lock(&start);
-               reset_cycles_ctr();
-               
+    while (!thread_terminate) {
+        /* Waiting for the trigger */
+        pthread_mutex_lock(&start);
+        reset_cycles_ctr();
+
 #ifdef USE_SCHEDULER
-               pid_t pid=getpid();
-               struct sched_param parm;
-                       
-               if (globals.use_realtime && (globals.audiodevice_type!=JACK)) {
-                       sched_getparam(pid, &parm);
-                       parm.sched_priority=sched_get_priority_max(SCHED_FIFO);
-                                               
-                       if (pthread_setschedparam(pthread_self(), SCHED_FIFO, &parm)) {
-                               tX_msg("loop(): failed to set realtime priority.");
-                       } else {
-                               tX_debug("loop(): set SCHED_FIFO.");
-                       }
-               } else {
-                       sched_getparam(pid, &parm);
-                       parm.sched_priority=sched_get_priority_max(SCHED_OTHER);
-                                               
-                       if (pthread_setschedparam(pthread_self(), SCHED_OTHER, &parm)) {
-                               tX_msg("loop(): failed to set non-realtime priority.");
-                       } else {
-                               tX_debug("loop(): set SCHED_OTHER.");
-                       }                       
-               }
-#endif         
-               loop_is_active=true;
-               pthread_mutex_unlock(&start);
-
-               if (!stop_flag) device->start(); // Hand flow control over to the device
-
-               // in case we got kicked out by jack we might have
-               // to kill the mouse grab
-/*             if (grab_active) {
+        pid_t pid = getpid();
+        struct sched_param parm;
+
+        if (globals.use_realtime && (globals.audiodevice_type != JACK)) {
+            sched_getparam(pid, &parm);
+            parm.sched_priority = sched_get_priority_max(SCHED_FIFO);
+
+            if (pthread_setschedparam(pthread_self(), SCHED_FIFO, &parm)) {
+                tX_msg("loop(): failed to set realtime priority.");
+            } else {
+                tX_debug("loop(): set SCHED_FIFO.");
+            }
+        } else {
+            sched_getparam(pid, &parm);
+            parm.sched_priority = sched_get_priority_max(SCHED_OTHER);
+
+            if (pthread_setschedparam(pthread_self(), SCHED_OTHER, &parm)) {
+                tX_msg("loop(): failed to set non-realtime priority.");
+            } else {
+                tX_debug("loop(): set SCHED_OTHER.");
+            }
+        }
+#endif
+        loop_is_active = true;
+        pthread_mutex_unlock(&start);
+
+        if (!stop_flag)
+            device->start(); // Hand flow control over to the device
+
+        // in case we got kicked out by jack we might have
+        // to kill the mouse grab
+        /*             if (grab_active) {
                        mouse->ungrab();
                        grab_active=false;
                        grab_off();
                } */
 
-               if (!stop_flag) {
-                       runtime_error=true;
-                       usleep(100);
-               }
-               /* Stopping engine... */
-               loop_is_active=false;
-       }
+        if (!stop_flag) {
+            runtime_error = true;
+            usleep(100);
+        }
+        /* Stopping engine... */
+        loop_is_active = false;
+    }
 }
 
-void *engine_thread_entry(void *engine_void) {
-       tX_engine *engine=(tX_engine*) engine_void;
-       
+void* engine_thread_entry(void* engine_void) {
+    tX_engine* engine = (tX_engine*)engine_void;
+
 #ifdef USE_SCHEDULER
-       pid_t pid=getpid();
-       struct sched_param parm;
-
-       if (globals.use_realtime) {
-               sched_getparam(pid, &parm);
-               parm.sched_priority=sched_get_priority_max(SCHED_FIFO);
-                                       
-               if (pthread_setschedparam(pthread_self(), SCHED_FIFO, &parm)) {
-                       // we failed to get max prio, let see whether we can get a little less
-                       bool success = false;
-                       
-                       for (int i = parm.__sched_priority; i >= sched_get_priority_min(SCHED_FIFO); i--) {
-                               parm.__sched_priority = i;
-                               
-                               if (!pthread_setschedparam(pthread_self(), SCHED_FIFO, &parm)) {
-                                       success = true;
-                                       break;
-                               }
-                       }
-                       
-                       if (success) {
-                               tX_msg("engine_thread_entry(): set SCHED_FIFO with priority %i.", parm.__sched_priority);
-                       } else {
-                               tX_warning("engine_thread_entry(): failed to set realtime priority.");
-                       }
-               } else {
-                       tX_debug("engine_thread_entry(): set SCHED_FIFO with maximum priority.");
-               }
-       }
+    pid_t pid = getpid();
+    struct sched_param parm;
+
+    if (globals.use_realtime) {
+        sched_getparam(pid, &parm);
+        parm.sched_priority = sched_get_priority_max(SCHED_FIFO);
+
+        if (pthread_setschedparam(pthread_self(), SCHED_FIFO, &parm)) {
+            // we failed to get max prio, let see whether we can get a little less
+            bool success = false;
+
+            for (int i = parm.__sched_priority; i >= sched_get_priority_min(SCHED_FIFO); i--) {
+                parm.__sched_priority = i;
+
+                if (!pthread_setschedparam(pthread_self(), SCHED_FIFO, &parm)) {
+                    success = true;
+                    break;
+                }
+            }
+
+            if (success) {
+                tX_msg("engine_thread_entry(): set SCHED_FIFO with priority %i.", parm.__sched_priority);
+            } else {
+                tX_warning("engine_thread_entry(): failed to set realtime priority.");
+            }
+        } else {
+            tX_debug("engine_thread_entry(): set SCHED_FIFO with maximum priority.");
+        }
+    }
 #endif //USE_SCHEDULER
-               
+
 #ifdef USE_JACK
-       /* Create the client now, so the user has something to connect to. */
-       tX_jack_client::get_instance();
-#endif 
-       
-       engine->loop();
-       tX_debug("engine_thread_entry() engine thread terminating.");
-       pthread_exit(NULL);
+    /* Create the client now, so the user has something to connect to. */
+    tX_jack_client::get_instance();
+#endif
+
+    engine->loop();
+    tX_debug("engine_thread_entry() engine thread terminating.");
+    pthread_exit(NULL);
 }
 
-tX_engine :: tX_engine() {
-       int result;
-       
-       pthread_mutex_init(&start, NULL);
-       pthread_mutex_lock(&start);
-       thread_terminate=false;
-       
-       result=pthread_create(&thread, NULL, engine_thread_entry, (void *) this);
-       
-       if (result!=0) {
-               tX_error("tX_engine() - Failed to create engine thread. Errno is %i.", errno);
-               exit(1);
-       }
-       
-#ifdef USE_ALSA_MIDI_IN        
-       midi=new tX_midiin();
-#endif 
-       tape=new tx_tapedeck();
-
-       device=NULL;
-       recording=false;
-       recording_request=false;
-       loop_is_active=false;
+tX_engine ::tX_engine() {
+    int result;
+
+    pthread_mutex_init(&start, NULL);
+    pthread_mutex_lock(&start);
+    thread_terminate = false;
+
+    result = pthread_create(&thread, NULL, engine_thread_entry, (void*)this);
+
+    if (result != 0) {
+        tX_error("tX_engine() - Failed to create engine thread. Errno is %i.", errno);
+        exit(1);
+    }
+
+#ifdef USE_ALSA_MIDI_IN
+    midi = new tX_midiin();
+#endif
+    tape = new tx_tapedeck();
+
+    device = NULL;
+    recording = false;
+    recording_request = false;
+    loop_is_active = false;
 }
 
-void tX_engine :: set_recording_request (bool recording) {
-       this->recording_request=recording;
+void tX_engine ::set_recording_request(bool recording) {
+    this->recording_request = recording;
 }
 
-tX_engine_error tX_engine :: run() {
-       list <vtt_class *> :: iterator vtt;
-       
-       runtime_error=false;
-       overload_error=false;
-       
-       if (loop_is_active) return ERROR_BUSY;
-       
-       switch (globals.audiodevice_type) {
-#ifdef USE_OSS 
-               case OSS:
-                       device=new tX_audiodevice_oss(); 
-                       break;
-#endif                 
-
-#ifdef USE_ALSA                        
-               case ALSA:
-                       device=new tX_audiodevice_alsa(); 
-                       break;
+tX_engine_error tX_engine ::run() {
+    list<vtt_class*>::iterator vtt;
+
+    runtime_error = false;
+    overload_error = false;
+
+    if (loop_is_active)
+        return ERROR_BUSY;
+
+    switch (globals.audiodevice_type) {
+#ifdef USE_OSS
+    case OSS:
+        device = new tX_audiodevice_oss();
+        break;
+#endif
+
+#ifdef USE_ALSA
+    case ALSA:
+        device = new tX_audiodevice_alsa();
+        break;
 #endif
 
 #ifdef USE_JACK
-               case JACK:
-                       device=new tX_audiodevice_jack();
-                       break;
+    case JACK:
+        device = new tX_audiodevice_jack();
+        break;
 #endif
 
 #ifdef USE_PULSE
-               case PULSE:
-                       device=new tX_audiodevice_pulse();
-                       break;
+    case PULSE:
+        device = new tX_audiodevice_pulse();
+        break;
 #endif
-               
-               default:
-                       device=NULL; return ERROR_BACKEND;
-       }
-       
-       if (device->open()) {
-               if (device->get_is_open()) device->close();
-               delete device;
-               device=NULL;            
-               return ERROR_AUDIO;
-       }       
-
-       vtt_class::set_sample_rate(device->get_sample_rate());
-       
-       if (recording_request) {
-               if (tape->start_record(globals.record_filename, vtt_class::get_mix_buffer_size(), device->get_sample_rate())) {
-                       device->close();
-                       delete device;
-                       device=NULL;                    
-                       return ERROR_TAPE;                      
-               } else {
-                       recording=true;
-               }
-       }
-       
-       for (vtt=vtt_class::main_list.begin(); vtt!=vtt_class::main_list.end(); vtt++) {
-               (*vtt)->sync_countdown=0;
-               if ((*vtt)->autotrigger) (*vtt)->trigger();
-       }
-
-       sequencer.forward_to_start_timestamp(1);        
-       stop_flag=false;
-       /* Trigger the engine thread... */
-       pthread_mutex_unlock(&start);
-       
-       return NO_ERROR;
+
+    default:
+        device = NULL;
+        return ERROR_BACKEND;
+    }
+
+    if (device->open()) {
+        if (device->get_is_open())
+            device->close();
+        delete device;
+        device = NULL;
+        return ERROR_AUDIO;
+    }
+
+    vtt_class::set_sample_rate(device->get_sample_rate());
+
+    if (recording_request) {
+        if (tape->start_record(globals.record_filename, vtt_class::get_mix_buffer_size(), device->get_sample_rate())) {
+            device->close();
+            delete device;
+            device = NULL;
+            return ERROR_TAPE;
+        } else {
+            recording = true;
+        }
+    }
+
+    for (vtt = vtt_class::main_list.begin(); vtt != vtt_class::main_list.end(); vtt++) {
+        (*vtt)->sync_countdown = 0;
+        if ((*vtt)->autotrigger)
+            (*vtt)->trigger();
+    }
+
+    sequencer.forward_to_start_timestamp(1);
+    stop_flag = false;
+    /* Trigger the engine thread... */
+    pthread_mutex_unlock(&start);
+
+    return NO_ERROR;
 }
 
-void tX_engine :: stop() {
-       list <vtt_class *> :: iterator vtt;
-       
-       if (!loop_is_active) {
-               tX_error("tX_engine::stop() - but loop's not running?");
-       }
-       
-       pthread_mutex_lock(&start);
-       stop_flag=true;
-       
-       tX_debug("tX_engine::stop() - waiting for loop to stop.");
-       
-       while (loop_is_active) {
-               /* Due to gtk+ signal handling this can cause a deadlock
+void tX_engine ::stop() {
+    list<vtt_class*>::iterator vtt;
+
+    if (!loop_is_active) {
+        tX_error("tX_engine::stop() - but loop's not running?");
+    }
+
+    pthread_mutex_lock(&start);
+    stop_flag = true;
+
+    tX_debug("tX_engine::stop() - waiting for loop to stop.");
+
+    while (loop_is_active) {
+        /* Due to gtk+ signal handling this can cause a deadlock
                   on the seqpars' update list. So we need to handle events
                   while waiting...                     
                */
-               while (gtk_events_pending()) gtk_main_iteration();
-               usleep(50);
-       }
-       
-       tX_debug("tX_engine::stop() - loop has stopped.");
-
-       if (device->get_is_open()) device->close();
-       delete device;
-       device=NULL;
-       
-       for (vtt=vtt_class::main_list.begin(); vtt!=vtt_class::main_list.end(); vtt++) {
-               (*vtt)->stop();
-               (*vtt)->ec_clear_buffer();
-       }
-       
-       if (is_recording()) tape->stop_record();
-       recording=false;
+        while (gtk_events_pending())
+            gtk_main_iteration();
+        usleep(50);
+    }
+
+    tX_debug("tX_engine::stop() - loop has stopped.");
+
+    if (device->get_is_open())
+        device->close();
+    delete device;
+    device = NULL;
+
+    for (vtt = vtt_class::main_list.begin(); vtt != vtt_class::main_list.end(); vtt++) {
+        (*vtt)->stop();
+        (*vtt)->ec_clear_buffer();
+    }
+
+    if (is_recording())
+        tape->stop_record();
+    recording = false;
 }
 
-tX_engine :: ~tX_engine() {
-       void *dummy;
-               
-       thread_terminate=true;
-       stop_flag=true;
-       pthread_mutex_unlock(&start);
-       tX_debug("~tX_engine() - Waiting for engine thread to terminate.");
-       pthread_join(thread, &dummy);   
-       
-#ifdef USE_ALSA_MIDI_IN                
-       delete midi;
-#endif 
-       delete tape;    
+tX_engine ::~tX_engine() {
+    void* dummy;
+
+    thread_terminate = true;
+    stop_flag = true;
+    pthread_mutex_unlock(&start);
+    tX_debug("~tX_engine() - Waiting for engine thread to terminate.");
+    pthread_join(thread, &dummy);
+
+#ifdef USE_ALSA_MIDI_IN
+    delete midi;
+#endif
+    delete tape;
 }
index d8ba407b35b97ec03a8ea3a2bf8711a5ecdf8834..7dec9cc40a32b1d13bc9598e93d3ba1df0dd83e3 100644 (file)
@@ -1,31 +1,31 @@
 /*
     terminatorX - realtime audio scratching software
     Copyright (C) 1999-2021  Alexander König
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
+
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
+
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
     File: tX_engine.h
+
     Description: Header to tX_engine.cc
-*/    
+*/
 
 #ifndef _TX_ENGINE_H_
 #define _TX_ENGINE_H_
 
-#include "tX_tape.h"
 #include "tX_audiodevice.h"
 #include "tX_midiin.h"
+#include "tX_tape.h"
 #include <sys/types.h>
 
 #define ENG_ERR 4
 
 #include <pthread.h>
 enum tX_engine_error {
-       NO_ERROR,
-       ERROR_TAPE,
-       ERROR_AUDIO,
-       ERROR_BACKEND,
-       ERROR_BUSY      
+    NO_ERROR,
+    ERROR_TAPE,
+    ERROR_AUDIO,
+    ERROR_BACKEND,
+    ERROR_BUSY
 };
 
 enum tX_engine_status {
-       RUNNING,
-       STOPPED
+    RUNNING,
+    STOPPED
 };
 
 class tX_engine {
-       private:
-       static tX_engine *engine;
-       
-       pthread_t thread;
-       pthread_mutex_t start;
-       bool thread_terminate;
-       tX_audiodevice *device;
-       tx_tapedeck *tape;
-       bool recording;
-       bool recording_request;
-       bool stop_flag;
-       bool loop_is_active;
-/*     bool grab_request;
+  private:
+    static tX_engine* engine;
+
+    pthread_t thread;
+    pthread_mutex_t start;
+    bool thread_terminate;
+    tX_audiodevice* device;
+    tx_tapedeck* tape;
+    bool recording;
+    bool recording_request;
+    bool stop_flag;
+    bool loop_is_active;
+    /* bool grab_request;
        bool grab_active; */
-       bool runtime_error;
-       bool overload_error;
-       int cycles_ctr;
-       
+    bool runtime_error;
+    bool overload_error;
+    int cycles_ctr;
+
 #ifdef USE_ALSA_MIDI_IN
-       private: tX_midiin *midi;
-       public: tX_midiin *get_midi() { return midi; }
-#endif 
-       public:
-
-       pthread_t get_thread_id() { return thread; }
-       bool check_error() { return runtime_error || overload_error; }
-       bool get_runtime_error() { return runtime_error; }
-       bool get_overload_error() { return overload_error; }
-       void reset_cycles_ctr() { /*tX_msg("cycles reset at %i.", cycles_ctr);*/ cycles_ctr=0; } // locking?
-       static tX_engine *get_instance();
-       tX_engine();
-       ~tX_engine();
-       
-       tX_engine_error run();
-       void stop();
-       void loop();
-       
-       void set_recording_request(bool recording);
-       bool get_recording_request() { return recording_request; }
-       bool is_recording() { return recording; }
-       int16_t* render_cycle();
-       
-/*     void set_grab_request(); */
-       bool is_stopped() { return stop_flag; }
+  private:
+    tX_midiin* midi;
+
+  public:
+    tX_midiin* get_midi() { return midi; }
+#endif
+  public:
+    pthread_t get_thread_id() { return thread; }
+    bool check_error() { return runtime_error || overload_error; }
+    bool get_runtime_error() { return runtime_error; }
+    bool get_overload_error() { return overload_error; }
+    void reset_cycles_ctr() { /*tX_msg("cycles reset at %i.", cycles_ctr);*/
+        cycles_ctr = 0;
+    } // locking?
+    static tX_engine* get_instance();
+    tX_engine();
+    ~tX_engine();
+
+    tX_engine_error run();
+    void stop();
+    void loop();
+
+    void set_recording_request(bool recording);
+    bool get_recording_request() { return recording_request; }
+    bool is_recording() { return recording; }
+    int16_t* render_cycle();
+
+    /* void set_grab_request(); */
+    bool is_stopped() { return stop_flag; }
 };
 #endif
index 290c91fa2ed26ec8d39d54d3b812ee00407400f6..1d0148b1e3d88434773a37ae4f12f1e0edd8def5 100644 (file)
@@ -1,56 +1,59 @@
 /*
     terminatorX - realtime audio scratching software
     Copyright (C) 1999-2021  Alexander König
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
+
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
+
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
     File: tX_event.cc
+
     Description: This implements the sequencer events.
-*/ 
+*/
 
 #include <tX_event.h>
 #include <tX_global.h>
 
-void tX_event :: store (FILE *rc, gzFile rz, char *indent) {
-       tX_store("%s<event pid=\"%i\" value=\"%lf\" time=\"%i\"/>\n", indent, sp->get_persistence_id(), value, timestamp);
+void tX_event ::store(FILE* rc, gzFile rz, char* indent) {
+    tX_store("%s<event pid=\"%i\" value=\"%lf\" time=\"%i\"/>\n", indent, sp->get_persistence_id(), value, timestamp);
 }
 
-tX_event* tX_event :: load_event (xmlDocPtr doc, xmlNodePtr node) {
-       unsigned int sp_persistence_id;
-       char *buffer;
-       float value;
-       guint32 timestamp;
-       tX_event *event=NULL;
-       tX_seqpar *sp=NULL;
-       
-       buffer=(char *) xmlGetProp(node, (xmlChar *) "pid");
-       if (buffer) sscanf(buffer, "%i", &sp_persistence_id);
-       
-       buffer=(char *) xmlGetProp(node, (xmlChar *) "value");
-       if (buffer) sscanf(buffer, "%f", &value);
-       
-       buffer=(char *) xmlGetProp(node, (xmlChar *) "time");
-       if (buffer) sscanf(buffer, "%i", &timestamp);
-
-       sp=tX_seqpar::get_sp_by_persistence_id(sp_persistence_id);
-       
-       if (sp) {
-               event=new tX_event(timestamp, sp, value);
-       } else {
-               tX_error("failed to resolve event at %i - pid [%i]. Event lost.", timestamp, sp_persistence_id);
-       }
-       
-       return event;
+tX_event* tX_event ::load_event(xmlDocPtr doc, xmlNodePtr node) {
+    unsigned int sp_persistence_id;
+    char* buffer;
+    float value;
+    guint32 timestamp;
+    tX_event* event = NULL;
+    tX_seqpar* sp = NULL;
+
+    buffer = (char*)xmlGetProp(node, (xmlChar*)"pid");
+    if (buffer)
+        sscanf(buffer, "%i", &sp_persistence_id);
+
+    buffer = (char*)xmlGetProp(node, (xmlChar*)"value");
+    if (buffer)
+        sscanf(buffer, "%f", &value);
+
+    buffer = (char*)xmlGetProp(node, (xmlChar*)"time");
+    if (buffer)
+        sscanf(buffer, "%i", &timestamp);
+
+    sp = tX_seqpar::get_sp_by_persistence_id(sp_persistence_id);
+
+    if (sp) {
+        event = new tX_event(timestamp, sp, value);
+    } else {
+        tX_error("failed to resolve event at %i - pid [%i]. Event lost.", timestamp, sp_persistence_id);
+    }
+
+    return event;
 }
index 0f047f8b6de25ef846438cac91e83ea592de54d2..85c3e1c9e861ce636fe9eb8d52828c8059addaf5 100644 (file)
@@ -1,66 +1,68 @@
 /*
     terminatorX - realtime audio scratching software
     Copyright (C) 1999-2021  Alexander König
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
+
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
+
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
     File: tX_event.h
+
     Description: Header to tX_event.cc
-*/ 
+*/
 
 #ifndef _h_tx_event_
 #define _h_tx_event_ 1
 
 #include "tX_seqpar.h"
+#include "tX_types.h"
 #include "tX_vtt.h"
-#include <stdio.h>
 #include <glib.h>
-#include "tX_types.h"
+#include <stdio.h>
 
-#include <libxml/xmlmemory.h>
 #include <libxml/parser.h>
+#include <libxml/xmlmemory.h>
+
+class tX_event {
+  private:
+    guint32 timestamp;
+    tX_seqpar* sp;
+    float value;
+
+  public:
+    tX_event(guint32 time, tX_seqpar* sp_in, float val)
+        : timestamp(time)
+        , sp(sp_in)
+        , value(val) {}
+
+#ifdef ENABLE_TX_LEGACY
+    tX_event(FILE* input);
+#endif
+    static tX_event* load_event(xmlDocPtr, xmlNodePtr);
+
+    void store(FILE* rc, gzFile rz, char* indent);
+
+    tX_seqpar* get_sp() { return sp; }
+    guint32 get_timestamp() { return timestamp; }
+    float get_value() { return value; }
+    void set_value(float val) { value = val; }
+
+    const char* get_vtt_name() { return sp->get_vtt_name(); }
+    const char* get_seqpar_name() { return sp->get_name(); }
 
-class tX_event
-{
-       private:
-       guint32                 timestamp;
-       tX_seqpar               *sp;
-       float                   value;
-       
-       public:
-       tX_event(guint32 time, tX_seqpar *sp_in, float val) : 
-               timestamp(time),sp(sp_in),value(val) {}
-
-#ifdef ENABLE_TX_LEGACY                
-       tX_event(FILE *input);
-#endif         
-       static tX_event* load_event(xmlDocPtr, xmlNodePtr);
-       
-       void store(FILE *rc, gzFile rz, char *indent);
-
-       tX_seqpar *get_sp() { return sp; }
-       guint32 get_timestamp() { return timestamp; }
-       float get_value() { return value; }
-       void set_value(float val) { value=val; }
-
-       const char *get_vtt_name() { return sp->get_vtt_name(); }
-       const char *get_seqpar_name() { return sp->get_name(); }
-
-       void playback() {
-               if (sp->is_untouched()) sp->exec_value(value);
-       }
+    void playback() {
+        if (sp->is_untouched())
+            sp->exec_value(value);
+    }
 };
 
 #endif
index 36700e57021d4bc9db98960dd7db3f02ecabdfab..fd8f43c5b665ac7cad56dcd2290354adaabcfc0a 100644 (file)
@@ -1,21 +1,21 @@
 /*
     terminatorX - realtime audio scratching software
     Copyright (C) 1999-2021  Alexander König
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
+
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
+
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-*/    
+*/
 
 #include "tX_extdial.h"
 #include "tX_seqpar.h"
 #define WID_DYN TRUE, TRUE, 0
 #define WID_FIX FALSE, FALSE, 0
 
-GCallback tX_extdial :: f_entry(GtkWidget *w, tX_extdial *ed)
-{
-       strcpy(ed->sval, gtk_entry_get_text(GTK_ENTRY(ed->entry)));
-       ed->s2f();
-       gtk_adjustment_set_value(ed->adj, ed->fval);
-       return NULL;
+GCallback tX_extdial ::f_entry(GtkWidget* w, tX_extdial* ed) {
+    strcpy(ed->sval, gtk_entry_get_text(GTK_ENTRY(ed->entry)));
+    ed->s2f();
+    gtk_adjustment_set_value(ed->adj, ed->fval);
+    return NULL;
 }
 
-GCallback tX_extdial :: f_adjustment(GtkWidget *w, tX_extdial *ed)
-{
-       ed->fval=gtk_adjustment_get_value(ed->adj);
-       ed->f2s();
-       gtk_entry_set_text(GTK_ENTRY(ed->entry), ed->sval);
-       return NULL;    
+GCallback tX_extdial ::f_adjustment(GtkWidget* w, tX_extdial* ed) {
+    ed->fval = gtk_adjustment_get_value(ed->adj);
+    ed->f2s();
+    gtk_entry_set_text(GTK_ENTRY(ed->entry), ed->sval);
+    return NULL;
 }
 
-tX_extdial :: tX_extdial(const char *l, GtkAdjustment *a, tX_seqpar * sp, bool text_below, bool hide_entry)
-{
-       adj=a;
-       fval=gtk_adjustment_get_value(adj);
-       f2s();
-       if (l) {
-               label=gtk_label_new(NULL);
-               gtk_label_set_markup(GTK_LABEL(label),l); 
-       }
-       dial=gtk_tx_dial_new(adj);
-       entry=gtk_entry_new();
-       gtk_entry_set_max_length(GTK_ENTRY(entry), 5);
-       gtk_entry_set_text(GTK_ENTRY(entry), sval);
-#if GTK_CHECK_VERSION(2,4,0)
-       gtk_entry_set_alignment(GTK_ENTRY(entry), 0.5);
+tX_extdial ::tX_extdial(const char* l, GtkAdjustment* a, tX_seqpar* sp, bool text_below, bool hide_entry) {
+    adj = a;
+    fval = gtk_adjustment_get_value(adj);
+    f2s();
+    if (l) {
+        label = gtk_label_new(NULL);
+        gtk_label_set_markup(GTK_LABEL(label), l);
+    }
+    dial = gtk_tx_dial_new(adj);
+    entry = gtk_entry_new();
+    gtk_entry_set_max_length(GTK_ENTRY(entry), 5);
+    gtk_entry_set_text(GTK_ENTRY(entry), sval);
+#if GTK_CHECK_VERSION(2, 4, 0)
+    gtk_entry_set_alignment(GTK_ENTRY(entry), 0.5);
 #endif
-       ignore_adj=0;
-       
-       eventbox=gtk_event_box_new();           
-       mainbox=gtk_box_new(GTK_ORIENTATION_VERTICAL,  text_below ? 5 : 0);
-       
-       gtk_container_add(GTK_CONTAINER(eventbox), mainbox);
-       
-       subbox=gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
-       gtk_box_set_homogeneous(GTK_BOX(subbox), TRUE);
-       gtk_box_pack_start(GTK_BOX(subbox), dial, WID_FIX);
-       gtk_box_pack_start(GTK_BOX(mainbox), subbox, WID_FIX);
-       if (text_below) {
-               gtk_box_pack_start(GTK_BOX(mainbox), entry, WID_DYN);
-       } else {
-               gtk_box_pack_start(GTK_BOX(subbox), entry, TRUE, TRUE, 3);
-       }
-       if (l) gtk_box_pack_start(GTK_BOX(mainbox), label, WID_FIX);
-       
-       if (l) gtk_widget_show(label);
-       if (!hide_entry){ gtk_widget_show(entry); }
-       gtk_entry_set_width_chars(GTK_ENTRY(entry), 4);
-       gtk_entry_set_max_width_chars(GTK_ENTRY(entry), 4);
-       gtk_widget_show(dial);
-       gtk_widget_show(subbox);
-       gtk_widget_show(mainbox);
-       gtk_widget_show(eventbox);
-       
-       g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(tX_extdial::f_entry), (void *) this);
-       g_signal_connect(G_OBJECT(adj), "value_changed", G_CALLBACK(tX_extdial::f_adjustment), (void *) this);
-       
-       if (sp) {
-               g_signal_connect(G_OBJECT(dial), "button_press_event", G_CALLBACK(tX_seqpar::tX_seqpar_press), sp);
-               g_signal_connect(G_OBJECT(entry), "button_press_event", G_CALLBACK(tX_seqpar::tX_seqpar_press), sp);                    
-               g_signal_connect(G_OBJECT(eventbox), "button_press_event", G_CALLBACK(tX_seqpar::tX_seqpar_press), sp);                 
-       }
+    ignore_adj = 0;
+
+    eventbox = gtk_event_box_new();
+    mainbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, text_below ? 5 : 0);
+
+    gtk_container_add(GTK_CONTAINER(eventbox), mainbox);
+
+    subbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
+    gtk_box_set_homogeneous(GTK_BOX(subbox), TRUE);
+    gtk_box_pack_start(GTK_BOX(subbox), dial, WID_FIX);
+    gtk_box_pack_start(GTK_BOX(mainbox), subbox, WID_FIX);
+    if (text_below) {
+        gtk_box_pack_start(GTK_BOX(mainbox), entry, WID_DYN);
+    } else {
+        gtk_box_pack_start(GTK_BOX(subbox), entry, TRUE, TRUE, 3);
+    }
+    if (l)
+        gtk_box_pack_start(GTK_BOX(mainbox), label, WID_FIX);
+
+    if (l)
+        gtk_widget_show(label);
+    if (!hide_entry) {
+        gtk_widget_show(entry);
+    }
+    gtk_entry_set_width_chars(GTK_ENTRY(entry), 4);
+    gtk_entry_set_max_width_chars(GTK_ENTRY(entry), 4);
+    gtk_widget_show(dial);
+    gtk_widget_show(subbox);
+    gtk_widget_show(mainbox);
+    gtk_widget_show(eventbox);
+
+    g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(tX_extdial::f_entry), (void*)this);
+    g_signal_connect(G_OBJECT(adj), "value_changed", G_CALLBACK(tX_extdial::f_adjustment), (void*)this);
+
+    if (sp) {
+        g_signal_connect(G_OBJECT(dial), "button_press_event", G_CALLBACK(tX_seqpar::tX_seqpar_press), sp);
+        g_signal_connect(G_OBJECT(entry), "button_press_event", G_CALLBACK(tX_seqpar::tX_seqpar_press), sp);
+        g_signal_connect(G_OBJECT(eventbox), "button_press_event", G_CALLBACK(tX_seqpar::tX_seqpar_press), sp);
+    }
 }
 
-tX_extdial :: ~tX_extdial()
-{
-       gtk_widget_destroy(entry);
-       gtk_widget_destroy(label);
-       gtk_widget_destroy(dial);
-       gtk_widget_destroy(subbox);
-       gtk_widget_destroy(mainbox);
-       gtk_widget_destroy(eventbox);   
+tX_extdial ::~tX_extdial() {
+    gtk_widget_destroy(entry);
+    gtk_widget_destroy(label);
+    gtk_widget_destroy(dial);
+    gtk_widget_destroy(subbox);
+    gtk_widget_destroy(mainbox);
+    gtk_widget_destroy(eventbox);
 }
index 4472bd939c583f7b52191a8ad0c3de0bbf8b86aa..ad61b821ba0d7973e2c7761687a60d52ac1bf6d8 100644 (file)
@@ -1,58 +1,60 @@
 /*
     terminatorX - realtime audio scratching software
     Copyright (C) 1999-2021  Alexander König
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
+
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
+
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
-    File: tX_extdial.h 
-*/    
+
+    File: tX_extdial.h
+*/
 
 #ifndef _h_tx_extdial_
 #define _h_tx_extdial_
 
-#include <gtk/gtk.h>
 #include "tX_dial.h"
+#include <gtk/gtk.h>
 #include <stdio.h>
 
 class tX_seqpar;
 
-class tX_extdial
-{
-       GtkWidget *eventbox;
-       GtkWidget *mainbox;
-       GtkWidget *subbox;
-       GtkWidget *dial;
-       GtkWidget *label;
-       GtkWidget *entry;
-       GtkAdjustment *adj;
-       int ignore_adj;
-       float fval;
-       char sval[30];
-
-       private:
-       void s2f() { sscanf(sval, "%f", &fval); /*printf("s2f(): s:%s, f%f\n", sval, fval);*/ };
-       void f2s() { sprintf(sval, "%3f", fval); sval[4]=0; /* printf("f2s(): s:%s, f%f\n", sval, fval); */ };
-       
-       public:
-       tX_extdial(const char *l, GtkAdjustment *a, tX_seqpar * sp, bool text_below=false, bool hide_entry=false);
-       ~tX_extdial();
-       GtkWidget *get_widget() { return eventbox; };
-       GtkWidget *get_dial() { return dial; }
-       GtkWidget *get_entry() { return entry; }
-       
-       static GCallback f_entry(GtkWidget *w, tX_extdial *ed);
-       static GCallback f_adjustment(GtkWidget *w, tX_extdial *ed);
+class tX_extdial {
+    GtkWidget* eventbox;
+    GtkWidget* mainbox;
+    GtkWidget* subbox;
+    GtkWidget* dial;
+    GtkWidget* label;
+    GtkWidget* entry;
+    GtkAdjustment* adj;
+    int ignore_adj;
+    float fval;
+    char sval[30];
+
+  private:
+    void s2f() { sscanf(sval, "%f", &fval); /*printf("s2f(): s:%s, f%f\n", sval, fval);*/ };
+    void f2s() {
+        sprintf(sval, "%3f", fval);
+        sval[4] = 0; /* printf("f2s(): s:%s, f%f\n", sval, fval); */
+    };
+
+  public:
+    tX_extdial(const char* l, GtkAdjustment* a, tX_seqpar* sp, bool text_below = false, bool hide_entry = false);
+    ~tX_extdial();
+    GtkWidget* get_widget() { return eventbox; };
+    GtkWidget* get_dial() { return dial; }
+    GtkWidget* get_entry() { return entry; }
+
+    static GCallback f_entry(GtkWidget* w, tX_extdial* ed);
+    static GCallback f_adjustment(GtkWidget* w, tX_extdial* ed);
 };
 
 #endif
index 7a08ecf1832be9a428c193e0980485856fde9a64..c59052ace78543699168d7d4264858cc82688f35 100644 (file)
@@ -1,32 +1,31 @@
 /*
     terminatorX - realtime audio scratching software
     Copyright (C) 1999-2021  Alexander König
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
+
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
+
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
     File: tX_flash.c
+
     Description: This contains the implementation of the tx_flash_flash widget.
-*/    
+*/
 
 #include <math.h>
 
-
 #define IS_TX_FLASH 1
 #include "tX_flash.h"
-#include "tX_types.h"
 #include "tX_global.h"
+#include "tX_types.h"
 #include <malloc.h>
 
 #ifndef WIN32
@@ -52,424 +51,404 @@ extern "C" {
 #define MAX_MAX_CYCLES 30;
 
 /* pre dec */
-static void gtk_tx_flash_class_init (GtkTxFlashClass *);
-static void gtk_tx_flash_init (GtkTxFlash *tx_flash);
-GtkWidget* gtk_tx_flash_new ();
-static void gtk_tx_flash_destroy (GtkWidget *widget);
-static void gtk_tx_flash_realize (GtkWidget *widget);
-static void gtk_tx_flash_get_preferred_width (GtkWidget *widget, gint *minimal_height, gint *natural_height);
-static void gtk_tx_flash_get_preferred_height (GtkWidget *widget, gint *minimal_height, gint *natural_height);
+static void gtk_tx_flash_class_init(GtkTxFlashClass*);
+static void gtk_tx_flash_init(GtkTxFlash* tx_flash);
+GtkWidget* gtk_tx_flash_new();
+static void gtk_tx_flash_destroy(GtkWidget* widget);
+static void gtk_tx_flash_realize(GtkWidget* widget);
+static void gtk_tx_flash_get_preferred_width(GtkWidget* widget, gint* minimal_height, gint* natural_height);
+static void gtk_tx_flash_get_preferred_height(GtkWidget* widget, gint* minimal_height, gint* natural_height);
 
-static void gtk_tx_flash_size_allocate (GtkWidget *widget, GtkAllocation *allocation);
-static gboolean gtk_tx_flash_draw (GtkWidget *widget, cairo_t *cairo);
+static void gtk_tx_flash_size_allocate(GtkWidget* widget, GtkAllocation* allocation);
+static gboolean gtk_tx_flash_draw(GtkWidget* widget, cairo_t* cairo);
 
 /* Local data */
 
-static GtkWidgetClass *parent_class = NULL;
-
-GType gtk_tx_flash_get_type ()
-{
-       static GType tx_flash_type = 0;
-
-       if (!tx_flash_type) {
-               static const GTypeInfo tx_flash_info = {
-                       sizeof (GtkTxFlashClass),
-                       NULL,
-                       NULL,
-                       (GClassInitFunc) gtk_tx_flash_class_init, 
-                       NULL,
-                       NULL,
-                       sizeof (GtkTxFlash),
-               0,
-                       (GInstanceInitFunc) gtk_tx_flash_init,
-               };
-
-               tx_flash_type = g_type_register_static(GTK_TYPE_WIDGET, "GtkTxFlash", &tx_flash_info, 0);
+static GtkWidgetClass* parent_class = NULL;
+
+GType gtk_tx_flash_get_type() {
+    static GType tx_flash_type = 0;
+
+    if (!tx_flash_type) {
+        static const GTypeInfo tx_flash_info = {
+            sizeof(GtkTxFlashClass),
+            NULL,
+            NULL,
+            (GClassInitFunc)gtk_tx_flash_class_init,
+            NULL,
+            NULL,
+            sizeof(GtkTxFlash),
+            0,
+            (GInstanceInitFunc)gtk_tx_flash_init,
+        };
+
+        tx_flash_type = g_type_register_static(GTK_TYPE_WIDGET, "GtkTxFlash", &tx_flash_info, 0);
     }
-       
-       return tx_flash_type;
+
+    return tx_flash_type;
 }
 
-static void gtk_tx_flash_class_init (GtkTxFlashClass *gclass)
-{
-       GtkWidgetClass *widget_class;
-       
-       widget_class = (GtkWidgetClass*) gclass;
-       
-       parent_class = (GtkWidgetClass*) g_type_class_peek (gtk_widget_get_type ());
-       
-       widget_class->destroy = gtk_tx_flash_destroy;
-       
-       widget_class->realize = gtk_tx_flash_realize;
-       widget_class->draw = gtk_tx_flash_draw;
-       
-       widget_class->get_preferred_height = gtk_tx_flash_get_preferred_height;
-       widget_class->get_preferred_width = gtk_tx_flash_get_preferred_width;
-       
-       widget_class->size_allocate = gtk_tx_flash_size_allocate;
+static void gtk_tx_flash_class_init(GtkTxFlashClass* gclass) {
+    GtkWidgetClass* widget_class;
+
+    widget_class = (GtkWidgetClass*)gclass;
+
+    parent_class = (GtkWidgetClass*)g_type_class_peek(gtk_widget_get_type());
+
+    widget_class->destroy = gtk_tx_flash_destroy;
+
+    widget_class->realize = gtk_tx_flash_realize;
+    widget_class->draw = gtk_tx_flash_draw;
+
+    widget_class->get_preferred_height = gtk_tx_flash_get_preferred_height;
+    widget_class->get_preferred_width = gtk_tx_flash_get_preferred_width;
+
+    widget_class->size_allocate = gtk_tx_flash_size_allocate;
 }
 
 enum {
-       COL_BG,
-       COL_NORM,
-       COL_NORM_HALF,
-       COL_LOUD,
-       COL_LOUD_HALF,
-       NO_COLS
+    COL_BG,
+    COL_NORM,
+    COL_NORM_HALF,
+    COL_LOUD,
+    COL_LOUD_HALF,
+    NO_COLS
 };
 
 /* c=a+(a-b)*x; */
 
-void mk_half(double s, GdkRGBA *a, GdkRGBA *b, GdkRGBA *c)
-{
-       c->red=a->red-(a->red-b->red)*s;
-       c->green=a->green-(a->green-b->green)*s;
-       c->blue=a->blue-(a->blue-b->blue)*s;
-       c->alpha=1.0;
+void mk_half(double s, GdkRGBA* a, GdkRGBA* b, GdkRGBA* c) {
+    c->red = a->red - (a->red - b->red) * s;
+    c->green = a->green - (a->green - b->green) * s;
+    c->blue = a->blue - (a->blue - b->blue) * s;
+    c->alpha = 1.0;
 }
 
-void gtk_tx_flash_update_colors(GtkTxFlash *tx)
-{
-       gdk_rgba_parse(&tx->colors[COL_BG], globals.vu_meter_bg);
-       tx->colors[COL_BG].alpha = 1.0;
-       gdk_rgba_parse(&tx->colors[COL_LOUD], globals.vu_meter_loud);
-       tx->colors[COL_LOUD].alpha = 1.0;
-       gdk_rgba_parse(&tx->colors[COL_NORM], globals.vu_meter_normal);
-       tx->colors[COL_NORM].alpha = 1.0;
-       mk_half(globals.vu_meter_border_intensity, &tx->colors[COL_BG], &tx->colors[COL_LOUD], &tx->colors[COL_LOUD_HALF]);
-       mk_half(globals.vu_meter_border_intensity, &tx->colors[COL_BG], &tx->colors[COL_NORM], &tx->colors[COL_NORM_HALF]);
+void gtk_tx_flash_update_colors(GtkTxFlash* tx) {
+    gdk_rgba_parse(&tx->colors[COL_BG], globals.vu_meter_bg);
+    tx->colors[COL_BG].alpha = 1.0;
+    gdk_rgba_parse(&tx->colors[COL_LOUD], globals.vu_meter_loud);
+    tx->colors[COL_LOUD].alpha = 1.0;
+    gdk_rgba_parse(&tx->colors[COL_NORM], globals.vu_meter_normal);
+    tx->colors[COL_NORM].alpha = 1.0;
+    mk_half(globals.vu_meter_border_intensity, &tx->colors[COL_BG], &tx->colors[COL_LOUD], &tx->colors[COL_LOUD_HALF]);
+    mk_half(globals.vu_meter_border_intensity, &tx->colors[COL_BG], &tx->colors[COL_NORM], &tx->colors[COL_NORM_HALF]);
 }
 
-static void gtk_tx_flash_init (GtkTxFlash *tx_flash)
-{
-       tx_flash->surface = NULL;
+static void gtk_tx_flash_init(GtkTxFlash* tx_flash) {
+    tx_flash->surface = NULL;
 
-       gtk_tx_flash_update_colors(tx_flash);
+    gtk_tx_flash_update_colors(tx_flash);
 }
 
-GtkWidget* gtk_tx_flash_new ()
-{
-       GtkTxFlash *tx_flash;
-       tx_flash = (GtkTxFlash *)g_object_new(gtk_tx_flash_get_type (), NULL);  
-       
-       // tX_msg("creating a new flash: %08x\n", tx_flash);
-       return GTK_WIDGET (tx_flash);
+GtkWidget* gtk_tx_flash_new() {
+    GtkTxFlash* tx_flash;
+    tx_flash = (GtkTxFlash*)g_object_new(gtk_tx_flash_get_type(), NULL);
+
+    // tX_msg("creating a new flash: %08x\n", tx_flash);
+    return GTK_WIDGET(tx_flash);
 }
 
-static void gtk_tx_flash_destroy (GtkWidget *widget)
-{
-       g_return_if_fail (widget != NULL);
-       g_return_if_fail (GTK_IS_TX_FLASH (widget));
-       
-       if (GTK_WIDGET_CLASS (parent_class)->destroy)
-               (*GTK_WIDGET_CLASS (parent_class)->destroy) (widget);
+static void gtk_tx_flash_destroy(GtkWidget* widget) {
+    g_return_if_fail(widget != NULL);
+    g_return_if_fail(GTK_IS_TX_FLASH(widget));
+
+    if (GTK_WIDGET_CLASS(parent_class)->destroy)
+        (*GTK_WIDGET_CLASS(parent_class)->destroy)(widget);
 }
 
-static void gtk_tx_flash_realize (GtkWidget *widget)
-{
-       GtkTxFlash *tx_flash;
-       GdkWindowAttr attributes;
-       gint attributes_mask;
-       
-       g_return_if_fail (widget != NULL);
-       g_return_if_fail (GTK_IS_TX_FLASH (widget));
-       
-       tx_flash=GTK_TX_FLASH(widget);
-
-       gtk_widget_set_realized(widget, TRUE);
-       GtkAllocation allocation;
-       gtk_widget_get_allocation(widget, &allocation);
-       
-       attributes.x = allocation.x;
-       attributes.y = allocation.y;
-       attributes.width = allocation.width;
-       attributes.height = allocation.height;
-       attributes.wclass = GDK_INPUT_OUTPUT;
-       attributes.window_type = GDK_WINDOW_CHILD;
-       attributes.event_mask = gtk_widget_get_events (widget) | 
-               GDK_EXPOSURE_MASK;
-       attributes.visual = gtk_widget_get_visual (widget);
-       attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
-       
-       gtk_widget_set_window(widget, gdk_window_new (gtk_widget_get_parent_window(widget), &attributes, attributes_mask));
-       
-       gdk_window_set_user_data (gtk_widget_get_window(widget), widget);
-       
-       if (tx_flash->surface) {
-               cairo_surface_destroy (tx_flash->surface);
-       }
-       
-       tx_flash->surface = gdk_window_create_similar_surface (gtk_widget_get_window(widget), CAIRO_CONTENT_COLOR, allocation.width, allocation.height);
+static void gtk_tx_flash_realize(GtkWidget* widget) {
+    GtkTxFlash* tx_flash;
+    GdkWindowAttr attributes;
+    gint attributes_mask;
+
+    g_return_if_fail(widget != NULL);
+    g_return_if_fail(GTK_IS_TX_FLASH(widget));
+
+    tx_flash = GTK_TX_FLASH(widget);
+
+    gtk_widget_set_realized(widget, TRUE);
+    GtkAllocation allocation;
+    gtk_widget_get_allocation(widget, &allocation);
+
+    attributes.x = allocation.x;
+    attributes.y = allocation.y;
+    attributes.width = allocation.width;
+    attributes.height = allocation.height;
+    attributes.wclass = GDK_INPUT_OUTPUT;
+    attributes.window_type = GDK_WINDOW_CHILD;
+    attributes.event_mask = gtk_widget_get_events(widget) | GDK_EXPOSURE_MASK;
+    attributes.visual = gtk_widget_get_visual(widget);
+    attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
+
+    gtk_widget_set_window(widget, gdk_window_new(gtk_widget_get_parent_window(widget), &attributes, attributes_mask));
+
+    gdk_window_set_user_data(gtk_widget_get_window(widget), widget);
+
+    if (tx_flash->surface) {
+        cairo_surface_destroy(tx_flash->surface);
+    }
+
+    tx_flash->surface = gdk_window_create_similar_surface(gtk_widget_get_window(widget), CAIRO_CONTENT_COLOR, allocation.width, allocation.height);
 }
 
-static void gtk_tx_flash_get_preferred_width (GtkWidget *widget, gint *minimal_width, gint *natural_width)
-{
-  *minimal_width = *natural_width = TX_FLASH_DEFAULT_SIZE_X;
+static void gtk_tx_flash_get_preferred_width(GtkWidget* widget, gint* minimal_width, gint* natural_width) {
+    *minimal_width = *natural_width = TX_FLASH_DEFAULT_SIZE_X;
 }
 
-static void gtk_tx_flash_get_preferred_height (GtkWidget *widget, gint *minimal_height, gint *natural_height)
-{
+static void gtk_tx_flash_get_preferred_height(GtkWidget* widget, gint* minimal_height, gint* natural_height) {
     *minimal_height = *natural_height = TX_FLASH_DEFAULT_SIZE_Y;
 }
 
+static void gtk_tx_flash_prepare(GtkWidget* widget) {
+    GtkTxFlash* tx_flash;
+
+    g_return_if_fail(widget != NULL);
+    g_return_if_fail(GTK_IS_TX_FLASH(widget));
+
+    tx_flash = GTK_TX_FLASH(widget);
 
-static void gtk_tx_flash_prepare(GtkWidget *widget)
-{
-       GtkTxFlash *tx_flash;
-
-       g_return_if_fail (widget != NULL);
-       g_return_if_fail (GTK_IS_TX_FLASH (widget));
-       
-       tx_flash=GTK_TX_FLASH(widget);
-
-       GtkAllocation allocation;
-       gtk_widget_get_allocation(widget, &allocation);
-       
-       tx_flash->levels=(allocation.height-(2*DY))/DLEVEL;
-       tx_flash->channel[0].last_level=0;
-       tx_flash->channel[1].last_level=0;
-       tx_flash->channel[0].max=0;
-       tx_flash->channel[1].max=0;
-       tx_flash->level_value=MAX_VALUE/(f_prec) tx_flash->levels;
-       tx_flash->red_level=(RED_BORDER/tx_flash->level_value);
-       
-       tx_flash->channel[0].x1=DMINIX+S_MINIX+2;
-       tx_flash->channel[1].x2=allocation.width-tx_flash->channel[0].x1;
-               
-       if (allocation.width%2>0) {
-               // odd
-               tx_flash->center_expand=0;
-               tx_flash->channel[0].x2=allocation.width/2-1;
-       } else {
-               // even
-               tx_flash->center_expand=1;
-               tx_flash->channel[0].x2=allocation.width/2-2;
-       }
-       tx_flash->channel[1].x1=allocation.width/2+2;
-       
-       //tX_msg("flash: width %i: left %i, right %i", widget->allocation.width, tx_flash->channel[0].x2-tx_flash->channel[0].x1, tx_flash->channel[1].x2-tx_flash->channel[1].x1);
+    GtkAllocation allocation;
+    gtk_widget_get_allocation(widget, &allocation);
+
+    tx_flash->levels = (allocation.height - (2 * DY)) / DLEVEL;
+    tx_flash->channel[0].last_level = 0;
+    tx_flash->channel[1].last_level = 0;
+    tx_flash->channel[0].max = 0;
+    tx_flash->channel[1].max = 0;
+    tx_flash->level_value = MAX_VALUE / (f_prec)tx_flash->levels;
+    tx_flash->red_level = (RED_BORDER / tx_flash->level_value);
+
+    tx_flash->channel[0].x1 = DMINIX + S_MINIX + 2;
+    tx_flash->channel[1].x2 = allocation.width - tx_flash->channel[0].x1;
+
+    if (allocation.width % 2 > 0) {
+        // odd
+        tx_flash->center_expand = 0;
+        tx_flash->channel[0].x2 = allocation.width / 2 - 1;
+    } else {
+        // even
+        tx_flash->center_expand = 1;
+        tx_flash->channel[0].x2 = allocation.width / 2 - 2;
+    }
+    tx_flash->channel[1].x1 = allocation.width / 2 + 2;
+
+    //tX_msg("flash: width %i: left %i, right %i", widget->allocation.width, tx_flash->channel[0].x2-tx_flash->channel[0].x1, tx_flash->channel[1].x2-tx_flash->channel[1].x1);
 }
 
-static void gtk_tx_flash_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
-{
-       g_return_if_fail (widget != NULL);
-       g_return_if_fail (GTK_IS_TX_FLASH (widget));
-       g_return_if_fail (allocation != NULL);
-       
-       gtk_widget_set_allocation(widget, allocation);
-       
-       gtk_tx_flash_prepare(widget);
-       
-       if (gtk_widget_get_realized (widget)) {
-               gdk_window_move_resize (gtk_widget_get_window(widget),
-                                 allocation->x, allocation->y,
-                                 allocation->width, allocation->height);
-       }
+static void gtk_tx_flash_size_allocate(GtkWidget* widget, GtkAllocation* allocation) {
+    g_return_if_fail(widget != NULL);
+    g_return_if_fail(GTK_IS_TX_FLASH(widget));
+    g_return_if_fail(allocation != NULL);
+
+    gtk_widget_set_allocation(widget, allocation);
+
+    gtk_tx_flash_prepare(widget);
+
+    if (gtk_widget_get_realized(widget)) {
+        gdk_window_move_resize(gtk_widget_get_window(widget),
+            allocation->x, allocation->y,
+            allocation->width, allocation->height);
+    }
 }
 
-static void gtk_tx_flash_paint_yourself(GtkWidget *widget, cairo_t *cr)
-{
-       GtkTxFlash *tx_flash;
-       GtkAllocation allocation;
-       
-       gint i, x11, x12,x21, x22, y, middle;
-       int long_level;
-       
-       tx_flash = GTK_TX_FLASH (widget);
-       gtk_widget_get_allocation(widget, &allocation);
-       
-       cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
-       cairo_set_source_surface (cr, tx_flash->surface, 0, 0);
-
-       gdk_cairo_set_source_rgba (cr, &tx_flash->colors[COL_BG]);
-       cairo_rectangle(cr, 0, 0, allocation.width, allocation.height);
-       cairo_fill(cr);
-       
-       cairo_set_line_width(cr,1);
-       gdk_cairo_set_source_rgba (cr, &tx_flash->colors[COL_NORM]);
-       
-       x12=DMINIX+S_MINIX;
-       x21=allocation.width-1-x12;
-       middle=allocation.width/2;
-       
-       for (i=0, y=allocation.height-DY; i<=tx_flash->levels; y-=DLEVEL, i++) {
-               if (i==0) {
-                       long_level=1;
-               } else if (i==tx_flash->red_level-1) {
-                       long_level=1;
-               } else if (i==tx_flash->red_level) {
-                       long_level=1;
-                       gdk_cairo_set_source_rgba (cr, &tx_flash->colors[COL_LOUD_HALF]);       
-               } else if (i==tx_flash->levels) {
-                       long_level=1;
-               } else long_level=0;
-               
-               if (long_level) {
-                       x11=x12-L_MINIX;
-                       x22=x21+L_MINIX;
-               } else {
-                       x11=x12-S_MINIX;
-                       x22=x21+S_MINIX;                
-               }
-               
-               cairo_move_to (cr, x11, y);
-               cairo_line_to (cr, x12+1, y);
-               
-               cairo_move_to (cr, x21, y);
-               cairo_line_to (cr, x22+1, y);
-
-               if (tx_flash->center_expand) {
-                       cairo_move_to (cr, middle-1, y);
-                       cairo_line_to (cr, middle+1, y);
-               } else {
-                       cairo_move_to (cr, middle, y);
-                       cairo_line_to (cr, middle+1, y);
-               }
-               cairo_stroke (cr);
-       }
+static void gtk_tx_flash_paint_yourself(GtkWidget* widget, cairo_t* cr) {
+    GtkTxFlash* tx_flash;
+    GtkAllocation allocation;
+
+    gint i, x11, x12, x21, x22, y, middle;
+    int long_level;
+
+    tx_flash = GTK_TX_FLASH(widget);
+    gtk_widget_get_allocation(widget, &allocation);
+
+    cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
+    cairo_set_source_surface(cr, tx_flash->surface, 0, 0);
+
+    gdk_cairo_set_source_rgba(cr, &tx_flash->colors[COL_BG]);
+    cairo_rectangle(cr, 0, 0, allocation.width, allocation.height);
+    cairo_fill(cr);
+
+    cairo_set_line_width(cr, 1);
+    gdk_cairo_set_source_rgba(cr, &tx_flash->colors[COL_NORM]);
+
+    x12 = DMINIX + S_MINIX;
+    x21 = allocation.width - 1 - x12;
+    middle = allocation.width / 2;
+
+    for (i = 0, y = allocation.height - DY; i <= tx_flash->levels; y -= DLEVEL, i++) {
+        if (i == 0) {
+            long_level = 1;
+        } else if (i == tx_flash->red_level - 1) {
+            long_level = 1;
+        } else if (i == tx_flash->red_level) {
+            long_level = 1;
+            gdk_cairo_set_source_rgba(cr, &tx_flash->colors[COL_LOUD_HALF]);
+        } else if (i == tx_flash->levels) {
+            long_level = 1;
+        } else
+            long_level = 0;
+
+        if (long_level) {
+            x11 = x12 - L_MINIX;
+            x22 = x21 + L_MINIX;
+        } else {
+            x11 = x12 - S_MINIX;
+            x22 = x21 + S_MINIX;
+        }
+
+        cairo_move_to(cr, x11, y);
+        cairo_line_to(cr, x12 + 1, y);
+
+        cairo_move_to(cr, x21, y);
+        cairo_line_to(cr, x22 + 1, y);
+
+        if (tx_flash->center_expand) {
+            cairo_move_to(cr, middle - 1, y);
+            cairo_line_to(cr, middle + 1, y);
+        } else {
+            cairo_move_to(cr, middle, y);
+            cairo_line_to(cr, middle + 1, y);
+        }
+        cairo_stroke(cr);
+    }
 }
 
-static gboolean gtk_tx_flash_draw(GtkWidget *widget, cairo_t *cr)
-{
-       g_return_val_if_fail (widget != NULL, FALSE);
-       g_return_val_if_fail (GTK_IS_TX_FLASH (widget), FALSE);
-       
-       gtk_tx_flash_prepare(widget);
-       gtk_tx_flash_paint_yourself(widget, cr); 
-       
-       return FALSE;
-} 
-
-
-static void gtk_tx_flash_set_channel_level(GtkTxFlash *tx_flash, f_prec new_value, struct flash_channel *channel);
-
-void gtk_tx_flash_set_level(GtkWidget *widget, f_prec left_channel, f_prec right_channel)
-{
-       GtkTxFlash *tx_flash;
-       
-       g_return_if_fail (widget != NULL);
-       g_return_if_fail (GTK_IS_TX_FLASH (widget));
-       
-       tx_flash = GTK_TX_FLASH (widget);
-       
-       gtk_tx_flash_set_channel_level(tx_flash, left_channel, &tx_flash->channel[0]);
-       gtk_tx_flash_set_channel_level(tx_flash, right_channel, &tx_flash->channel[1]);
+static gboolean gtk_tx_flash_draw(GtkWidget* widget, cairo_t* cr) {
+    g_return_val_if_fail(widget != NULL, FALSE);
+    g_return_val_if_fail(GTK_IS_TX_FLASH(widget), FALSE);
+
+    gtk_tx_flash_prepare(widget);
+    gtk_tx_flash_paint_yourself(widget, cr);
+
+    return FALSE;
 }
 
-static void gtk_tx_flash_set_channel_level(GtkTxFlash *tx_flash, f_prec new_value, struct flash_channel *channel)
-{
-       GtkWidget *widget=GTK_WIDGET(tx_flash);
-       GtkAllocation allocation;
-       GdkDrawingContext *context;
-       GdkWindow *window;
-       cairo_t *cr;
-       cairo_region_t *region;
-       gint i, y;
-       int new_level;
-       int red=0;
-       
-       new_level=(int) (new_value/tx_flash->level_value);
-       gtk_widget_get_allocation(widget, &allocation);
-       
-       region = cairo_region_create();
-       window = gtk_widget_get_window(widget);
-       context = gdk_window_begin_draw_frame(window, region);
-       cr =  gdk_drawing_context_get_cairo_context(context);
-       cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
-       cairo_set_line_width(cr,1);
-       cairo_set_source_surface (cr, tx_flash->surface, 0, 0);
-
-       gdk_cairo_set_source_rgba (cr, &tx_flash->colors[COL_BG]);
-
-       // tX_msg("setting level: %5d for widget %08x channel %08x\n", new_level, tx_flash, channel);
-       
-       if (new_level>tx_flash->levels) 
-               new_level=tx_flash->levels;
-       
-       if (new_level>channel->max) {
-               channel->max=new_level;
-               tx_flash->max_cycles=MAX_MAX_CYCLES;
-       } else {
-               tx_flash->max_cycles--;
-       }
-       
-       if (tx_flash->max_cycles <= 0) {
-               y=allocation.height-(DY+(channel->max)*DLEVEL);
-               gdk_cairo_set_source_rgba (cr, &tx_flash->colors[COL_BG]);
-               cairo_move_to (cr, channel->x1, y);
-               cairo_line_to (cr, channel->x2, y);
-               cairo_stroke (cr);
-               
-               if (channel->max>0) {
-                       channel->max--;
-                       y+=DLEVEL;
-                       if (channel->max>tx_flash->red_level) {
-                               gdk_cairo_set_source_rgba (cr, &tx_flash->colors[COL_LOUD]);
-                       } else {
-                               gdk_cairo_set_source_rgba (cr, &tx_flash->colors[COL_NORM]);
-                       }
-                       
-                       cairo_move_to (cr, channel->x1, y);
-                       cairo_line_to (cr, channel->x2, y);
-                       cairo_stroke (cr);
-               }
-       }
-       
-       if (new_level!=channel->last_level)  {
-           if (new_level<channel->last_level) {
-                   new_level=channel->last_level*globals.flash_response;
-           }
-
-           if (new_level>channel->last_level) {
-                   gdk_cairo_set_source_rgba (cr, &tx_flash->colors[COL_NORM]);
-
-                   for (i=channel->last_level, y=allocation.height-(DY+channel->last_level*DLEVEL); i<=new_level; y-=DLEVEL, i++) {
-                           if (!red) {
-                                   if (i>=tx_flash->red_level) {
-                                           gdk_cairo_set_source_rgba (cr, &tx_flash->colors[COL_LOUD]);
-                                           red=1;
-                                   }
-                           }
-                           cairo_move_to (cr, channel->x1, y);
-                           cairo_line_to (cr, channel->x2, y);
-                           cairo_stroke (cr);
-                   }
-           } else {
-                   gdk_cairo_set_source_rgba (cr, &tx_flash->colors[COL_BG]);
-
-                   if (channel->last_level==channel->max) {
-                           i=channel->last_level-1;
-                   } else {
-                           i=channel->last_level;
-                   }
-
-                   for (y=allocation.height-(DY+i*DLEVEL); i>new_level; y+=DLEVEL, i--) {
-                           cairo_move_to (cr, channel->x1, y);
-                           cairo_line_to (cr, channel->x2, y);
-                           cairo_stroke (cr);
-                   }
-           }
-           channel->last_level=new_level;
-       }
-
-       gdk_window_end_draw_frame(window, context);
-       cairo_region_destroy(region);
+static void gtk_tx_flash_set_channel_level(GtkTxFlash* tx_flash, f_prec new_value, struct flash_channel* channel);
+
+void gtk_tx_flash_set_level(GtkWidget* widget, f_prec left_channel, f_prec right_channel) {
+    GtkTxFlash* tx_flash;
+
+    g_return_if_fail(widget != NULL);
+    g_return_if_fail(GTK_IS_TX_FLASH(widget));
+
+    tx_flash = GTK_TX_FLASH(widget);
+
+    gtk_tx_flash_set_channel_level(tx_flash, left_channel, &tx_flash->channel[0]);
+    gtk_tx_flash_set_channel_level(tx_flash, right_channel, &tx_flash->channel[1]);
 }
 
-void
-gtk_tx_flash_clear (GtkWidget *widget)
-{
-       GtkTxFlash *tx_flash;
-
-       tx_flash = GTK_TX_FLASH (widget);
-       
-       tx_flash->channel[0].max=0;
-       tx_flash->channel[1].max=0;
-       tx_flash->channel[0].last_level=0;
-       tx_flash->channel[1].last_level=0;
-       tx_flash->max_cycles=0;
-       
-       gtk_widget_queue_draw(widget);
+static void gtk_tx_flash_set_channel_level(GtkTxFlash* tx_flash, f_prec new_value, struct flash_channel* channel) {
+    GtkWidget* widget = GTK_WIDGET(tx_flash);
+    GtkAllocation allocation;
+    GdkDrawingContext* context;
+    GdkWindow* window;
+    cairo_t* cr;
+    cairo_region_t* region;
+    gint i, y;
+    int new_level;
+    int red = 0;
+
+    new_level = (int)(new_value / tx_flash->level_value);
+    gtk_widget_get_allocation(widget, &allocation);
+
+    region = cairo_region_create();
+    window = gtk_widget_get_window(widget);
+    context = gdk_window_begin_draw_frame(window, region);
+    cr = gdk_drawing_context_get_cairo_context(context);
+    cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
+    cairo_set_line_width(cr, 1);
+    cairo_set_source_surface(cr, tx_flash->surface, 0, 0);
+
+    gdk_cairo_set_source_rgba(cr, &tx_flash->colors[COL_BG]);
+
+    // tX_msg("setting level: %5d for widget %08x channel %08x\n", new_level, tx_flash, channel);
+
+    if (new_level > tx_flash->levels)
+        new_level = tx_flash->levels;
+
+    if (new_level > channel->max) {
+        channel->max = new_level;
+        tx_flash->max_cycles = MAX_MAX_CYCLES;
+    } else {
+        tx_flash->max_cycles--;
+    }
+
+    if (tx_flash->max_cycles <= 0) {
+        y = allocation.height - (DY + (channel->max) * DLEVEL);
+        gdk_cairo_set_source_rgba(cr, &tx_flash->colors[COL_BG]);
+        cairo_move_to(cr, channel->x1, y);
+        cairo_line_to(cr, channel->x2, y);
+        cairo_stroke(cr);
+
+        if (channel->max > 0) {
+            channel->max--;
+            y += DLEVEL;
+            if (channel->max > tx_flash->red_level) {
+                gdk_cairo_set_source_rgba(cr, &tx_flash->colors[COL_LOUD]);
+            } else {
+                gdk_cairo_set_source_rgba(cr, &tx_flash->colors[COL_NORM]);
+            }
+
+            cairo_move_to(cr, channel->x1, y);
+            cairo_line_to(cr, channel->x2, y);
+            cairo_stroke(cr);
+        }
+    }
+
+    if (new_level != channel->last_level) {
+        if (new_level < channel->last_level) {
+            new_level = channel->last_level * globals.flash_response;
+        }
+
+        if (new_level > channel->last_level) {
+            gdk_cairo_set_source_rgba(cr, &tx_flash->colors[COL_NORM]);
+
+            for (i = channel->last_level, y = allocation.height - (DY + channel->last_level * DLEVEL); i <= new_level; y -= DLEVEL, i++) {
+                if (!red) {
+                    if (i >= tx_flash->red_level) {
+                        gdk_cairo_set_source_rgba(cr, &tx_flash->colors[COL_LOUD]);
+                        red = 1;
+                    }
+                }
+                cairo_move_to(cr, channel->x1, y);
+                cairo_line_to(cr, channel->x2, y);
+                cairo_stroke(cr);
+            }
+        } else {
+            gdk_cairo_set_source_rgba(cr, &tx_flash->colors[COL_BG]);
+
+            if (channel->last_level == channel->max) {
+                i = channel->last_level - 1;
+            } else {
+                i = channel->last_level;
+            }
+
+            for (y = allocation.height - (DY + i * DLEVEL); i > new_level; y += DLEVEL, i--) {
+                cairo_move_to(cr, channel->x1, y);
+                cairo_line_to(cr, channel->x2, y);
+                cairo_stroke(cr);
+            }
+        }
+        channel->last_level = new_level;
+    }
+
+    gdk_window_end_draw_frame(window, context);
+    cairo_region_destroy(region);
+}
+
+void gtk_tx_flash_clear(GtkWidget* widget) {
+    GtkTxFlash* tx_flash;
+
+    tx_flash = GTK_TX_FLASH(widget);
+
+    tx_flash->channel[0].max = 0;
+    tx_flash->channel[1].max = 0;
+    tx_flash->channel[0].last_level = 0;
+    tx_flash->channel[1].last_level = 0;
+    tx_flash->max_cycles = 0;
+
+    gtk_widget_queue_draw(widget);
 }
 
 #ifdef __cplusplus
index 54057e825443e495d0deda73f1e3644f97d4fa83..b04e4c3476f94b473be5b2ad897a876346ee8b14 100644 (file)
@@ -1,25 +1,24 @@
 /*
     terminatorX - realtime audio scratching software
     Copyright (C) 1999-2021  Alexander König
+
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.