Snapshot
Overview
The sound applet is designed to present volume sliders and mute buttons for ever playback or capture track the sound hardware supports. It presents a notebook where each tab represents a different "sound element" or "track". Tracks can be things like Master, PCM, CD, Aux, Line in, etc. Within each notebook tab there are a series of controller elements instantiated for each channel available in the track. For instance if a track is mono it will have only one controller element. If it's stereo it will have two, one for left and one for right. If a track is 5.1 dolby it will have 6 controller elements: front left, front right, front center, rear left, rear right, and woofer.
Each controller element has a title, and potentially a volume slider and/or a mute button. The layout of each controller element is determined by the hardware. Some tracks only support volume and no mute switch, others have no volume slider and only a mute switch, and some have both. The only guarantee is that no tracks will have neither.
There is also a checkbox at the bottom of the dialog called "sync", and its purpose is to enable all the channel controls in a track to act the same, i.e. to be in "sync". This means that moving one volume slider will move all volume sliders the same way, and pressing one mute button will press all mute buttons. This checkbox can be pressed and unpressed at will for whatever settings needs the user has.
Files Needed
- /usr/lib/moblin-applets/libhcpcommon.so
- all control panel applets need this
- /usr/lib/hildon-control-panel/mixer.so
- The applet library
- /usr/share/applications/hildon-control-panel/mixer.desktop
- The applet descriptor, tells mobile-basic-flash to create a shortcut in "Settings"
- /usr/share/moblin-applets/glade/mixer.glade
- Glade XML file describing the dialog
- /usr/lib/moblin-applets/libvolumecontrol.so
- ALSA volume hardware access library
Applet Design
ALSA Library
The sound applet interfaces with the hardware via a moblin-applets library called libvolumecontrol. This library encapsulates all the hardware device handling and ALSA function calls into a simple API which is used by all components of moblin-applets which configure sound: this applet, the volume status bar applet, and moblin-settings-daemon. The API is shown here:
| API Function | Description |
|---|---|
| int init_alsa_vars(); | initializes the library, called prior to use at applet startup |
| int num_sound_elements(); | Determines how many tabs to display in the notebook |
| int num_channels(int e); | Determines how many channel controls to display in a page |
| gchar* name_from_index(int e); | Determines each notebook tab title |
| const char* name_from_channel(int e, int channel); | Determines each channel title |
| int get_volume_range(int e, int *min, int *max); | Determines the volume slider range |
| int get_volume(int e, int channel, int *val); | Gets the current volume for a track and channel on init |
| int set_volume(int e, int channel, int val); | Sets the volume on every slider change, no reads needed |
| int set_all_volume(int e, int val); | Sets volume for a track when the sync box is checked |
| int get_switch(int e, int channel, int *val); | Gets the current mute for a track and channel on init |
| int set_switch(int e, int channel, int val); | Sets the mute on every button press, no reads needed |
| int set_all_switch(int e, int val); | Sets mute for a track when the sync box is checked |
| void set_primary_sound_element_index(int e); | Set the track which the status bar and keybindings control |
| int get_primary_sound_element_index(); | Get the track which the status bar and keybindings control |
| int get_support(int e, int *vol, int *sw); | Determines whether volume, mute, or both are needed |
| int get_pse_volume_range(void); | Macro to get the volume range for the pse |
GUI Construction
The GUI Dialog is designed using glade and by default has a single tab (single track) with a single channel. The dialog is instantiated and then the glade defined track tab is duplicated and instantiated as many times as are needed to cover all the available tracks. The glade defined channel control is duplicated within each tab as many times as are needed to cover all the available channels. Once the entire dialog is instantiated in memory, four callbacks are used to offer notification from every dialog item.
All the volume sliders are assigned to a single callback where an argument is passed in with the tab and channel. All the mute buttons also go to a single callback with the same tab and channel info. Then the sync and close buttons go to their own simpler callbacks. This makes the code for the GUI quite simple and robust.
Code Reuse
This applet is written entirely from scratch for moblin.
