~ubuntu-branches/debian/stretch/gnac/stretch

« back to all changes in this revision

Viewing changes to src/profiles/formats/gnac-profiles-wavpack.c

  • Committer: Package Import Robot
  • Author(s): Khalid El Fathi
  • Date: 2012-04-14 20:15:31 UTC
  • Revision ID: package-import@ubuntu.com-20120414201531-2gcfq8fs94kgp9qr
Tags: upstream-0.2.4
ImportĀ upstreamĀ versionĀ 0.2.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of GNAC - Gnome Audio Converter
 
3
 *
 
4
 * Copyright (C) 2007 - 2012 Gnac
 
5
 *    
 
6
 *    - DUPASQUIER  Benoit    <bdupasqu@src.gnome.org>
 
7
 *    - JOAQUIM     David     <djoaquim@src.gnome.org>
 
8
 *    - ROUX        Alexandre <alexroux@src.gnome.org>
 
9
 *
 
10
 * GNAC is free software; you can redistribute it and/or modify
 
11
 * it under the terms of the GNU General Public License as published by
 
12
 * the Free Software Foundation; either version 3 of the License, or
 
13
 * (at your option) any later version.
 
14
 *
 
15
 * GNAC is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 * GNU General Public License for more details.
 
19
 *
 
20
 * You should have received a copy of the GNU General Public License
 
21
 * along with GNAC; if not, write to the Free Software
 
22
 * Foundation, Inc., 51 Franklin St, Fifth Floor, 
 
23
 * Boston, MA  02110-1301  USA
 
24
 */
 
25
 
 
26
#include <glib/gstdio.h>
 
27
 
 
28
#include "../gnac-profiles-properties.h"
 
29
#include "gnac-profiles-wavpack.h"
 
30
 
 
31
 
 
32
typedef struct
 
33
{
 
34
  AudioProfileGeneric *generic;
 
35
 
 
36
  gchar   *mode;
 
37
  gdouble  bitrate;
 
38
  gdouble  bits_per_sample;
 
39
  gdouble  extra_processing;
 
40
  gchar   *joint_stereo_mode;
 
41
  gchar   *md5;
 
42
}
 
43
AudioProfileWavpack;
 
44
 
 
45
typedef enum {
 
46
  AVERAGE_BITRATE,
 
47
  BITS_PER_SAMPLE
 
48
} ControlMethod;
 
49
 
 
50
BasicFormatInfo wavpack_bfi = {
 
51
  PKGDATADIR "/profiles/gnac-profiles-wavpack.xml",
 
52
  NULL,
 
53
  PKGDATADIR "/profiles/wavpack.xml",
 
54
  NULL,
 
55
  NULL,
 
56
  NULL,
 
57
  NULL,
 
58
  NULL,
 
59
  NULL,
 
60
  NULL,
 
61
  NULL,
 
62
  NULL
 
63
};
 
64
 
 
65
 
 
66
static void
 
67
gnac_profiles_wavpack_bitrate_control_on_changed(GtkComboBox *widget);
 
68
 
 
69
static AudioProfileWavpack *
 
70
gnac_profiles_wavpack_audio_profile_new(void);
 
71
 
 
72
 
 
73
void
 
74
gnac_profiles_wavpack_on_bitrate_control_changed(GtkComboBox *widget,
 
75
                                                 gpointer     user_data)
 
76
{
 
77
  gnac_profiles_wavpack_bitrate_control_on_changed(widget);
 
78
  gnac_profiles_wavpack_generate_pipeline();
 
79
}
 
80
 
 
81
 
 
82
static const gchar *
 
83
gnac_profiles_wavpack_init(void)
 
