sponsored by djcj.org
Linux Audio Users Guide

DJCJ Custom GTK Widgets Collection

DEVELOPER

Author: Patrick Shirkey - Boost Hardware Ltd
Contact: pshirkey_at_boosthardware.com

DOWNLOAD

DESCRIPTION

GtkMeter - custom VU meter widget for GTK+ written in C

The code demonstrates how to build a custom widget class for GTK3 and cairo.

USING

#include "gtkmeter.h"



  GtkMeter *meter1 = make_meter ("meter1", "", "", -60, 6);
  gtk_widget_set_name (meter1, "meter1");
  gtk_widget_show (meter1);
  gtk_box_pack_start (GTK_BOX (inmeter_hbox), meter1, TRUE, TRUE, 0);
  gtk_widget_set_size_request (meter1, 15, 0);

  meter2 = make_meter ("meter2", "right", "", -40, 0);
  gtk_widget_set_name (meter2, "meter2");
  gtk_widget_show (meter2);
  gtk_box_pack_start (GTK_BOX (vbox_l), meter2, FALSE, TRUE, 0);
  gtk_widget_set_size_request (meter2, 0, 12);
  gtk_widget_set_tooltip_text (meter2, _("Level"));

  meter3 = make_meter ("meter3", "left", "", -40, 0);
  gtk_widget_set_name (meter3, "meter3");
  gtk_widget_show (meter3);
  gtk_box_pack_start (GTK_BOX (vbox_l), meter3, FALSE, TRUE, 0);
  gtk_widget_set_size_request (meter3, 0, 12);


/* slider for adjusting input/output volume levels */

  in_trim_scale = gtk_scale_new (GTK_ORIENTATION_VERTICAL, 
			GTK_ADJUSTMENT (gtk_adjustment_new (-0.1, -12, 12, 1, 6, 0)));
  gtk_widget_set_name (in_trim_scale, "in_trim_scale");
  gtk_widget_show (in_trim_scale);
  gtk_container_add (GTK_CONTAINER (in_trim_scale_event_box), in_trim_scale);
  gtk_range_set_inverted (GTK_RANGE (in_trim_scale), TRUE);
  
  

  gtk_meter_set_adjustment (meter1, gtk_adjustment_set_value(in_trim_scale));
  

  

GtkWidget*
make_meter (gchar *widget_name, gchar *string1, gchar *string2,
                gint int1, gint int2)
{
    GtkWidget *ret;
    gint dir = GTK_METER_UP;
    int sides = 0;
    GtkAdjustment *adjustment = (GtkAdjustment*) gtk_adjustment_new (0.0,
                    (float)int1, (float)int2, 0.0, 0.0, 0.0);

    if (!string1 || !strcmp(string1, "up")) {
        dir = GTK_METER_UP;
    } else if (!strcmp(string1, "down")) {
        dir = GTK_METER_DOWN;
    } else if (!strcmp(string1, "left")) {
        dir = GTK_METER_LEFT;
    } else if (!strcmp(string1, "right")) {
        dir = GTK_METER_RIGHT;
    }
  

    if (string1 && strstr(string1, "left")) {
        sides |= GTK_METERSCALE_LEFT;
    }
    if (string1 && strstr(string1, "right")) {
        sides |= GTK_METERSCALE_RIGHT;
    }
    if (string1 && strstr(string1, "top")) {
        sides |= GTK_METERSCALE_TOP;
    }
    if (string1 && strstr(string1, "bottom")) {
        sides |= GTK_METERSCALE_BOTTOM;
    }

    ret = gtk_meter_new(adjustment, dir, sides, int1, int2);
    gtk_meter_set_adjustment(GTK_METER (ret), adjustment);

    return ret;

  
}



MORE PROJECTS

Check out jackEQ and jack-menu for more projects from DJCJ and Boost Hardware Ltd.

Python/GTK3/Clutter CMKeyboard

Check out the Linux Audio Users Guide, the Linux Audio Musicians - Best of Mixes, Linux Music Videos and the Quick Toots for lots of useful information, music and multimedia from the Linux Audio Community.