1 /*
2 * Copyright (C) 2002 2003 2004 2005 2006, Magnus Hjorth
3 *
4 * This file is part of mhWaveEdit.
5 *
6 * mhWaveEdit is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * mhWaveEdit is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with mhWaveEdit; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21
22 #include <config.h>
23
24 #include "gettext.h"
25
26 #include "mainwindow.h"
27 #include "mapchannelsdialog.h"
28 #include "effectbrowser.h"
29 #include "main.h"
30
31 static GtkObjectClass *parent_class;
32 static gboolean *map_matrix = NULL;
33
map_channels_dialog_apply_proc(Chunk * chunk,StatusBar * bar,gpointer user_data)34 static Chunk *map_channels_dialog_apply_proc(Chunk *chunk, StatusBar *bar,
35 gpointer user_data)
36 {
37 MapChannelsDialog *mcd = MAP_CHANNELS_DIALOG(user_data);
38 g_assert(mcd->channels_in == chunk->format.channels);
39 return chunk_remap_channels(chunk,mcd->channels_out,map_matrix,
40 dither_editing,bar);
41 }
42
map_channels_dialog_apply(EffectDialog * ed)43 static gboolean map_channels_dialog_apply(EffectDialog *ed)
44 {
45 guint i,j;
46 gboolean b;
47
48 Document *d = EFFECT_BROWSER(ed->eb)->dl->selected;
49 MapChannelsDialog *mcd = MAP_CHANNELS_DIALOG(ed);
50
51 g_assert(mcd->channels_in == d->chunk->format.channels);
52
53 if (intbox_check(mcd->outchannels)) return TRUE;
54
55 map_matrix = g_malloc(mcd->channels_in*mcd->channels_out*
56 sizeof(gboolean));
57 for (i=0; i<mcd->channels_in; i++)
58 for (j=0; j<mcd->channels_out; j++)
59 map_matrix[i*mcd->channels_out + j] =
60 gtk_toggle_button_get_active(mcd->channel_map[i*8+j]);
61
62 b = document_apply_cb(d,map_channels_dialog_apply_proc,FALSE,mcd);
63
64 g_free(map_matrix);
65 map_matrix = NULL;
66
67 return b;
68 }
69
map_channels_dialog_target_changed(EffectDialog * ed)70 static void map_channels_dialog_target_changed(EffectDialog *ed)
71 {
72 MapChannelsDialog *ccd = MAP_CHANNELS_DIALOG(ed);
73 if (ccd->channels_in != EFFECT_BROWSER(ed->eb)->dl->format.channels)
74 effect_browser_invalidate_effect(EFFECT_BROWSER(ed->eb),
75 "mapchannels",'B');
76 }
77
numchannels_changed(Intbox * box,long int val,gpointer user_data)78 static void numchannels_changed(Intbox *box, long int val, gpointer user_data)
79 {
80 MapChannelsDialog *mcd = MAP_CHANNELS_DIALOG(user_data);
81 int i,j;
82
83 mcd->channels_out = val;
84
85 for (i=0; i<8; i++) {
86
87 if (i < val)
88 gtk_widget_show(mcd->outnames[i]);
89 else
90 gtk_widget_hide(mcd->outnames[i]);
91
92 for (j=0; j<mcd->channels_in; j++) {
93 if (i < val)
94 gtk_widget_show(GTK_WIDGET(mcd->channel_map[j*8+i]));
95 else
96 gtk_widget_hide(GTK_WIDGET(mcd->channel_map[j*8+i]));
97 }
98 }
99 }
100
map_channels_setup(EffectDialog * ed)101 static void map_channels_setup(EffectDialog *ed)
102 {
103 int i,j;
104 GtkWidget *z,*a,*b,*c,*d;
105 GtkLabel *l;
106 guint channels_in = EFFECT_BROWSER(ed->eb)->dl->format.channels;
107 MapChannelsDialog *mcd = MAP_CHANNELS_DIALOG(ed);
108
109 mcd->channels_in = channels_in;
110 mcd->channels_out = channels_in;
111 mcd->outchannels = INTBOX(intbox_new(8));
112
113 z = gtk_vbox_new(FALSE,5);
114 gtk_box_pack_start(GTK_BOX(ed->input_area),z,FALSE,FALSE,0);
115
116 a = gtk_label_new(_("This effect applies to the whole file, "
117 "not just the selection"));
118 gtk_container_add(GTK_CONTAINER(z),a);
119
120 a = gtk_hbox_new(FALSE,3);
121 gtk_container_add(GTK_CONTAINER(z),a);
122
123 b = gtk_label_new(_("Output channels: "));
124 gtk_box_pack_start(GTK_BOX(a),b,FALSE,FALSE,0);
125 b = intbox_create_scale(mcd->outchannels,1,8);
126 gtk_box_pack_start(GTK_BOX(a),b,FALSE,FALSE,0);
127 b = GTK_WIDGET(mcd->outchannels);
128 gtk_box_pack_start(GTK_BOX(a),b,FALSE,FALSE,0);
129
130 a = gtk_frame_new(_("Map"));
131 gtk_container_add(GTK_CONTAINER(z),a);
132
133
134 b = gtk_table_new(2+channels_in,3,FALSE);
135 gtk_container_add(GTK_CONTAINER(a),b);
136 attach_label("x",b,1,1);
137 c = gtk_label_new(_("Source"));
138 gtk_table_attach(GTK_TABLE(b),c,0,1,2,2+channels_in,0,0,4,0);
139 attach_label(_("Destination"),b,0,2);
140 /*
141 c = gtk_label_new(_("Destination"));
142 gtk_misc_set_alignment(GTK_MISC(c),0.0,0.5);
143 gtk_table_attach(GTK_TABLE(b),c,2,3,0,1,GTK_FILL,0,10,0);
144 */
145
146 c = gtk_table_new(1+channels_in,8,TRUE);
147 gtk_table_attach(GTK_TABLE(b),c,2,3,1,2+channels_in,GTK_FILL,GTK_FILL,0,0);
148
149 for (i=0; i<8; i++) {
150 l = attach_label(channel_name(i,8),c,0,i);
151 mcd->outnames[i] = GTK_WIDGET(l);
152 }
153 for (i=0; i<channels_in; i++) {
154 attach_label(channel_name(i,channels_in),b,2+i,1);
155 for (j=0; j<8; j++) {
156 d = gtk_check_button_new();
157 if (i == j)
158 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(d),TRUE);
159 mcd->channel_map[i*8+j] = GTK_TOGGLE_BUTTON(d);
160 gtk_table_attach(GTK_TABLE(c),d,j,j+1,1+i,1+i+1,GTK_FILL,0,0,
161 0);
162 }
163 }
164
165 gtk_table_set_col_spacings(GTK_TABLE(c),4);
166
167 gtk_widget_show_all(z);
168
169 gtk_signal_connect(GTK_OBJECT(mcd->outchannels),"numchanged",
170 GTK_SIGNAL_FUNC(numchannels_changed),mcd);
171 intbox_set(mcd->outchannels,mcd->channels_out);
172
173 }
174
map_channels_dialog_class_init(EffectDialogClass * klass)175 static void map_channels_dialog_class_init(EffectDialogClass *klass)
176 {
177 parent_class = gtk_type_class(effect_dialog_get_type());
178 klass->apply = map_channels_dialog_apply;
179 klass->setup = map_channels_setup;
180 klass->target_changed = map_channels_dialog_target_changed;
181 }
182
map_channels_dialog_init(MapChannelsDialog * obj)183 static void map_channels_dialog_init(MapChannelsDialog *obj)
184 {
185 }
186
map_channels_dialog_get_type(void)187 GtkType map_channels_dialog_get_type(void)
188 {
189 static GtkType id = 0;
190 if (!id) {
191 GtkTypeInfo info = {
192 "MapChannelsDialog",
193 sizeof(MapChannelsDialog),
194 sizeof(MapChannelsDialogClass),
195 (GtkClassInitFunc)map_channels_dialog_class_init,
196 (GtkObjectInitFunc)map_channels_dialog_init
197 };
198 id = gtk_type_unique(effect_dialog_get_type(),&info);
199 }
200 return id;
201 }
202