84
{
 
85
  GtkWidget *widget;
 
86
  GtkWidget *widget2;
 
87
 
 
88
  gnac_profiles_default_init(&wavpack_bfi);
 
89
 
 
90
  // Encoding mode
 
91
  gnac_profiles_utils_init_widget(&wavpack_bfi, "combo-mode",
 
92
      "//variable[@id='mode']");
 
93
 
 
94
  // Bitrate
 
95
  gnac_profiles_utils_init_widget(&wavpack_bfi, "slider-bitrate",
 
96
      "//variable[@id='bitrate']");
 
97
 
 
98
  // Bits per sample
 
99
  gnac_profiles_utils_init_widget(&wavpack_bfi, "slider-bits-per-sample",
 
100
      "//variable[@id='bits-per-sample']");
 
101
 
 
102
  // Extra processing
 
103
  widget = gnac_profiles_utils_init_widget(&wavpack_bfi,
 
104
      "slider-extra-processing", "//variable[@id='extra-processing']");
 
105
  widget2 = gnac_profiles_utils_get_widget(&wavpack_bfi,
 
106
      "label-extra-processing"),
 
107
  gnac_profiles_utils_add_description_tooltip(&wavpack_bfi,
 
108
      "//variable[@id='extra-processing']/description",
 
109
      widget, widget2, NULL);
 
110
 
 
111
  // Joint stereo mode
 
112
  gnac_profiles_utils_init_widget(&wavpack_bfi,
 
113
      "combo-joint-stereo-mode", "//variable[@id='joint-stereo-mode']");
 
114
 
 
115
  // MD5
 
116
  widget = gnac_profiles_utils_init_widget(&wavpack_bfi, "checkbutton-md5",
 
117
      "//variable[@id='md5']");
 
118
  gnac_profiles_utils_add_description_tooltip(&wavpack_bfi,
 
119
      "//variable[@id='md5']/description", widget, NULL);
 
120
 
 
121
 // Bitrate control
 
122
  widget = gnac_profiles_utils_init_widget(&wavpack_bfi,
 
123
      "combo-bitrate-control", "//variable[@id='bitrate-control']");
 
124
  widget2 = gnac_profiles_utils_get_widget(&wavpack_bfi,
 
125
      "checkbutton-bitrate-control");
 
126
  gnac_profiles_wavpack_bitrate_control_on_toggle(widget,
 
127
      GTK_TOGGLE_BUTTON(widget2));
 
128
 
 
129
  gnac_profiles_xml_engine_free_doc_xpath(wavpack_bfi.doc);
 
130
  wavpack_bfi.doc = NULL;
 
131
 
 
132
  return wavpack_bfi.format_id;
 
133
}
 
134
 
 
135
 
 
136
static void
 
137
gnac_profiles_wavpack_show_abr_widgets(gboolean show)
 
138
{
 
139
  GtkWidget *abr_widgets[] = {
 
140
    gnac_profiles_utils_get_widget(&wavpack_bfi, "label-bitrate"),
 
141
    gnac_profiles_utils_get_widget(&wavpack_bfi, "slider-bitrate"),
 
142
    gnac_profiles_utils_get_widget(&wavpack_bfi, "label-bits-per-sample"),
 
143
    gnac_profiles_utils_get_widget(&wavpack_bfi, "slider-bits-per-sample"),
 
144
  };
 
145
 
 
146
  guint i;
 
147
  for (i = 0; i < G_N_ELEMENTS(abr_widgets); i++) {
 
148
    if (show) gtk_widget_show_all(abr_widgets[i]);
 
149
    else gtk_widget_hide(abr_widgets[i]);
 
150
  }
 
151
}
 
152
 
 
153
 
 
154
static void
 
155
gnac_profiles_wavpack_show_bps_widgets(gboolean show)
 
156
{
 
157
  GtkWidget *bps_widgets[] = {
 
158
    gnac_profiles_utils_get_widget(&wavpack_bfi, "label-bits-per-sample"),
 
159
    gnac_profiles_utils_get_widget(&wavpack_bfi, "slider-bits-per-sample"),
 
160
  };
 
161
 
 
162
  guint i;
 
163
  for (i = 0; i < G_N_ELEMENTS(bps_widgets); i++) {
 
164
    if (show) gtk_widget_show_all(bps_widgets[i]);
 
165
    else gtk_widget_hide(bps_widgets[i]);
 
166
  }
 
167
}
 
168
 
 
169
 
 
170
static void
 
