Skip to content

Commit

Permalink
machine: add "pretty-name" property
Browse files Browse the repository at this point in the history
The property will contain the original name if the machine was renamed. E.g.
when using the 'hihat' preset from simsyn and thus naming the machine 'hihats',
the 'pretty-name' will be 'hihats (simsyn)'. This can be used for e.g. tooltips.

See issue #32
  • Loading branch information
ensonic committed Dec 20, 2014
1 parent a9c9e9d commit 2a5ec02
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 30 deletions.
52 changes: 42 additions & 10 deletions src/lib/core/machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ enum
MACHINE_OUTPUT_GAIN,
MACHINE_OUTPUT_POST_LEVEL,
MACHINE_PATTERNS,
MACHINE_STATE
MACHINE_STATE,
MACHINE_PRETTY_NAME
};

// adder, capsfiter, level, volume are gap-aware
Expand Down Expand Up @@ -687,8 +688,8 @@ bt_machine_insert_element (BtMachine * const self, GstPad * const peer,
bt_machine_link_elements (self, src_pads[pos],
sink_pads[post]))) {
if ((wire =
(self->dst_wires ? (BtWire *) (self->dst_wires->
data) : NULL))) {
(self->dst_wires ? (BtWire *) (self->
dst_wires->data) : NULL))) {
if (!(res = bt_wire_reconnect (wire))) {
GST_WARNING_OBJECT (self,
"failed to reconnect wire after linking '%s' before '%s'",
Expand Down Expand Up @@ -716,8 +717,8 @@ bt_machine_insert_element (BtMachine * const self, GstPad * const peer,
if ((res =
bt_machine_link_elements (self, src_pads[pre], sink_pads[pos]))) {
if ((wire =
(self->src_wires ? (BtWire *) (self->src_wires->
data) : NULL))) {
(self->src_wires ? (BtWire *) (self->
src_wires->data) : NULL))) {
if (!(res = bt_wire_reconnect (wire))) {
GST_WARNING_OBJECT (self,
"failed to reconnect wire after linking '%s' after '%s'",
Expand Down Expand Up @@ -1371,8 +1372,8 @@ bt_machine_init_global_params (const BtMachine * const self)
//g_assert(gst_child_proxy_get_children_count(GST_CHILD_PROXY(self->priv->machines[PART_MACHINE])));
// get child for voice 0
if ((voice_child =
gst_child_proxy_get_child_by_index (GST_CHILD_PROXY (self->priv->
machines[PART_MACHINE]), 0))) {
gst_child_proxy_get_child_by_index (GST_CHILD_PROXY (self->
priv->machines[PART_MACHINE]), 0))) {
child_properties =
g_object_class_list_properties (G_OBJECT_CLASS (GST_OBJECT_GET_CLASS
(voice_child)), &number_of_child_properties);
Expand Down Expand Up @@ -1434,8 +1435,8 @@ bt_machine_init_voice_params (const BtMachine * const self)
// register voice params
// get child for voice 0
if ((voice_child =
gst_child_proxy_get_child_by_index (GST_CHILD_PROXY (self->priv->
machines[PART_MACHINE]), 0))) {
gst_child_proxy_get_child_by_index (GST_CHILD_PROXY (self->
priv->machines[PART_MACHINE]), 0))) {
GParamSpec **properties;
guint number_of_properties;

Expand Down Expand Up @@ -3230,6 +3231,30 @@ bt_machine_get_property (GObject * const object, const guint property_id,
case MACHINE_STATE:
g_value_set_enum (value, self->priv->state);
break;
case MACHINE_PRETTY_NAME:{
GstPluginFeature *feature =
(GstPluginFeature *) gst_element_get_factory (self->priv->
machines[PART_MACHINE]);
// same as self->priv->plugin_name
const gchar *factory_name = gst_plugin_feature_get_name (feature);
const gchar *plugin_name = gst_plugin_feature_get_plugin_name (feature);
gint len = strlen (plugin_name);

// TODO(ensonic): see ui/edit/machine-menu.c:bt_machine_menu_init_submenu
// remove prefix "<plugin-name>-"
if (!strncasecmp (factory_name, plugin_name, len) &&
factory_name[len] == '-') {
factory_name = &factory_name[len + 1];
}
GST_INFO_OBJECT ("%s|%s", self->priv->id, factory_name);
if (!g_str_has_prefix (self->priv->id, factory_name)) {
g_value_take_string (value, g_strdup_printf ("%s (%s)",
self->priv->id, factory_name));
} else {
g_value_set_string (value, self->priv->id);
}
break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
Expand Down Expand Up @@ -3583,6 +3608,13 @@ bt_machine_class_init (BtMachineClass * const klass)
"a copy of the list of patterns",
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));

g_object_class_install_property (gobject_class, MACHINE_STATE, g_param_spec_enum ("state", "state prop", "the current state of this machine", BT_TYPE_MACHINE_STATE, /* enum type */
g_object_class_install_property (gobject_class, MACHINE_STATE,
g_param_spec_enum ("state", "state prop",
"the current state of this machine", BT_TYPE_MACHINE_STATE,
BT_MACHINE_STATE_NORMAL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

g_object_class_install_property (gobject_class, MACHINE_PRETTY_NAME,
g_param_spec_string ("pretty-name", "pretty-name prop",
"pretty-printed name for display purposes", NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}
2 changes: 1 addition & 1 deletion src/ui/edit/machine-menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ bt_machine_menu_init_submenu (const BtMachineMenu * self, GtkWidget * submenu,
GType type;
gboolean have_submenu;

/* list known gstreamer element that are not useful under buzztrax,
/* list of known gstreamer elements that are not useful under buzztrax,
* but we can't detect otherwise */
const gchar *blacklist[] = {
"audiorate",
Expand Down
8 changes: 4 additions & 4 deletions src/ui/edit/machine-preferences-dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,12 @@ on_machine_id_changed (const BtMachine * machine, GParamSpec * arg,
gpointer user_data)
{
BtMachinePreferencesDialog *self = BT_MACHINE_PREFERENCES_DIALOG (user_data);
gchar *id, *title;
gchar *name, *title;

g_object_get ((GObject *) machine, "id", &id, NULL);
title = g_strdup_printf (_("%s preferences"), id);
g_object_get ((GObject *) machine, "pretty-name", &name, NULL);
title = g_strdup_printf (_("%s preferences"), name);
gtk_window_set_title (GTK_WINDOW (self), title);
g_free (id);
g_free (name);
g_free (title);
}

Expand Down
8 changes: 4 additions & 4 deletions src/ui/edit/machine-properties-dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -2459,12 +2459,12 @@ on_machine_id_changed (const BtMachine * machine, GParamSpec * arg,
gpointer user_data)
{
BtMachinePropertiesDialog *self = BT_MACHINE_PROPERTIES_DIALOG (user_data);
gchar *id, *title;
gchar *name, *title;

g_object_get ((GObject *) machine, "id", &id, NULL);
title = g_strdup_printf (_("%s properties"), id);
g_object_get ((GObject *) machine, "pretty-name", &name, NULL);
title = g_strdup_printf (_("%s properties"), name);
gtk_window_set_title (GTK_WINDOW (self), title);
g_free (id);
g_free (name);
g_free (title);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui/edit/main-page-machines.c
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ on_canvas_query_tooltip (GtkWidget * widget, gint x, gint y,
if (!(ci = get_machine_canvas_item_under_cursor (self)))
return FALSE;

bt_child_proxy_get (ci, "machine::id", &name, NULL);
bt_child_proxy_get (ci, "machine::pretty_name", &name, NULL);
gtk_tooltip_set_text (tooltip, name);
g_free (name);
g_object_unref (ci);
Expand Down
23 changes: 13 additions & 10 deletions src/ui/edit/main-page-sequence.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,12 +808,13 @@ on_machine_id_changed_seq (BtMachine * machine, GParamSpec * arg,
gpointer user_data)
{
GtkEntry *label = GTK_ENTRY (user_data);
gchar *str;
gchar *id, *pretty_name;

g_object_get (machine, "id", &str, NULL);
GST_INFO ("update seq headers for machine id changed to \"%s\"", str);
g_object_set (label, "text", str, "tooltip-text", str, NULL);
g_free (str);
g_object_get (machine, "id", &id, "pretty-name", &pretty_name, NULL);
GST_INFO ("update seq headers for machine id changed to \"%s\"", id);
g_object_set (label, "text", id, "tooltip-text", pretty_name, NULL);
g_free (id);
g_free (pretty_name);
}

static void
Expand Down Expand Up @@ -1454,7 +1455,6 @@ sequence_table_refresh_columns (const BtMainPageSequence * self,
gulong j, track_ct;
BtMachine *machine;
GtkWidget *header;
gchar *str;
gint col_index;
GtkCellRenderer *renderer;
GtkTreeViewColumn *tree_col;
Expand Down Expand Up @@ -1488,6 +1488,7 @@ sequence_table_refresh_columns (const BtMainPageSequence * self,
GtkWidget *label, *button, *box;
GtkVUMeter *vumeter;
GstElement *level;
gchar *id, *pretty_name;
gchar *level_name = "output-post-level";
gboolean first_track_for_machine;

Expand All @@ -1502,7 +1503,8 @@ sequence_table_refresh_columns (const BtMainPageSequence * self,
// its the sink, which already has it enabled
level_name = "input-post-level";
}
g_object_get (machine, "id", &str, level_name, &level, NULL);
g_object_get (machine, "id", &id, "pretty-name", &pretty_name, level_name,
&level, NULL);

// TODO(ensonic): add context menu like that in the machine_view to the header

Expand All @@ -1527,10 +1529,11 @@ sequence_table_refresh_columns (const BtMainPageSequence * self,
digit_width) + PANGO_SCALE - 1) / PANGO_SCALE);
gint num_chars = SEQUENCE_CELL_WIDTH / (char_pixels + 1);
GST_DEBUG ("setting width to %d chars", num_chars);
g_object_set (label, "has-frame", FALSE, "inner-border", 0, "text", str,
"tooltip-text", str, "width-chars", num_chars, "ellipsize",
g_object_set (label, "has-frame", FALSE, "inner-border", 0, "text", id,
"tooltip-text", pretty_name, "width-chars", num_chars, "ellipsize",
PANGO_ELLIPSIZE_END, NULL);
g_free (str);
g_free (id);
g_free (pretty_name);
if (g_object_class_find_property (G_OBJECT_GET_CLASS (label),
"max-width-chars")) {
g_object_set (label, "max-width-chars", num_chars, NULL);
Expand Down

0 comments on commit 2a5ec02

Please sign in to comment.