~ubuntu-branches/ubuntu/hardy/gnomad2/hardy

« back to all changes in this revision

Viewing changes to src/player.c

  • Committer: Bazaar Package Importer
  • Author(s): Shaun Jackman
  • Date: 2005-08-19 16:09:28 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050819160928-l2glu227nh0algdc
Tags: 2.8.0-2
Add a versioned dependency for libnjb-dev (>> 2.2). Closes: #324036.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
} eax_adjust_props_t;
28
28
 
29
29
static gboolean playing = FALSE;
 
30
static GSList *exclusive_patches = NULL;
 
31
// Previous (since last callback) position in the file as percent
 
32
static guint prevpos;
30
33
 
31
34
/* option values */
32
35
static void patch_changed (gpointer combo,
33
36
                           gpointer data)
34
37
{
 
38
  GSList *tmplist;
 
39
  gboolean was_exclusive = FALSE;
35
40
  guint effect = GPOINTER_TO_UINT(data);
36
41
#if ! GTK_CHECK_VERSION(2,4,0)
37
42
  guint patch = gtk_option_menu_get_history(GTK_OPTION_MENU(combo));
38
43
#else
39
44
  guint patch = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
40
45
#endif
 
46
  // See if it is exclusive
 
47
  tmplist = exclusive_patches;
 
48
  while (tmplist != NULL) {
 
49
    if (combo == tmplist->data) {
 
50
      was_exclusive = TRUE;
 
51
    }
 
52
    tmplist = g_slist_next(tmplist);
 
53
  }
 
54
  // OK it was exclusive, reset all other exclusive patches...
 
55
  if (was_exclusive) {
 
56
    tmplist = exclusive_patches;
 
57
    // Reset all
 
58
    while (tmplist != NULL) {
 
59
      if (combo != tmplist->data) {
 
60
        // Reset it
 
61
#if ! GTK_CHECK_VERSION(2,4,0)
 
62
        gtk_option_menu_set_history(GTK_OPTION_MENU(tmplist->data), 0);
 
63
#else
 
64
        gtk_combo_box_set_active(GTK_COMBO_BOX(tmplist->data), 0);
 
65
#endif
 
66
      }
 
67
      tmplist = g_slist_next(tmplist);
 
68
    }
 
69
    // Then make sure it is set
 
70
#if ! GTK_CHECK_VERSION(2,4,0)
 
71
    gtk_option_menu_set_history(GTK_OPTION_MENU(combo), patch);
 
72
#else
 
73
    gtk_combo_box_set_active(GTK_COMBO_BOX(combo), patch);
 
74
#endif
 
75
  }
41
76
  
42
77
  if (playing) {
43
78
    // Wire scalevalue to 0
44
 
    g_print("Selecting patch %d for effect %04X\n", patch, effect);
 
79
    // g_print("Selecting patch %d for effect %04X\n", patch, effect);
45
80
    jukebox_adjust_eax(effect, patch, 0);
46
81
  }
47
82
}
163
198
  gint16 scalevalue = (gint16) adj->value;
164
199
 
165
200
  if (playing) {
166
 
    g_print("Setting scalevalue for effect %04X to %d\n", 
167
 
            adjprops->effect, scalevalue);
 
201
    //g_print("Setting scalevalue for effect %04X to %d\n", 
 
202
    //  adjprops->effect, scalevalue);
168
203
    jukebox_adjust_eax(adjprops->effect, 0, scalevalue);
169
204
  }
170
205
}
174
209
{
175
210
  eax_adjust_props_t *adjprops = (eax_adjust_props_t *) data;
176
211
 
177
 
  g_print("Destroying adjprops for %04X\n", adjprops->effect);
 
212
  //g_print("Destroying adjprops for %04X\n", adjprops->effect);
178
213
  g_free(adjprops);
179
214
}
180
215
 
254
289
#define VERTICAL   0x01
255
290
  u_int8_t last_direction = HORIZONTAL;
256
291
 
 
292
  // Clear old exclusive list...
 
293
  if (exclusive_patches != NULL) {
 
294
    g_slist_free(exclusive_patches);
 
295
    exclusive_patches = NULL;
 
296
  }
 
297
 
257
298
  // Stuff all EAX stuff into this frame
258
299
  hbox = gtk_hbox_new(FALSE, 5);
259
300
 
271
312
      // If this groups consists of scalevalues (we are guessing
272
313
      // that the first group member speaks for the rest), then create
273
314
      // a hbox, else (for patches etc) create a hbox.
