[gnome-sound-recorder] add stereo/mono in primary menu



commit 9c64c4c6e89553e2799154b1fabdfbf6753bd24a
Author: Kavan Mevada <kavanmevada gmail com>
Date:   Sat Jun 6 17:04:04 2020 +0530

    add stereo/mono in primary menu
    
    fix #75

 data/org.gnome.SoundRecorder.gschema.xml.in |  9 +++++++++
 data/ui/window.ui                           | 13 +++++++++++++
 src/application.js                          | 27 +++++++++++++++++++++++++++
 src/recorder.js                             | 12 +++++++++++-
 4 files changed, 60 insertions(+), 1 deletion(-)
---
diff --git a/data/org.gnome.SoundRecorder.gschema.xml.in b/data/org.gnome.SoundRecorder.gschema.xml.in
index bc68bec..4cf6c09 100644
--- a/data/org.gnome.SoundRecorder.gschema.xml.in
+++ b/data/org.gnome.SoundRecorder.gschema.xml.in
@@ -6,6 +6,10 @@
     <value nick='mp3' value='3'/>
     <value nick='m4a' value='4'/>
   </enum>
+  <enum id="@app-id@.AudioChannel">
+    <value nick='stereo' value='0'/>
+    <value nick='mono' value='1'/>
+  </enum>
   <schema id="@app-id@" path="/org/gnome/SoundRecorder/" gettext-domain="@gettext-package@">
     <key name="window-size" type="ai">
       <default>[780, 480]</default>
@@ -22,6 +26,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="audio-channel" enum="@app-id@.AudioChannel">
+      <default>'stereo'</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>
   </schema>
 </schemalist>
 
diff --git a/data/ui/window.ui b/data/ui/window.ui
index c218479..6187030 100644
--- a/data/ui/window.ui
+++ b/data/ui/window.ui
@@ -403,6 +403,19 @@
         <attribute name="target">m4a</attribute>
       </item>
     </submenu>
+    <submenu>
+      <attribute translatable="yes" name="label">Audio Channel</attribute>
+      <item>
+        <attribute translatable="yes" name="label">Stereo</attribute>
+        <attribute name="action">app.audio-channel</attribute>
+        <attribute name="target">stereo</attribute>
+      </item>
+      <item>
+        <attribute translatable="yes" name="label">Mono</attribute>
+        <attribute name="action">app.audio-channel</attribute>
+        <attribute name="target">mono</attribute>
+      </item>
+    </submenu>
     <section>
       <item>
         <attribute name="action">app.about</attribute>
diff --git a/src/application.js b/src/application.js
index 0cfb11b..5488fcc 100644
--- a/src/application.js
+++ b/src/application.js
@@ -88,6 +88,33 @@ var Application = GObject.registerClass(class Application extends Gtk.Applicatio
         this.add_action(profileAction);
 
 
+        function getDefaultChannel() {
+            switch (settings.get_enum('audio-channel')) {
+            case 0:
+                return new GLib.Variant('s', 'stereo');
+            case 1:
+                return new GLib.Variant('s', 'mono');
+            }
+        }
+
+        let channelAction = new Gio.SimpleAction({
+            enabled: true,
+            name: 'audio-channel',
+            state: getDefaultChannel(),
+            parameter_type: new GLib.VariantType('s'),
+        });
+        channelAction.connect('activate', (action, parameter) => {
+            action.change_state(parameter);
+        });
+        channelAction.connect('change-state', (action, state) => {
+            settings.set_value('audio-channel', state);
+        });
+        settings.connect('changed::audio-channel', () => {
+            channelAction.state = getDefaultChannel();
+        });
+        this.add_action(channelAction);
+
+
         let aboutAction = new Gio.SimpleAction({ name: 'about' });
         aboutAction.connect('activate', () => {
             this._showAbout();
diff --git a/src/recorder.js b/src/recorder.js
index 7489a64..eb4dba0 100644
--- a/src/recorder.js
+++ b/src/recorder.js
@@ -55,6 +55,11 @@ var EncodingProfiles = [
         mimeType: 'audio/mpeg' },
 ];
 
+var AudioChannels = {
+    0: { name: 'stereo', channels: 2 },
+    1: { name: 'mono', channels: 1 },
+};
+
 var Recorder = new GObject.registerClass({
     Properties: {
         'duration': GObject.ParamSpec.int(
@@ -214,12 +219,17 @@ var Recorder = new GObject.registerClass({
         }
     }
 
+    _getChannel() {
+        let channelIndex = Application.settings.get_enum('audio-channel');
+        return AudioChannels[channelIndex].channels;
+    }
+
     _getProfile() {
         let profileIndex = Application.settings.get_enum('audio-profile');
         const profile = EncodingProfiles[profileIndex];
 
         let audioCaps = Gst.Caps.from_string(profile.audioCaps);
-        audioCaps.set_value('channels', 2);
+        audioCaps.set_value('channels', this._getChannel());
 
         let encodingProfile = GstPbutils.EncodingAudioProfile.new(audioCaps, null, null, 1);
         let containerCaps = Gst.Caps.from_string(profile.containerCaps);


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