Difference between revisions of "Libcanberra"

From ArchWiki
Jump to: navigation, search
(fix related pages)
(Syntax)
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Category:Development (English)]]
+
[[Category:Development]]
{{i18n|Libcanberra}}
+
 
+
 
{{Article summary start|Summary}}
 
{{Article summary start|Summary}}
{{Article summary text|This article discusses how to install and configure libcanberra. Libcanberra is a small and lightweight library that implements the XDG Sound Theme Specification. This article covers how to get libcanberra on your system and how to use it for application development.}}
+
{{Article summary text|This article discusses how to install and configure libcanberra.}}
 
{{Article summary heading|Related}}
 
{{Article summary heading|Related}}
{{Article summary wiki|GNOME}}
+
{{Article summary wiki|GTK+}}
 
{{Article summary wiki|Libnotify}}
 
{{Article summary wiki|Libnotify}}
 
{{Article summary end}}
 
{{Article summary end}}
Line 29: Line 27:
 
{{hc|$HOME/.gtkrc-2.0 and $XDG_CONFIG_HOME/gtk-3.0/settings.ini|<nowiki>gtk-enable-event-sounds=true
 
{{hc|$HOME/.gtkrc-2.0 and $XDG_CONFIG_HOME/gtk-3.0/settings.ini|<nowiki>gtk-enable-event-sounds=true
 
gtk-enable-input-feedback-sounds=true
 
gtk-enable-input-feedback-sounds=true
gtk-sound-theme-name=freedestop</nowiki>}}
+
gtk-sound-theme-name=freedesktop</nowiki>}}
  
 
In GNOME, these settings are managed by gnome-settings-daemon, and the configuration is available in GSettings under org.gnome.desktop.sound schema.
 
In GNOME, these settings are managed by gnome-settings-daemon, and the configuration is available in GSettings under org.gnome.desktop.sound schema.
Line 40: Line 38:
 
====Bash====
 
====Bash====
 
*Dependency: {{Pkg|libcanberra}}
 
*Dependency: {{Pkg|libcanberra}}
{{hc|hallo_world.sh|<nowiki>#!/bin/bash
+
{{hc|hello_world.sh|<nowiki>#!/bin/bash
canberra-gtk-play -i phone-incoming-call -d "Hallo world"</nowiki>}}
+
canberra-gtk-play -i phone-incoming-call -d "hello world"</nowiki>}}
  
 
====C====
 
====C====
 
*Dependency: {{Pkg|libcanberra}}
 
