~ubuntu-branches/ubuntu/precise/gnome-control-center/precise-updates

« back to all changes in this revision

Viewing changes to capplets/sound/mixer-support.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-05-02 17:07:13 UTC
  • Revision ID: james.westby@ubuntu.com-20070502170713-t7f816n7kr57w340
Tags: upstream-2.19.1
ImportĀ upstreamĀ versionĀ 2.19.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* mixer-support.c
 
2
 *
 
3
 * Copyright (C) 2007 Jan Arne Petersen <jap@gnome.org>
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2, or (at your option)
 
8
 * any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
18
 * 02111-1307, USA.
 
19
 */
 
20
 
 
21
#ifdef HAVE_CONFIG_H
 
22
#include "config.h"
 
23
#endif
 
24
 
 
25
#include <string.h>
 
26
 
 
27
#include <glib/glist.h>
 
28
#include <glib/gi18n.h>
 
29
#include <gst/audio/mixerutils.h>
 
30
 
 
31
#include <gtk/gtkliststore.h>
 
32
 
 
33
#include "mixer-support.h"
 
34
 
 
35
GtkTreeModel *
 
36
create_mixer_device_tree_model (void)
 
37
{
 
38
  GtkListStore *device_store;
 
39
  GList *mixer_list, *l;
 
40
  guint unknown = 0;
 
41
 
 
42
  device_store = gtk_list_store_new (MIXER_DEVICE_MODEL_COLUMN_COUNT,
 
43
      G_TYPE_STRING, G_TYPE_STRING, GST_TYPE_ELEMENT);
 
44
 
 
45
  mixer_list = gst_audio_default_registry_mixer_filter(NULL, FALSE, NULL);
 
46
 
 
47
  for (l = mixer_list; l != NULL; l = l->next) {
 
48
    GstElement *mixer = GST_ELEMENT (l->data);
 
49
    gchar *device_name = NULL, *device = NULL;
 
50
    GstElementFactory *factory;
 
51
    const gchar *longname, *factory_name;
 
52
    gchar *name;
 
53
    GtkTreeIter tree_iter;
 
54
 
 
55
    gst_element_set_state (mixer, GST_STATE_READY);
 
56
 
 
57
    /* fetch name */
 
58
    if (g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (mixer)), "device-name")) {
 
59
      g_object_get (mixer, "device-name", &device_name, NULL);
 
60
    }
 
61
    if (g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (mixer)), "device")) {
 
62
      g_object_get (mixer, "device", &device, NULL);
 
63
    }
 
64
 
 
65
    factory = gst_element_get_factory (mixer);
 
66
    longname = gst_element_factory_get_longname (factory);
 
67
    factory_name = gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)); 
 
68
 
 
69
    /* gst_element_set_state (mixer, GST_STATE_NULL); */
 
70
 
 
71
    if (device_name) {
 
72
      name = g_strdup_printf ("%s (%s)", device_name, longname);
 
73
      g_free (device_name);
 
74
    } else {
 
75
      gchar *title;
 
76
 
 
77
      unknown++;
 
78
 
 
79
      title = g_strdup_printf (_("Unknown Volume Control %d"), unknown);
 
80
      name = g_strdup_printf ("%s (%s)", title, longname);
 
81
      g_free (title);
 
82
    }
 
83
 
 
84
    if (device) {
 
85
      gchar *tmp;
 
86
 
 
87
      tmp = g_strdup_printf ("%s:%s", factory_name, device);
 
88
      g_free (device);
 
89
      device = tmp;
 
90
    } else {
 
91
      device = g_strdup (factory_name); 
 
92
    }
 
93
 
 
94
    gtk_list_store_insert_with_values (device_store, &tree_iter, -1, 
 
95
        MIXER_DEVICE_MODEL_NAME_COLUMN, name,
 
96
        MIXER_DEVICE_MODEL_DEVICE_COLUMN, device,
 
97
        MIXER_DEVICE_MODEL_MIXER_COLUMN, mixer,
 
98
        -1);
 
99
 
 
100
    gst_element_set_state (mixer, GST_STATE_NULL);
 
101
    gst_object_unref (GST_OBJECT (mixer));
 
102
 
 
103
    g_free (name);
 
104
    g_free (device);
 
105
  }
 
106
 
 
107
  g_list_free (mixer_list);
 
108
 
 
109
  return GTK_TREE_MODEL (device_store);
 
110
}
 
111
 
 
112
GtkTreeModel *
 
113
create_mixer_tracks_tree_model_for_mixer (GstMixer *mixer)
 
114
{
 
115
  GtkListStore *tracks_store;
 
116
  const GList *tracks, *l;
 
117
 
 
118
  tracks_store = gtk_list_store_new (MIXER_TRACKS_MODEL_COLUMN_COUNT,
 
119
      G_TYPE_STRING);
 
120
 
 
121
  tracks = gst_mixer_list_tracks (mixer);
 
122
  for (l = tracks; l != NULL; l = l->next) {
 
123
    GstMixerTrack *track = l->data;
 
124
    GtkTreeIter iter;
 
125
 
 
126
    if (track->num_channels <= 0) {
 
127
      continue;
 
128
    }
 
129
 
 
130
    gtk_list_store_insert_with_values (tracks_store, &iter, -1,
 
131
        MIXER_TRACKS_MODEL_LABEL_COLUMN, track->label,
 
132
        -1);
 
133
  }
 
134
 
 
135
  return GTK_TREE_MODEL (tracks_store);
 
136
}