171
gnac_profiles_wavpack_bitrate_control_on_changed(GtkComboBox *widget)
 
172
{
 
173
  GtkToggleButton *bitrate_ctrl_btn = GTK_TOGGLE_BUTTON(
 
174
      gnac_profiles_utils_get_widget(&wavpack_bfi, "checkbutton-bitrate-control"));
 
175
  gboolean bitrate_ctrl_enabled = gtk_toggle_button_get_active(bitrate_ctrl_btn);
 
176
  ControlMethod control_method = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
 
177
  
 
178
  gnac_profiles_wavpack_show_abr_widgets(
 
179
      bitrate_ctrl_enabled && control_method == AVERAGE_BITRATE);
 
180
  gnac_profiles_wavpack_show_bps_widgets(
 
181
      bitrate_ctrl_enabled && control_method == BITS_PER_SAMPLE);
 
182
}
 
183
 
 
184
 
 
185
void
 
186
gnac_profiles_wavpack_generate_pipeline(void)
 
187
{
 
188
  gchar *pipeline = gnac_profiles_default_generate_pipeline(&wavpack_bfi);
 
189
  GtkWidget *widget = gnac_profiles_utils_get_widget(&wavpack_bfi,
 
190
      "combo-bitrate-control");
 
191
 
 
192
  pipeline = gnac_profiles_utils_add_properties(pipeline, &wavpack_bfi,
 
193
      "combo-mode",  NULL);
 
194
  pipeline = gnac_profiles_utils_add_properties_slider(pipeline, &wavpack_bfi, 
 
195
      "%.0f", "slider-extra-processing", NULL);
 
196
  pipeline = gnac_profiles_utils_add_properties_checked_combo(pipeline,
 
197
      &wavpack_bfi,
 
198
      "combo-joint-stereo-mode", "checkbutton-joint-stereo-mode",
 
199
      NULL);
 
200
  pipeline = gnac_profiles_utils_add_properties(pipeline, &wavpack_bfi,
 
201
      "checkbutton-md5", NULL);
 
202
  GtkWidget *check = gnac_profiles_utils_get_widget(&wavpack_bfi,
 
203
      "checkbutton-bitrate-control");
 
204
 
 
205
  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check))) {
 
206
    ControlMethod control_method = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
 
207
 
 
208
    if (control_method == AVERAGE_BITRATE) {
 
209
      widget = gnac_profiles_utils_get_widget(&wavpack_bfi, "slider-bitrate");
 
210
      pipeline = gnac_profiles_utils_add_property_slider(pipeline,
 
211
          "%.0f", 1000, widget);
 
212
    } else {
 
213
      pipeline = gnac_profiles_utils_add_properties_slider(pipeline,
 
214
          &wavpack_bfi, "%.0f", "slider-bits-per-sample", NULL);
 
215
    }
 
216
  }
 
217
 
 
218
  gnac_profiles_properties_update_textbuffer(pipeline);
 
219
 
 
220
  g_free(wavpack_bfi.pipeline);
 
221
 
 
222
  wavpack_bfi.pipeline = pipeline;
 
223
}
 
224
 
 
225
 
 
226
void
 
227
gnac_profiles_wavpack_bitrate_control_on_toggle(GtkWidget       *widget,
 
228
                                                GtkToggleButton *togglebutton)
 
229
{
 
230
  GtkWidget *label = gnac_profiles_utils_get_widget(&wavpack_bfi,
 
231
      "label-control-method");
 
232
  GtkWidget *hbox = gnac_profiles_utils_get_widget(&wavpack_bfi,
 
233
      "hbox-control-method");
 
234
 
 
235
  if (gtk_toggle_button_get_active(togglebutton)) {
 
236
    gtk_widget_show(hbox);
 
237
    gtk_widget_show(label);
 
238
  } else {
 
239
    gtk_widget_hide(hbox);
 
240
    gtk_widget_hide(label);
 
241
  }
 
242
 
 
243
  gnac_profiles_wavpack_bitrate_control_on_changed(GTK_COMBO_BOX(widget));
 
244
  gnac_profiles_wavpack_generate_pipeline();
 
245
}
 
