[gnome-sound-recorder] Enables recodings in mono



commit 16dcdc059a51306fe47084d43b671811b5648e86
Author: Miguel Vaello Martínez <miguel vaellomartinez gmail com>
Date:   Wed Jan 6 00:12:48 2016 +0100

    Enables recodings in mono
    
    Now is possible to select between mono and stereo mode
    through preferences panel.
    The stereo channel is still used by default,
    almost for now.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=552420
    
    Signed-off-by: Meg Ford <megford gnome org>

 data/org.gnome.gnome-sound-recorder.gschema.xml |    5 ++++
 src/application.js                              |    9 +++++++
 src/mainWindow.js                               |   24 +++++++++++++++++++
 src/preferences.js                              |   29 +++++++++++++++--------
 src/record.js                                   |   28 +++++++++++++++++++++-
 5 files changed, 84 insertions(+), 11 deletions(-)
---
diff --git a/data/org.gnome.gnome-sound-recorder.gschema.xml b/data/org.gnome.gnome-sound-recorder.gschema.xml
index 3b6c40c..c644150 100644
--- a/data/org.gnome.gnome-sound-recorder.gschema.xml
+++ b/data/org.gnome.gnome-sound-recorder.gschema.xml
@@ -15,6 +15,11 @@
       <summary>Maps media types to audio encoder preset names.</summary>
       <description>Maps media types to audio encoder preset names. If there is no mapping set, the default 
encoder settings will be used.</description>
     </key>
+    <key name="channel" type="i">
+      <default>1</default>
+      <summary>Available channels</summary>
+      <description>Maps available channels. If there is not no mapping set, stereo channel will be used by 
default.</description>
+    </key>
     <key name="mic-volume" type="d">
       <default>0.75</default>
       <summary>Microphone volume level</summary>
