2
* Copyright (C) 2002 2003 2004 2005 2006, Magnus Hjorth
4
* This file is part of mhWaveEdit.
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26
#include "mainwindow.h"
27
#include "mapchannelsdialog.h"
28
#include "effectbrowser.h"
31
static GtkObjectClass *parent_class;
32
static gboolean *map_matrix = NULL;
34
static Chunk *map_channels_dialog_apply_proc(Chunk *chunk, StatusBar *bar,
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,
43
static gboolean map_channels_dialog_apply(EffectDialog *ed)
48
Document *d = EFFECT_BROWSER(ed->eb)->dl->selected;
49
MapChannelsDialog *mcd = MAP_CHANNELS_DIALOG(ed);
51
g_assert(mcd->channels_in == d->chunk->format.channels);
53
if (intbox_check(mcd->outchannels)) return TRUE;
55
map_matrix = g_malloc(mcd->channels_in*mcd->channels_out*
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]);
62
b = document_apply_cb(d,map_channels_dialog_apply_proc,FALSE,mcd);
70
static void map_channels_dialog_target_changed(EffectDialog *ed)
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),
78
static void numchannels_changed(Intbox *box, long int val, gpointer user_data)
80
MapChannelsDialog *mcd = MAP_CHANNELS_DIALOG(user_data);
83
mcd->channels_out = val;
88
gtk_widget_show(mcd->outnames[i]);
90
gtk_widget_hide(mcd->outnames[i]);
92
for (j=0; j<mcd->channels_in; j++) {
94
gtk_widget_show(GTK_WIDGET(mcd->channel_map[j*8+i]));
96
gtk_widget_hide(GTK_WIDGET(mcd->channel_map[j*8+i]));
101
static void map_channels_setup(EffectDialog *ed)
104
GtkWidget *z,*a,*b,*c,*d;
106
guint channels_in = EFFECT_BROWSER(ed->eb)->dl->format.channels;
107
MapChannelsDialog *mcd = MAP_CHANNELS_DIALOG(ed);
109
mcd->channels_in = channels_in;
110
mcd->channels_out = channels_in;
111
mcd->outchannels = INTBOX(intbox_new(8));
113
z = gtk_vbox_new(FALSE,5);
114
gtk_box_pack_start(GTK_BOX(ed->input_area),z,FALSE,FALSE,0);
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);
120
a = gtk_hbox_new(FALSE,3);
121
gtk_container_add(GTK_CONTAINER(z),a);
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);
130
a = gtk_frame_new(_("Map"));
131
gtk_container_add(GTK_CONTAINER(z),a);
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);
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);
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);
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);
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();
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,
165
gtk_table_set_col_spacings(GTK_TABLE(c),4);
167
gtk_widget_show_all(z);
169
gtk_signal_connect(GTK_OBJECT(mcd->outchannels),"numchanged",
170
GTK_SIGNAL_FUNC(numchannels_changed),mcd);
171
intbox_set(mcd->outchannels,mcd->channels_out);
175
static void map_channels_dialog_class_init(EffectDialogClass *klass)
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;
183
static void map_channels_dialog_init(MapChannelsDialog *obj)
187
GtkType map_channels_dialog_get_type(void)
189
static GtkType id = 0;
193
sizeof(MapChannelsDialog),
194
sizeof(MapChannelsDialogClass),
195
(GtkClassInitFunc)map_channels_dialog_class_init,
196
(GtkObjectInitFunc)map_channels_dialog_init
198
id = gtk_type_unique(effect_dialog_get_type(),&info);