246
 
 
247
 
 
248
void
 
249
gnac_profiles_wavpack_joint_stereo_mode_on_toggle(GtkWidget       *widget,
 
250
                                                  GtkToggleButton *togglebutton)
 
251
{
 
252
  gnac_profiles_utils_on_toggle_optionnal_property(togglebutton, widget);
 
253
  gnac_profiles_wavpack_generate_pipeline();
 
254
}
 
255
 
 
256
 
 
257
static void
 
258
gnac_profiles_wavpack_reset_ui(void)
 
259
{
 
260
  gnac_profiles_default_reset_ui(&wavpack_bfi);
 
261
  gnac_profiles_utils_reset_values(&wavpack_bfi,
 
262
      "combo-mode", "combo-bitrate-control", "combo-joint-stereo-mode",
 
263
      "checkbutton-md5", "slider-bitrate", "slider-bits-per-sample",
 
264
      "slider-extra-processing", NULL);
 
265
  gnac_profiles_utils_set_active_toggle_button(&wavpack_bfi, FALSE,
 
266
      "checkbutton-bitrate-control", NULL);
 
267
}
 
268
 
 
269
 
 
270
static void
 
271
gnac_profiles_wavpack_set_fields(gpointer data)
 
272
{
 
273
  if (!data) {
 
274
    gnac_profiles_wavpack_reset_ui();
 
275
    return;
 
276
  }
 
277
 
 
278
  AudioProfileWavpack *profile = (AudioProfileWavpack *) data;
 
279
  gnac_profiles_utils_set_values(&wavpack_bfi,
 
280
      "combo-mode", profile->mode,
 
281
      "slider-extra-processing", profile->extra_processing,
 
282
      "checkbutton-md5", profile->md5, NULL);
 
283
  gnac_profiles_utils_set_values_checked(&wavpack_bfi,
 
284
      "combo-joint-stereo-mode", "checkbutton-joint-stereo-mode",
 
285
      profile->joint_stereo_mode, NULL);
 
286
 
 
287
  GtkWidget *widget = gnac_profiles_utils_get_widget(&wavpack_bfi,
 
288
      "combo-bitrate-control");
 
289
  GtkWidget *check = gnac_profiles_utils_get_widget(&wavpack_bfi,
 
290
      "checkbutton-bitrate-control");
 
291
 
 
292
  if (profile->bitrate != -1.0) {
 
293
    gnac_profiles_utils_set_values(&wavpack_bfi,
 
294
        "slider-bitrate", profile->bitrate, NULL);
 
295
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), TRUE);
 
296
    gtk_combo_box_set_active(GTK_COMBO_BOX(widget), AVERAGE_BITRATE);
 
297
  } else if (profile->bits_per_sample != -1) {
 
298
    gnac_profiles_utils_set_values(&wavpack_bfi,
 
299
        "slider-bits-per-sample", profile->bits_per_sample, NULL);
 
300
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), TRUE);
 
301
    gtk_combo_box_set_active(GTK_COMBO_BOX(widget), BITS_PER_SAMPLE);
 
302
  }
 
303
}
 
304
 
 
305
 
 
306
static gchar *
 
307
gnac_profiles_wavpack_get_combo_format_name(void)
 
308
{
 
309
  return gnac_profiles_default_get_combo_format_name(&wavpack_bfi);
 
310
}
 
311
 
 
312
 
 
313
static AudioProfileWavpack *
 
314
gnac_profiles_wavpack_audio_profile_new(void)
 
315
{
 
316
  AudioProfileWavpack *profile = g_malloc(sizeof(AudioProfileWavpack));
 
317
  
 
318
  profile->mode = NULL;
 
319
  profile->bitrate = -1;
 
320
  profile->bits_per_sample = -1;
 
321
  profile->extra_processing = -1;
 
322
  profile->joint_stereo_mode = NULL;
 
323
  profile->md5 = NULL;
 
324
 
 
325
  return profile;
 
326
}
 
327
 
 
328
 
 
329
static void
 
330
gnac_profiles_wavpack_free_audio_profile(gpointer data)
 
