[chronojump] can play sounds from file, select by triggers, mac and linux with systemsounds
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] can play sounds from file, select by triggers, mac and linux with systemsounds
- Date: Tue, 17 Apr 2018 22:08:32 +0000 (UTC)
commit dc59190c1bf2552aa872cd91148c4686d12add18
Author: Xavier de Blas <xaviblas gmail com>
Date: Wed Apr 18 00:07:09 2018 +0200
can play sounds from file, select by triggers, mac and linux with systemsounds
glade/preferences_win.glade | 26 +++++++++-
src/config.cs | 3 +
src/encoderCapture.cs | 5 ++-
src/gui/chronojump.cs | 5 ++
src/gui/encoder.cs | 6 ++-
src/gui/preferences.cs | 18 ++++++--
src/preferences.cs | 2 +-
src/util.cs | 106 +++++++++++++++++++++++++++++++++----------
8 files changed, 136 insertions(+), 35 deletions(-)
---
diff --git a/glade/preferences_win.glade b/glade/preferences_win.glade
index 39e8bc4..31d95a1 100644
--- a/glade/preferences_win.glade
+++ b/glade/preferences_win.glade
@@ -3059,7 +3059,7 @@ Other</property>
<widget class="GtkTable" id="table_gstreamer">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="n_rows">3</property>
+ <property name="n_rows">4</property>
<property name="n_columns">2</property>
<property name="column_spacing">12</property>
<property name="row_spacing">10</property>
@@ -3188,8 +3188,8 @@ Other</property>
</child>
</widget>
<packing>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
+ <property name="top_attach">3</property>
+ <property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
@@ -3201,9 +3201,29 @@ Other</property>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
+ <property name="top_attach">3</property>
+ <property name="bottom_attach">4</property>
+ <property name="x_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <widget class="GtkRadioButton" id="radio_sound_systemsounds">
+ <property name="label">System sounds</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ <property name="group">radio_gstreamer_0_1</property>
+ </widget>
+ <packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
+ <property name="y_options"/>
</packing>
</child>
</widget>
diff --git a/src/config.cs b/src/config.cs
index 0cfec47..6cb4679 100644
--- a/src/config.cs
+++ b/src/config.cs
@@ -42,6 +42,7 @@ public class Config
public int CompujumpStationID = -1;
public Constants.Menuitem_modes CompujumpStationMode = Constants.Menuitem_modes.UNDEFINED;
public string RunScriptOnExit;
+ public bool PlaySoundsFromFile;
public Config()
{
@@ -93,6 +94,8 @@ public class Config
else if(parts[0] == "SessionMode" &&
Enum.IsDefined(typeof(SessionModeEnum), parts[1]))
SessionMode = (SessionModeEnum)
Enum.Parse(typeof(SessionModeEnum), parts[1]);
+ else if(parts[0] == "PlaySoundsFromFile" &&
Util.StringToBool(parts[1]))
+ PlaySoundsFromFile = true;
} while(true);
}
}
diff --git a/src/encoderCapture.cs b/src/encoderCapture.cs
index 7b318e0..4e726d1 100644
--- a/src/encoderCapture.cs
+++ b/src/encoderCapture.cs
@@ -227,7 +227,7 @@ public abstract class EncoderCapture
}
public bool Capture(string outputData1, EncoderRProcCapture encoderRProcCapture,
- bool compujump, Preferences.TriggerTypes cutByTriggers, double restClustersSeconds)
+ bool compujump, Preferences.TriggerTypes cutByTriggers, double restClustersSeconds,
bool playSoundsFromFile)
{
/*
* removed at 1.7.0
@@ -276,6 +276,9 @@ public abstract class EncoderCapture
continue;
}
+ if(playSoundsFromFile)
+ Util.NextSongInList();
+
//TriggerTypes.START_AT_FIRST_ON starts capture at first trigger. So when
this happens, reset capture
if(cutByTriggers == Preferences.TriggerTypes.START_AT_FIRST_ON && !
firstTriggerHappened)
{
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index b20202b..b2e6145 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -746,6 +746,11 @@ public partial class ChronoJumpWindow
LogB.Information(string.Format("coef = {0} {1} {2}", ls.Coef[0], ls.Coef[1], ls.Coef[2]));
*/
//new VersionCompareTests();
+ if(configChronojump.PlaySoundsFromFile)
+ {
+ Util.CreateSoundList();
+ Util.UseSoundList = true;
+ }
}
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 2f295a2..0822af9 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -2576,7 +2576,8 @@ public partial class ChronoJumpWindow
encoderRProcCapture,
configChronojump.Compujump,
encoderRProcCapture.CutByTriggers,
- encoderRhythm.RestClustersForEncoderCaptureAutoEnding()
+ encoderRhythm.RestClustersForEncoderCaptureAutoEnding(),
+ configChronojump.PlaySoundsFromFile
);
//wait to ensure capture thread has ended
@@ -2618,7 +2619,8 @@ public partial class ChronoJumpWindow
encoderRProcCapture,
false, //compujump
Preferences.TriggerTypes.NO_TRIGGERS,
- 0 //encoderRhythm.RestClustersForEncoderCaptureAutoEnding()
+ 0, //encoderRhythm.RestClustersForEncoderCaptureAutoEnding()
+ false //configChronojump.PlaySoundsFromFile
);
//wait to ensure capture thread has ended
diff --git a/src/gui/preferences.cs b/src/gui/preferences.cs
index 1ea92a3..4cb1a4f 100644
--- a/src/gui/preferences.cs
+++ b/src/gui/preferences.cs
@@ -135,6 +135,7 @@ public class PreferencesWindow
[Widget] Gtk.Table table_gstreamer;
[Widget] Gtk.RadioButton radio_gstreamer_0_1;
[Widget] Gtk.RadioButton radio_gstreamer_1_0;
+ [Widget] Gtk.RadioButton radio_sound_systemsounds;
[Widget] Gtk.Label label_test_sound_result;
[Widget] Gtk.Box hbox_combo_camera;
[Widget] Gtk.ComboBox combo_camera;
@@ -269,8 +270,10 @@ public class PreferencesWindow
if(preferences.gstreamer == Preferences.GstreamerTypes.GST_0_1)
PreferencesWindowBox.radio_gstreamer_0_1.Active = true;
- else
+ else if(preferences.gstreamer == Preferences.GstreamerTypes.GST_1_0)
PreferencesWindowBox.radio_gstreamer_1_0.Active = true;
+ else //(preferences.gstreamer == Preferences.GstreamerTypes.SYSTEMSOUNDS)
+ PreferencesWindowBox.radio_sound_systemsounds.Active = true;
PreferencesWindowBox.label_test_sound_result.Text = "";
PreferencesWindowBox.createComboCamera(UtilMultimedia.GetVideoDevices(),
preferences.videoDeviceNum);
@@ -572,8 +575,10 @@ public class PreferencesWindow
if(radio_gstreamer_0_1.Active)
sc = Util.PlaySound(Constants.SoundTypes.GOOD, true,
Preferences.GstreamerTypes.GST_0_1);
- else // radio_gstreamer_1_0.Active
+ else if(radio_gstreamer_1_0.Active)
sc = Util.PlaySound(Constants.SoundTypes.GOOD, true,
Preferences.GstreamerTypes.GST_1_0);
+ else
+ sc = Util.PlaySound(Constants.SoundTypes.GOOD, true,
Preferences.GstreamerTypes.SYSTEMSOUNDS);
if(sc == Util.SoundCodes.OK)
label_test_sound_result.Text = Catalog.GetString("Sound working");
@@ -1362,16 +1367,21 @@ public class PreferencesWindow
preferences.volumeOn = PreferencesWindowBox.checkbutton_volume.Active;
}
- if( preferences.gstreamer == Preferences.GstreamerTypes.GST_0_1 && radio_gstreamer_1_0.Active)
+ if( preferences.gstreamer != Preferences.GstreamerTypes.GST_1_0 && radio_gstreamer_1_0.Active)
{
SqlitePreferences.Update(Preferences.GstreamerStr,
Preferences.GstreamerTypes.GST_1_0.ToString(), true);
preferences.gstreamer = Preferences.GstreamerTypes.GST_1_0;
}
- else if( preferences.gstreamer == Preferences.GstreamerTypes.GST_1_0 &&
radio_gstreamer_0_1.Active)
+ else if( preferences.gstreamer != Preferences.GstreamerTypes.GST_0_1 &&
radio_gstreamer_0_1.Active)
{
SqlitePreferences.Update(Preferences.GstreamerStr,
Preferences.GstreamerTypes.GST_0_1.ToString(), true);
preferences.gstreamer = Preferences.GstreamerTypes.GST_0_1;
}
+ else if( preferences.gstreamer != Preferences.GstreamerTypes.SYSTEMSOUNDS &&
radio_sound_systemsounds.Active)
+ {
+ SqlitePreferences.Update(Preferences.GstreamerStr,
Preferences.GstreamerTypes.SYSTEMSOUNDS.ToString(), true);
+ preferences.gstreamer = Preferences.GstreamerTypes.SYSTEMSOUNDS;
+ }
if( preferences.videoDeviceNum != UtilGtk.ComboGetActivePos(combo_camera) ) {
SqlitePreferences.Update("videoDevice",
UtilGtk.ComboGetActivePos(combo_camera).ToString(), true);
diff --git a/src/preferences.cs b/src/preferences.cs
index 5099064..c2c8045 100644
--- a/src/preferences.cs
+++ b/src/preferences.cs
@@ -117,7 +117,7 @@ public class Preferences
public int encoderCaptureTimeIM = 180; //hardcoded 3 minutes.
- public enum GstreamerTypes { GST_0_1, GST_1_0 };
+ public enum GstreamerTypes { GST_0_1, GST_1_0, SYSTEMSOUNDS }; //SYSTEMSOUNDS is the default sounds
played on Windows
public GstreamerTypes gstreamer;
public static string GstreamerStr = "gstreamer"; //in order to ensure write correctly on SQL
diff --git a/src/util.cs b/src/util.cs
index e544d20..6e8fbbe 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -1382,36 +1382,21 @@ public class Util
* and some MacOSX users have 300% CPU
*/
- if( UtilAll.GetOSEnum() == UtilAll.OperatingSystems.LINUX ||
- UtilAll.GetOSEnum() == UtilAll.OperatingSystems.MACOSX )
- return playSoundGstreamer(mySound, gstreamer);
- else //Windows
+ if(UtilAll.GetOSEnum() == UtilAll.OperatingSystems.WINDOWS ||
+ gstreamer == Preferences.GstreamerTypes.SYSTEMSOUNDS)
return playSoundWindows(mySound);
+ else
+ return playSoundGstreamer(mySound, gstreamer);
}
-// private enum gstreamerVersions { GST_0_1, GST_1_0 }
+// private enum gstreamerVersions { GST_0_1, GST_1_0, SYSTEMSOUNDS }
private static SoundCodes playSoundGstreamer (Constants.SoundTypes mySound,
Preferences.GstreamerTypes gstreamer)
{
string fileName = "";
- switch(mySound) {
- case Constants.SoundTypes.CAN_START:
- fileName = "123804__kendallbear__kendallklap1.wav";
- //author: kendallbear
- //https://www.freesound.org/people/kendallbear/sounds/123804/
- break;
- case Constants.SoundTypes.GOOD:
- fileName = "135936__bradwesson__collectcoin.wav";
- //author: bradwesson
- //https://www.freesound.org/people/bradwesson/sounds/135936/
- break;
- case Constants.SoundTypes.BAD:
- fileName = "142608__autistic-lucario__error.wav";
- //author: Autistic Lucario
- //https://www.freesound.org/people/Autistic%20Lucario/sounds/142608/
- break;
- }
-
- fileName = Util.GetSoundsDir() + Path.DirectorySeparatorChar + fileName;
+ if(! UseSoundList)
+ fileName = getSound(mySound); //default chronojump
+ else
+ fileName = getSoundFromSoundList(); //espectacle
if(! File.Exists(fileName)) {
LogB.Warning("Cannot found this sound file: " + fileName);
@@ -1483,6 +1468,79 @@ public class Util
return SoundCodes.OK;
}
+ private static string getSound (Constants.SoundTypes mySound)
+ {
+ string fileName = "";
+ switch(mySound) {
+ case Constants.SoundTypes.CAN_START:
+ fileName = "123804__kendallbear__kendallklap1.wav";
+ //author: kendallbear
+ //https://www.freesound.org/people/kendallbear/sounds/123804/
+ break;
+ case Constants.SoundTypes.GOOD:
+ fileName = "135936__bradwesson__collectcoin.wav";
+ //author: bradwesson
+ //https://www.freesound.org/people/bradwesson/sounds/135936/
+ break;
+ case Constants.SoundTypes.BAD:
+ fileName = "142608__autistic-lucario__error.wav";
+ //author: Autistic Lucario
+ //https://www.freesound.org/people/Autistic%20Lucario/sounds/142608/
+ break;
+ }
+
+ fileName = Util.GetSoundsDir() + Path.DirectorySeparatorChar + fileName;
+ return fileName;
+ }
+
+ public static bool UseSoundList;
+ static List<string> soundList;
+ static int soundListPos;
+
+ public static string getSoundsFileName() {
+ return Path.Combine(UtilAll.GetApplicationDataDir() + Path.DirectorySeparatorChar +
"sounds.txt");
+ }
+
+ public static void CreateSoundList()
+ {
+ soundList = new List<string>();
+ soundListPos = 0;
+ string contents = Util.ReadFile(getSoundsFileName(), false);
+ if (contents != null && contents != "")
+ {
+ string line;
+ using (StringReader reader = new StringReader (contents)) {
+ do {
+ line = reader.ReadLine ();
+
+ if (line == null)
+ break;
+ if (line == "" || line[0] == '#')
+ continue;
+
+ soundList.Add(line);
+ } while(true);
+ }
+ }
+ }
+
+ //called on trigger use
+ public static void NextSongInList()
+ {
+ if(soundList == null)
+ return;
+
+ soundListPos ++;
+ if(soundListPos >= soundList.Count)
+ soundListPos = 0;
+ }
+
+ private static string getSoundFromSoundList()
+ {
+ return soundList[soundListPos];
+ }
+
+
/*
* ------------- end of sound stuff -----------
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]