File: example.skel

package info (click to toggle)
gnusound 0.6.2-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,488 kB
  • ctags: 1,778
  • sloc: ansic: 21,146; sh: 2,505; xml: 527; makefile: 171; perl: 157
file content (178 lines) | stat: -rw-r--r-- 5,681 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
 * Copyright (C) 2002,2003 Pascal Haakmat.
 */

#include <math.h>
#include <gtk/gtk.h>
#include <glade/glade.h>
#include "../modutils.h"

module modinfo;

typedef struct {
    module_id id;
    shell *shl;
    GtkRange *treshold_control;
    GtkSpinButton *duration_control;
    GtkToggleButton *invert_control;
    GtkToggleButton *ganging_control;
    GtkWidget *dialog;
    AFframecount duration;
    float treshold;
    int invert;
    int ganging;
} extractor_params;

#define EXAMPLE_GLADE_FILE "example.glade"

module *
module_new() {
    MODULE_INIT(&modinfo, 
		"Noise/silence extractor",
		"Pascal Haakmat",
		"Copyright (C) 2002,2003");
    return &modinfo;
}

void
on_apply_clicked(GtkWidget *w,
                 gpointer user_data) {
    struct _module_state *module_state = 
        gtk_object_get_user_data(GTK_OBJECT(gtk_widget_get_toplevel(w)));
    extractor_params *p = (extractor_params *)module_state->data;
    p->duration = gtk_spin_button_get_value_as_float(p->duration_control) *
        p->shl->grid.gap;
    p->treshold = gtk_range_get_adjustment(p->treshold_control)->value;
    p->ganging = gtk_toggle_button_get_active(p->ganging_control) ? 0 : 1;
    p->invert = gtk_toggle_button_get_active(p->invert_control) ? 0 : 1;
    action_do(ACTION_MODULE_EXECUTE_NEW(WITH_UNDO, 
                                        p->shl,
                                        p->id));
}

void
on_ok_clicked(GtkWidget *w,
              gpointer user_data) {
    struct _module_state *module_state = 
        gtk_object_get_user_data(GTK_OBJECT(gtk_widget_get_toplevel(w)));
    extractor_params *p = (extractor_params *)module_state->data;
    on_apply_clicked(w, NULL);
    gtk_object_destroy(GTK_OBJECT(p->dialog));
}

void
on_close_clicked(GtkWidget *w,
                  gpointer user_data) {
    struct _module_state *module_state = 
        gtk_object_get_user_data(GTK_OBJECT(gtk_widget_get_toplevel(w)));
    extractor_params *p = (extractor_params *)module_state->data;
    gtk_object_destroy(GTK_OBJECT(p->dialog));
}

void
on_dialog_destroy(GtkWidget *w,
                  gpointer user_data) {
    struct _module_state *module_state = 
        gtk_object_get_user_data(GTK_OBJECT(gtk_widget_get_toplevel(w)));
    module_state->is_open = 0;
    free(module_state->data);
}

void
module_open(module_id id,
            shell *shl, 
            int undo) {
    GladeXML *xml;
    GtkWidget *w;
    char path[4096];
    extractor_params *p = mem_calloc(1, sizeof(extractor_params));
    
    if(!p) {
        gui_alert("Not enough memory.");
        return;
    }

    snprintf(path, 4096, "%s/%s", dirname(modules[id].fname), EXTRACTOR_GLADE_FILE);
    DEBUG("loading interface %s\n", path);
    xml = glade_xml_new(path, "dialog");
    
    if(!xml) {
        gui_alert("Extractor: could not load interface %s.", path);
        free(p);
        return;
    }

    shl->module_state[id].is_open = 1;
    shl->module_state[id].data = p;
    p->id = id;
    p->shl = shl;
    p->treshold_control = GTK_RANGE(glade_xml_get_widget(xml, "treshold"));
    p->duration_control = GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "duration"));
    p->invert_control = GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "invert"));
    p->ganging_control = GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "ganging"));
    p->dialog = GTK_WIDGET(glade_xml_get_widget(xml, "dialog"));
    g_signal_connect(GTK_OBJECT(p->dialog), "destroy", 
                       on_dialog_destroy, shl);
    w = GTK_WIDGET(glade_xml_get_widget(xml, "ok"));
    g_signal_connect(GTK_OBJECT(w), "clicked", on_ok_clicked, shl);
    w = GTK_WIDGET(glade_xml_get_widget(xml, "close"));
    g_signal_connect(GTK_OBJECT(w), "clicked", on_close_clicked, shl);
    w = GTK_WIDGET(glade_xml_get_widget(xml, "apply"));
    g_signal_connect(GTK_OBJECT(w), "clicked", on_apply_clicked, shl);
    gtk_object_set_user_data(GTK_OBJECT(p->dialog), 
                             GINT_TO_POINTER(&shl->module_state[id]));
    gtk_object_unref(GTK_OBJECT(xml));
}

void
module_close(mod_state *module_state) {
    gtk_object_destroy(GTK_OBJECT(((extractor_params *)module_state->data)->dialog));
}

action_group *
module_execute(shell *shl, 
               int undo) {
    AFframecount start = shl->select_start,
        end = shl->select_end;
    int map = shl->select_channel_map;
    int t, id = shl->active_module_id;
    extractor_params *p;
    action_group *undo_ag = NULL;

    if(!shl->module_state[id].is_open) { 
        gui_alert("Extractor does not have defaults.");
        return NULL;
    }

    DEBUG("treshold: %f, duration: %ld, ganging: %d, invert: %d\n",
          p->treshold, p->duration, p->ganging, p->invert);

    rwlock_rlock(&shl->sr->rwl);

    /* This returns an action group that simply restores a
       block of samples. If your do_stuff function can change the
       length of the tracks that it is operating on, or worse,
       change each tracks length differently, then you need more
       complicated undo handling. */

    if(undo) 
        undo_ag = action_group_undo_create(shl,
                                           map, 
                                           start,
                                           end - start,
                                           start,
                                           end - start);

    for(t = 0; t < snd_track_count(shl->sr); t++) 
        if((1 << t) & map && t < shl->sr->channels) 
         do_stuff(shl,
                  t,
                  start,
                  end,
                  duration,
                  times,
                  decay);
    rwlock_runlock(&shl->sr->rwl);

    return undo_ag;
}