331
{
 
332
  if (!data) return;
 
333
 
 
334
  AudioProfileWavpack *profile = (AudioProfileWavpack *) data;
 
335
  gnac_profiles_utils_free_audio_profile_generic(profile->generic); 
 
336
  g_free(profile->mode);
 
337
  g_free(profile->joint_stereo_mode);
 
338
  g_free(profile->md5);
 
339
  g_free(profile);
 
340
}
 
341
 
 
342
 
 
343
static gpointer
 
344
gnac_profiles_wavpack_generate_audio_profile(GError **error)
 
345
{
 
346
  AudioProfileGeneric *generic = gnac_profiles_default_generate_audio_profile(
 
347
      &wavpack_bfi);
 
348
  AudioProfileWavpack *profile = gnac_profiles_wavpack_audio_profile_new();
 
349
  profile->generic = generic;
 
350
 
 
351
  gnac_profiles_utils_get_values_and_set(&wavpack_bfi,
 
352
      "combo-mode", &profile->mode,
 
353
      "slider-extra-processing", &profile->extra_processing,
 
354
      "checkbutton-md5", &profile->md5, NULL);
 
355
  gnac_profiles_utils_get_values_checked_combo_and_set(&wavpack_bfi,
 
356
      "combo-joint-stereo-mode", "checkbutton-joint-stereo-mode",
 
357
      &profile->joint_stereo_mode, NULL);
 
358
 
 
359
  GtkWidget *widget = gnac_profiles_utils_get_widget(&wavpack_bfi,
 
360
      "combo-bitrate-control");
 
361
  GtkWidget *check = gnac_profiles_utils_get_widget(&wavpack_bfi,
 
362
      "checkbutton-bitrate-control");
 
363
 
 
364
  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check))) {
 
365
    ControlMethod control_method = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
 
366
 
 
367
    if (control_method == AVERAGE_BITRATE) {
 
368
      gnac_profiles_utils_get_values_and_set(&wavpack_bfi,
 
369
          "slider-bitrate", &profile->bitrate, NULL);
 
370
    } else {
 
371
      gnac_profiles_utils_get_values_and_set(&wavpack_bfi,
 
372
          "slider-bits-per-sample", &profile->bits_per_sample, NULL);
 
373
    }
 
374
  }
 
375
 
 
376
  return profile;
 
377
}
 
378
 
 
379
 
 
380
static GtkWidget *
 
381
gnac_profiles_wavpack_get_widget(void)
 
382
{
 
383
  return gnac_profiles_default_get_properties_alignment(&wavpack_bfi);
 
384
}
 
385
 
 
386
 
 
387
static void
 
388
gnac_profiles_wavpack_save_profile(gpointer data)
 
389
{
 
390
  if (!data) return;
 
391
 
 
392
  gchar *bitrate = NULL;
 
393
  gchar *bits_per_sample = NULL;
 
394
  AudioProfileWavpack *profile = (AudioProfileWavpack *) data;
 
395
 
 
396
  if (profile->bitrate != -1) {
 
397
    bitrate = gnac_profiles_utils_gdouble_to_gchararray(profile->bitrate);
 
398
  } else if (profile->bits_per_sample != -1) {
 
399
    bits_per_sample = gnac_profiles_utils_gdouble_to_gchararray(
 
400
        profile->bits_per_sample);
 
401
  }
 
402
 
 
403
  gchar *extra_processing = gnac_profiles_utils_gdouble_to_gchararray(
 
404
      profile->extra_processing);
 
405
 
 
406
  XMLDoc *doc = gnac_profiles_default_save_profile(profile->generic,
 
407
      &wavpack_bfi);
 
408
  gnac_profiles_xml_engine_add_values(doc,
 
409
      "mode", profile->mode,
 
410
      "bitrate", bitrate,
 
411
      "bits-per-sample", bits_per_sample,
 
412
      "extra-processing", extra_processing,
 
413
      "joint-stereo-mode", profile->joint_stereo_mode,
 
414
      "md5", profile->md5,
 
415
      NULL);
 
416
  gnac_profiles_xml_engine_save_doc(doc, profile->generic->name);
 
417
 
 
418
  gnac_profiles_xml_engine_free_doc_xpath(doc);
 
419
  g_free(bitrate);
 
420
  g_free(bits_per_sample);
 
421
  g_free(extra_processing);
 
422
}
 