*Dependency: {{Pkg|libcanberra}}
*Build with: {{ic|gcc -o hallo_world `pkg-config --cflags --libs glib-2.0 libcanberra` hallo_world.c}}
+
*Build with: {{ic|gcc hello_world.c -o hello_world `pkg-config --cflags --libs glib-2.0 libcanberra`}}
{{hc|hallo_world.c|<nowiki>#include <glib.h>
+
{{hc|hello_world.c|<nowiki>#include <glib.h>
 
#include <canberra.h>
 
#include <canberra.h>
 
void main () {
 
void main () {
ca_context * Hallo;
+
ca_context * hello;
ca_context_create (&Hallo);
+
ca_context_create (&hello);
ca_context_play (Hallo, 0,
+
ca_context_play (hello, 0,
 
CA_PROP_EVENT_ID, "phone-incoming-call",
 
CA_PROP_EVENT_ID, "phone-incoming-call",
CA_PROP_EVENT_DESCRIPTION, "Hallo world",
+
CA_PROP_EVENT_DESCRIPTION, "hello world",
 
NULL);
 
NULL);
 
g_usleep (2000000);
 
g_usleep (2000000);
Line 61: Line 59:
 
*Dependency: {{Pkg|libcanberra}}
 
*Dependency: {{Pkg|libcanberra}}
 
*Makedependency: {{Pkg|vala}}
 
*Makedependency: {{Pkg|vala}}
*Build with: {{ic|valac --pkg libcanberra hallo_world.gs}}
+
*Build with: {{ic|valac --pkg libcanberra hello_world.gs}}
{{hc|hallo_world.gs|<nowiki>uses
+
{{hc|hello_world.gs|<nowiki>uses
 
Canberra
 
Canberra
 
init
 
init
Hallo: Context
+
hello: Context
Context.create(out Hallo)
+
Context.create(out hello)
Hallo.play (0,
+
hello.play (0,
 
PROP_EVENT_ID, "phone-incoming-call",
 
PROP_EVENT_ID, "phone-incoming-call",
PROP_EVENT_DESCRIPTION, "Hallo world")
+
PROP_EVENT_DESCRIPTION, "hello world")
 
Thread.usleep (2000000)</nowiki>}}
 
Thread.usleep (2000000)</nowiki>}}
  
Line 75: Line 73:
 
*Dependency: {{Pkg|libcanberra}}
 
*Dependency: {{Pkg|libcanberra}}
 
*Makedependency: {{Pkg|vala}}
 
*Makedependency: {{Pkg|vala}}
*Build with: {{ic|valac --pkg libcanberra hallo_world.vala}}
+
*Build with: {{ic|valac --pkg libcanberra hello_world.vala}}
{{hc|hallo_world.vala|<nowiki>using Canberra;
+
{{hc|hello_world.vala|<nowiki>using Canberra;
public class HalloWorld {
+
public class HelloWorld {
 
static void main () {
 
static void main () {
Context Hallo;
+
Context hello;
Context.create(out Hallo);
+
Context.create(out hello);
Hallo.play (0,
+
hello.play (0,
 
PROP_EVENT_ID, "phone-incoming-call",
 
PROP_EVENT_ID, "phone-incoming-call",
PROP_EVENT_DESCRIPTION, "Hallo world");
+
PROP_EVENT_DESCRIPTION, "hello world");
 
Thread.usleep (2000000);
 
Thread.usleep (2000000);
 
}
 
}
Line 89: Line 87:
  
 
==See also==
 
==See also==
*[http://developer.gnome.org/libcanberra/0.28/ Libcanberra Reference Manual]
+
*[http://0pointer.de/lennart/projects/libcanberra/gtkdoc/ Libcanberra Reference Manual]

Revision as of 19:08, 10 December 2012

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary end

Libcanberra is a simple abstract interface for playing event sounds. It implements the XDG Sound Theme and Naming Specifications for generating event sounds on free desktops, such as GNOME. Further description here

Installation

Libcanberra can be installed with the package libcanberra, available in the Official Repositories. It contains the library and a GTK+ module.

You have to choose a backend to play sounds:

Also, you have to install a sound theme in order to hear any event sound:

Configuration

By default, the GTK+ module is loaded automatically, when a GTK+ application launched. You can overwrite default settings in user's GtkSettings file:

$HOME/.gtkrc-2.0 and $XDG_CONFIG_HOME/gtk-3.0/settings.ini
gtk-enable-event-sounds=true
gtk-enable-input-feedback-sounds=true
gtk-sound-theme-name=freedesktop

In GNOME, these settings are managed by gnome-settings-daemon, and the configuration is available in GSettings under org.gnome.desktop.sound schema.

Tips and tricks

Write your own canberra app

You can write your own libcanberra sound events easily in some programming languages, or you can simply use bash.

Bash

hello_world.sh
#!/bin/bash
canberra-gtk-play -i phone-incoming-call -d "hello world"

C

  • Dependency: libcanberra
  • Build with: gcc hello_world.c -o hello_world `pkg-config --cflags --libs glib-2.0 libcanberra`
hello_world.c
#include <glib.h>
#include <canberra.h>
void main () {
	ca_context * hello;
	ca_context_create (&hello);
	ca_context_play (hello, 0,
		CA_PROP_EVENT_ID, "phone-incoming-call",
		CA_PROP_EVENT_DESCRIPTION, "hello world",
		NULL);
	g_usleep (2000000);
}

Genie

  • Dependency: libcanberra
  • Makedependency: vala
  • Build with: valac --pkg libcanberra hello_world.gs
hello_world.gs
uses
	Canberra
init
	hello: Context
	Context.create(out hello)
	hello.play (0,
		PROP_EVENT_ID, "phone-incoming-call",
		PROP_EVENT_DESCRIPTION, "hello world")
	Thread.usleep (2000000)

Vala

  • Dependency: libcanberra
  • Makedependency: vala
  • Build with: valac --pkg libcanberra hello_world.vala
hello_world.vala
using Canberra;
public class HelloWorld {
	static void main () {
	Context hello;
	Context.create(out hello);
	hello.play (0,
		PROP_EVENT_ID, "phone-incoming-call",
		PROP_EVENT_DESCRIPTION, "hello world");
	Thread.usleep (2000000);
	}
}

See also