diff --git a/src/application.js b/src/application.js
index 55a2dad..4b09ac8 100644
--- a/src/application.js
+++ b/src/application.js
@@ -128,6 +128,15 @@ const Application = new Lang.Class({
     setPreferences: function(profileName) {
         settings.set_int("media-type-preset", profileName);
     },
+
+    getChannelsPreferences: function() {
+        let set = settings.get_int("channel");
+        return set;
+    },
+
+    setChannelsPreferences: function(channel) {
+        settings.set_int("channel", channel);
+    },
      
     getMicVolume: function() {
         let micVolLevel = settings.get_double("mic-volume");
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 225bc9a..3f8b4a0 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -827,6 +827,30 @@ const EncoderComboBox = new Lang.Class({
     }
 });
 
+const ChannelsComboBox = new Lang.Class({
+    Name: "ChannelsComboBox",
+    Extends: Gtk.ComboBoxText,
+
+    // encoding setting labels in combobox
+    _init: function() {
+        this.parent();
+        let combo = [_("Mono"), _("Stereo")];
+
+        for (let i = 0; i < combo.length; i++)
+            this.append_text(combo[i]);
+        this.set_property('valign', Gtk.Align.CENTER);
+        this.set_sensitive(true);
+        activeProfile = Application.application.getChannelsPreferences();
+        this.set_active(activeProfile);
+        this.connect("changed", Lang.bind(this, this._onComboBoxTextChanged));
+    },
+
+    _onComboBoxTextChanged: function() {
+        activeProfile = this.get_active();
+        Application.application.setChannelsPreferences(activeProfile);
+    }
+});
+
 const LoadMoreButton = new Lang.Class({
     Name: 'LoadMoreButton',
     Extends: Gtk.Button,
diff --git a/src/preferences.js b/src/preferences.js
index 3ddfc8e..800902f 100644
--- a/src/preferences.js
+++ b/src/preferences.js
@@ -28,7 +28,8 @@ const C_ = imports.gettext.pgettext;
 const MainWindow = imports.mainWindow;
 const Main = imports.main;
 
-let comboBoxText = null;
+let formatComboBoxText = null;
+let channelsComboBoxText = null;
 let recordVolume= null;
 let playVolume = null;
 
@@ -62,16 +63,24 @@ const Preferences = new Lang.Class({
         
         let formatLabel = new Gtk.Label({ label: _("Preferred format"),
                                           halign: Gtk.Align.END });
-        formatLabel.get_style_context ().add_class('dim-label');
+        formatLabel.get_style_context().add_class('dim-label');
         grid.attach(formatLabel, 0, 0, 2, 1);
         
-        comboBoxText = new MainWindow.EncoderComboBox();
-        grid.attach(comboBoxText, 2, 0, 2, 1);
+        formatComboBoxText = new MainWindow.EncoderComboBox();
+        grid.attach(formatComboBoxText, 2, 0, 2, 1);
         
+        let channelsLabel = new Gtk.Label({ label: _("Default mode"),
+                                            halign: Gtk.Align.END });
+        channelsLabel.get_style_context().add_class('dim-label');
+        grid.attach(channelsLabel, 0, 1, 2, 1);
+
+        channelsComboBoxText = new MainWindow.ChannelsComboBox();
+        grid.attach(channelsComboBoxText, 2, 1, 2, 1);
+
         let volumeLabel = new Gtk.Label({ label: _("Volume"),
                                           halign: Gtk.Align.END });
-        volumeLabel.get_style_context ().add_class('dim-label');
-        grid.attach(volumeLabel, 0, 1, 2, 1);
+        volumeLabel.get_style_context().add_class('dim-label');
+        grid.attach(volumeLabel, 0, 2, 2, 1);
         
         playVolume = new Gtk.Scale({ orientation: Gtk.Orientation.HORIZONTAL });
         this.playRange = Gtk.Adjustment.new(MainWindow.volumeValue[0].play, 0, 1.0, 0.05, 0.0, 0.0);
@@ -81,12 +90,12 @@ const Preferences = new Lang.Class({
             function() {
                 MainWindow.view.presetVolume(MainWindow.ActiveArea.PLAY, playVolume.get_value());
             }));
-        grid.attach(playVolume, 2, 1, 2, 1);
+        grid.attach(playVolume, 2, 2, 2, 1);
         
         let micVolLabel = new Gtk.Label({ label: _("Microphone"),
                                           halign: Gtk.Align.END });
-        micVolLabel.get_style_context ().add_class('dim-label');
-        grid.attach(micVolLabel, 0, 2, 2, 1);
+        micVolLabel.get_style_context().add_class('dim-label');
+        grid.attach(micVolLabel, 0, 3, 2, 1);
         
         recordVolume = new Gtk.Scale({ orientation: Gtk.Orientation.HORIZONTAL });
         this.recordRange = Gtk.Adjustment.new(MainWindow.volumeValue[0].record, 0, 1.0, 0.05, 0.0, 0.0);
@@ -96,7 +105,7 @@ const Preferences = new Lang.Class({
             function() {
                 MainWindow.view.presetVolume(MainWindow.ActiveArea.RECORD, recordVolume.get_value());
             }));
-        grid.attach(recordVolume, 2, 2, 2, 1);
+        grid.attach(recordVolume, 2, 3, 2, 1);
         
         this.widget.show_all();
       },
diff --git a/src/record.js b/src/record.js
index f455f59..bd396b2 100644
--- a/src/record.js
+++ b/src/record.js
@@ -46,6 +46,11 @@ const ErrState = {
     ON: 1
 }
 
+const Channels = {
+    MONO: 0,
+    STEREO: 1
+}
+
 const _TENTH_SEC = 100000000;
 
 let errorDialogState;
@@ -81,7 +86,7 @@ const Record = new Lang.Class({
         this.pipeline.add(this.srcElement);
         this.audioConvert = Gst.ElementFactory.make("audioconvert", "audioConvert");
         this.pipeline.add(this.audioConvert);
-        this.caps = Gst.Caps.from_string("audio/x-raw, channels=2");
+        this.caps = Gst.Caps.from_string("audio/x-raw, channels=" + this._getChannels());
         this.clock = this.pipeline.get_clock();
         this.recordBus = this.pipeline.get_bus();
         this.recordBus.add_signal_watch();
@@ -292,6 +297,27 @@ const Record = new Lang.Class({
         }
     },
 
+    _getChannels: function() {
+
+        let channels = null;
+        let channelsPref = Application.application.getChannelsPreferences();
+
+        switch(channelsPref) {
+        case Channels.MONO:
+            channels = 1;
+            break;
+
+        case Channels.STEREO:
+            channels = 2;
+            break;
+
+        default:
+            channels = 2;
+        }
+
+        return channels;
+    },
+
     _showErrorDialog: function(errorStrOne, errorStrTwo) {
         if (errorDialogState == ErrState.OFF) {
             let errorDialog = new Gtk.MessageDialog ({ modal: true,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]