423
 
 
424
 
 
425
static gpointer
 
426
gnac_profiles_wavpack_load_specific_properties(XMLDoc              *doc,
 
427
                                               AudioProfileGeneric *generic)
 
428
{
 
429
  gchar *bitrate;
 
430
  gchar *bits_per_sample;
 
431
  gchar *extra_processing;
 
432
  
 
433
  AudioProfileWavpack *profile = gnac_profiles_wavpack_audio_profile_new();
 
434
  profile->generic = generic;
 
435
  gnac_profiles_utils_load_saved_profile(doc,
 
436
      "/audio-profile/format-specific/",
 
437
      "mode", &profile->mode,
 
438
      "bitrate", &bitrate,
 
439
      "bits-per-sample", &bits_per_sample,
 
440
      "extra-processing", &extra_processing,
 
441
      "joint-stereo-mode", &profile->joint_stereo_mode,
 
442
      "md5", &profile->md5,
 
443
      NULL);
 
444
 
 
445
  profile->extra_processing = gnac_profiles_utils_gchararray_to_gdouble(
 
446
      extra_processing);
 
447
  g_free(extra_processing);
 
448
 
 
449
  if (bitrate) {
 
450
    profile->bitrate = gnac_profiles_utils_gchararray_to_gdouble(bitrate);
 
451
    g_free(bitrate);
 
452
  } else if (bits_per_sample) {
 
453
    profile->bits_per_sample = gnac_profiles_utils_gchararray_to_gdouble(
 
454
        bits_per_sample);
 
455
    g_free(bits_per_sample);
 
456
  }
 
457
 
 
458
  return profile;
 
459
}
 
460
 
 
461
 
 
462
static void
 
463
gnac_profiles_wavpack_clean_up(void)
 
464
{
 
465
  gnac_profiles_default_clean_up(&wavpack_bfi);
 
466
  gnac_profiles_utils_free_values(&wavpack_bfi,
 
467
      "combo-bitrate-control", "combo-mode", "combo-joint-stereo-mode",
 
468
      "checkbutton-md5", "slider-bitrate", "slider-bits-per-sample",
 
469
      "slider-extra-processing", NULL);
 
470
  gnac_profiles_utils_free_basic_format_info(&wavpack_bfi);
 
471
}
 
472
 
 
473
 
 
474
static const gchar *
 
475
gnac_profiles_wavpack_get_plugin_name(void)
 
476
{
 
477
  return wavpack_bfi.format_plugin_name;
 
478
}
 
479
 
 
480
 
 
481
static const gchar *
 
482
gnac_profiles_wavpack_get_description(void)
 
483
{
 
484
  return wavpack_bfi.description;
 
485
}
 
486
 
 
487
 
 
488
FormatModuleFuncs
 
489
gnac_profiles_wavpack_get_funcs(void)
 
490
{
 
491
  FormatModuleFuncs funcs = {
 
492
    gnac_profiles_wavpack_init,
 
493
    gnac_profiles_wavpack_get_description,
 
494
    gnac_profiles_wavpack_generate_pipeline,
 
495
    gnac_profiles_wavpack_generate_audio_profile,
 
496
    gnac_profiles_wavpack_free_audio_profile,
 
497
    gnac_profiles_wavpack_set_fields,
 
498
    gnac_profiles_wavpack_get_widget,
 
499
    gnac_profiles_wavpack_save_profile,
 
500
    gnac_profiles_wavpack_load_specific_properties,
 
501
    gnac_profiles_wavpack_clean_up,
 
502
    NULL,
 
503
    gnac_profiles_wavpack_get_combo_format_name,
 
504
    gnac_profiles_wavpack_get_plugin_name
 
505
  };
 
506
 
 
507
  return funcs;
 
508
}