274
 
      if (eax->scaleable != 0x00) {
 
315
      if (eax->type == NJB_EAX_SLIDER_CONTROL) {
275
316
        group_box = gtk_hbox_new(FALSE, 0);
276
317
        last_direction = HORIZONTAL;
277
318
      } else {
282
323
    // Then each effect with it's label is stuffed in a vbox
283
324
    vbox = gtk_vbox_new(FALSE, 0);
284
325
    // onoff values
285
 
    if (eax->selectable != 0x00 &&
286
 
        eax->min_selectionvalue == 0x00 &&
287
 
        eax->max_selectionvalue == 0x01) {
 
326
    if (eax->type == NJB_EAX_FIXED_OPTION_CONTROL &&
 
327
        eax->min_value == 0x00 &&
 
328
        eax->max_value == 0x01) {
288
329
      guint effect = (guint) eax->number;
289
330
 
290
331
      checkbox = gtk_check_button_new_with_label(eax->name);
291
 
      if (eax->current_selectionvalue != 0x00) {
 
332
      if (eax->current_value != 0x00) {
292
333
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), TRUE);
293
334
      }
294
335
      g_signal_connect(GTK_OBJECT(checkbox),
302
343
      gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.0f);
303
344
      gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
304
345
      // Patch value combobox
305
 
      if (eax->selectable != 0x00) {
 
346
      if (eax->type == NJB_EAX_FIXED_OPTION_CONTROL) {
306
347
        guint i;
307
348
        GSList *names = NULL;
 
349
        GtkWidget *patches;
308
350
        
309
 
        for(i = 0; i < eax->max_selectionvalue - eax->min_selectionvalue + 1; i++) {
310
 
          names = g_slist_append(names, g_strdup(eax->selection_names[i]));
 
351
        for(i = 0; i < eax->max_value - eax->min_value + 1; i++) {
 
352
          names = g_slist_append(names, g_strdup(eax->option_names[i]));
311
353
        }
312
 
        GtkWidget *patches = create_patch_menu(eax->number,
313
 
                                               names,
314
 
                                               GTK_SIGNAL_FUNC(patch_changed),
315
 
                                               eax->current_selectionvalue);
 
354
        patches = create_patch_menu(eax->number,
 
355
                                    names,
 
356
                                    GTK_SIGNAL_FUNC(patch_changed),
 
357
                                    eax->current_value);
316
358
        gtk_box_pack_start(GTK_BOX(vbox), patches, TRUE, TRUE, 0);
 
359
        if (eax->exclusive) {
 
360
          // Add to list of exclusive stuff
 
361
          exclusive_patches = g_slist_append(exclusive_patches, (gpointer) patches);
 
362
        }
317
363
      }
318
364
      // Scale value slider
319
 
      if (eax->scaleable != 0x00) {
 
365
      if (eax->type == NJB_EAX_SLIDER_CONTROL) {
320
366
        GtkWidget *slider;
321
367
        
322
 
        g_print("Scalevalue %s, min %d, max %d, current %d\n",
323
 
                eax->name, eax->min_scalevalue, eax->max_scalevalue,
324
 
                eax->current_scalevalue);
 
368
        // g_print("Scalevalue %s, min %d, max %d, current %d\n",
 
369
        //      eax->name, eax->min_scalevalue, eax->max_scalevalue,
 
370
        //      eax->current_scalevalue);
325
371
        slider = create_adjustment_control(eax->number,
326
 
                                           eax->min_scalevalue,
327
 
                                           eax->max_scalevalue,
328
 
                                           eax->current_scalevalue);
 
372
                                           eax->min_value,
 
373
                                           eax->max_value,
 
374
                                           eax->current_value);
329
375
        gtk_box_pack_start(GTK_BOX(vbox), slider, TRUE, TRUE, 0);
330
376
        gtk_widget_show(slider);
331
377
      }
343
389
  return hbox;
344
390
}
345
391
 
 
392
static void adjust_position (GtkAdjustment *adj,
 
393
                             gpointer data)
 
394
{
 
395
  // eax_adjust_props_t *adjprops = (eax_adjust_props_t *) data;
 
396
  // gint16 scalevalue = adjprops->max+1 - ((gint16) adj->value);
 
397
  gint16 pos = (gint16) adj->value;
 
398
  // Calculate the byte position offset
 
399
  guint delta = 0;
 
400
  guint skipto = 0;
 
401
  
 
402
  // If we just passed a track boundary there is no delta,
 
403
  // else we find out how much the position has changed.
 
404
  if ((prevpos == 100 || prevpos == 99) && (pos == 0  || pos == 1)) {
 
405
    delta = 0;
 
406
  } else if (pos >= prevpos) {
 
407
    delta = pos - prevpos;
 
408
  } else if (pos < prevpos) {
 
409
    delta = prevpos - pos;
 
410
  }
 
411
 
 
412
  // If someone has dragged the progress bar, delta will be more
 
413
  // than 2 percent (let's say).
 
414
  if (delta > 2) {
 
415
    skipto = pos;
 
416
  }
 
417
 
 
418
  // If we're skipping backward or forward, execute this.
 
419
  if (playing && skipto > 0) {
 
420
    metadata_t *meta = jukebox_get_current_playing_metadata();
 
421
    guint seconds = mmss_to_seconds(meta->length);
 
422
    guint mspos = (seconds * 1000 * skipto) / 100;
 
423
    g_print("Skipping to millisecond offset %d in track\n", mspos);
 
424
    // Call NJB
 
425
    jukebox_skip_songposition(mspos);
 
426
  }
 
427
  prevpos = pos;
 
428
}
 
429
 
 
430
 
346
431
/* Creates a complicated player window */
347
432
void create_player_window(GList *metalist)
348
433
{
368
453
   * (upper - page_size). */
369
454
  adj = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
370
455
  hscale = gtk_hscale_new (GTK_ADJUSTMENT (adj));
371
 
  gtk_widget_set_sensitive(hscale, FALSE);
 
456
  // To make it possible to skip into the song
 
457
  // gtk_widget_set_sensitive(hscale, FALSE);
 
458
  g_signal_connect_data(GTK_OBJECT(adj),
 
459
                        "value_changed",
 
460
                        G_CALLBACK(adjust_position),
 
461
                        NULL, // data
 
462
                        NULL, // destructor
 
463
                        0);
372
464
  gtk_widget_set_usize (GTK_WIDGET (hscale), 200, 30);
373
465
  gtk_range_set_update_policy (GTK_RANGE (hscale),
374
466
                               GTK_UPDATE_CONTINUOUS);
376
468
  gtk_scale_set_value_pos (GTK_SCALE(hscale), GTK_POS_TOP);
377
469
  gtk_scale_set_draw_value (GTK_SCALE(hscale), FALSE);
378
470
  gtk_widget_show (hscale);
 
471
#if GTK_CHECK_VERSION(2,6,0)
 
472
  button =  gtk_button_new_from_stock(GTK_STOCK_MEDIA_STOP);
 
473
#else
379
474
  button = gtk_button_new_with_label(_("STOP"));
 
475
#endif
380
476
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
381
477
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), button,
382
478
                      FALSE, FALSE, 0);
402
498
  /* Manouver panel */
403
499
  hbox2 = gtk_hbox_new(FALSE, 0);
404
500
 
 
501
#if GTK_CHECK_VERSION(2,6,0)
 
502
  button =  gtk_button_new_from_stock(GTK_STOCK_MEDIA_PREVIOUS);
 
503
#else
405
504
  button = gtk_button_new();
406
505
  hbox3 = gtk_hbox_new(FALSE, 0);
407
506
  arrow = gtk_arrow_new(GTK_ARROW_LEFT, GTK_SHADOW_NONE);
410
509
  gtk_box_pack_start(GTK_BOX(hbox3), label, TRUE, TRUE, 0);
411
510
  gtk_widget_show(arrow);
412
511
  gtk_container_add(GTK_CONTAINER(button), hbox3);
 
512
#endif
413
513
  g_signal_connect_object(GTK_OBJECT(button),
414
514
                          "clicked",
415
515
                          G_CALLBACK(prevbutton_click),
419
519
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
420
520
  label3 = gtk_label_new("00:00:00");
421
521
  gtk_box_pack_start(GTK_BOX(hbox2), label3, TRUE, TRUE, 0);
 
522
#if GTK_CHECK_VERSION(2,6,0)
 
523
  button =  gtk_button_new_from_stock(GTK_STOCK_MEDIA_NEXT);
 
524
#else
422
525
  button = gtk_button_new();
423
526
  hbox3 = gtk_hbox_new(FALSE, 0);
424
527
  label = gtk_label_new(_("NEXT"));
427
530
  gtk_box_pack_start(GTK_BOX(hbox3), arrow, TRUE, TRUE, 0);
428
531
  gtk_widget_show(arrow);
429
532
  gtk_container_add(GTK_CONTAINER(button), hbox3);
 
533
#endif
430
534
  g_signal_connect_object(GTK_OBJECT(button),
431
535
                          "clicked",
432
536
                          G_CALLBACK(nextbutton_click),