diff --git a/.gitignore b/.gitignore index b8d69cd..7da6948 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ #Soundtrack data -testexetrisathlon/*.wav +testexetrisathlon/*.mp3 # Created by https://www.gitignore.io/api/rider,csharp,visualstudio diff --git a/DownloadData.py b/DownloadData.py index 72700e4..7fbe0a1 100644 --- a/DownloadData.py +++ b/DownloadData.py @@ -1,24 +1,32 @@ import os import os.path -import wave import youtube_dl +import wave os.chdir("testexetrisathlon") -def dl_vid(url, outfile): +def dl_vid(url, outfile, filetype): ydl_opts = { 'outtmpl': outfile, 'noplaylist': True, 'continue_dl': True, 'postprocessors': [{ 'key': 'FFmpegExtractAudio', - 'preferredcodec': 'wav' }] + 'preferredcodec': filetype }] } with youtube_dl.YoutubeDL(ydl_opts) as ydl: ydl.download([url]) def merge_vids(infiles, outfile): + #lStream = open("list.txt", "w") + #for infile in infiles: + # lStream.write("file '" + infile + ".wav'\n") + #lStream.close() + #os.system("ffmpeg -f concat -i list.txt -c copy " + outfile + ".mp3") + #os.remove("list.txt") + #for infile in infiles: + # os.remove(infile + ".mp3") data= [] for infile in infiles: w = wave.open(infile + ".wav", 'rb') @@ -31,21 +39,24 @@ def merge_vids(infiles, outfile): output.writeframes(data[0][1]) output.writeframes(data[1][1]) output.close() + os.system("ffmpeg -y -i " + outfile + ".wav " + outfile + ".mp3") + os.remove(outfile + ".wav") -if not os.path.isfile("Intro.wav"): - dl_vid("https://youtu.be/U06jlgpMtQs", "Intro") +if not os.path.isfile("Intro.mp3"): + dl_vid("https://youtu.be/U06jlgpMtQs", "Intro", "mp3") + -if not os.path.isfile("InGame1.wav"): - dl_vid("https://youtu.be/hueJrl83sOQ", "st1") - dl_vid("https://youtu.be/7gSS4h47rLU", "st2") - dl_vid("https://youtu.be/NDjDgvXlfVw", "st3") +if not os.path.isfile("InGame1.mp3"): + dl_vid("https://youtu.be/hueJrl83sOQ", "st1", "wav") + dl_vid("https://youtu.be/7gSS4h47rLU", "st2", "wav") + dl_vid("https://youtu.be/NDjDgvXlfVw", "st3", "wav") merge_vids(["st1", "st2", "st3"], "InGame1") -if not os.path.isfile("InGame2.wav"): - dl_vid("https://youtu.be/umEDct4BoGc", "st1") - dl_vid("https://youtu.be/NVpjt9gHlDw", "st2") - dl_vid("https://youtu.be/zgKazTrhXmI", "st3") +if not os.path.isfile("InGame2.mp3"): + dl_vid("https://youtu.be/umEDct4BoGc", "st1", "wav") + dl_vid("https://youtu.be/NVpjt9gHlDw", "st2", "wav") + dl_vid("https://youtu.be/zgKazTrhXmI", "st3", "wav") merge_vids(["st1", "st2", "st3"], "InGame2") -if not os.path.isfile("GameOver.wav"): - dl_vid("https://youtu.be/J_3Zad-e9f4", "GameOver") +if not os.path.isfile("GameOver.mp3"): + dl_vid("https://youtu.be/J_3Zad-e9f4", "GameOver", "mp3") diff --git a/testexetrisathlon/LinuxSizeSetter.cs b/testexetrisathlon/LinuxSizeSetter.cs new file mode 100644 index 0000000..f4601fa --- /dev/null +++ b/testexetrisathlon/LinuxSizeSetter.cs @@ -0,0 +1,10 @@ +namespace testexetrisathlon +{ + public static class SizeSetter + { + public static void SetWindowSize(int width, int height) + { + + } + } +} \ No newline at end of file diff --git a/testexetrisathlon/OSCheck.cs b/testexetrisathlon/OSCheck.cs deleted file mode 100644 index c86761e..0000000 --- a/testexetrisathlon/OSCheck.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Linq; - -namespace testexetrisathlon -{ - internal static class OSCheck - { - private static bool _checkedWindows; - private static bool _isWindows; - - public static bool IsWindows - { - get - { - if (_checkedWindows) return _isWindows; - _isWindows = - new[] {PlatformID.Win32S, PlatformID.Win32Windows, PlatformID.Win32NT, PlatformID.WinCE} - .Contains(Environment.OSVersion.Platform); - _checkedWindows = true; - return _isWindows; - } - } - } -} \ No newline at end of file diff --git a/testexetrisathlon/Program.cs b/testexetrisathlon/Program.cs index f89ddee..5120d65 100644 --- a/testexetrisathlon/Program.cs +++ b/testexetrisathlon/Program.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; -using System.Threading; using testexetrisathlon.SoundManagement; using static System.Console; @@ -51,7 +50,8 @@ namespace testexetrisathlon public static bool Debug; public static readonly Random Rnd = new Random(); - private static ISoundManager soundManager; + private static ISoundManager _soundManager; + public static IBeeper Beeper; private static string InGame => SettingsMan.UsingAltTrack ? "InGame2" : "InGame1"; #if DEBUG @@ -63,22 +63,20 @@ namespace testexetrisathlon { Debug = args.Contains("debug"); #endif + Beeper = new Beeper(); BackgroundColor = ConsoleColor.Red; ForegroundColor = ConsoleColor.Yellow; - soundManager = OSCheck.IsWindows ? (ISoundManager) new WindowsSoundManager() : new LinuxSoundManager(); - soundManager.Init(new Dictionary + _soundManager = new SoundManager(); + _soundManager.Init(new Dictionary { - {"Intro", "testexetrisathlon.Intro.wav"}, - {"InGame1", "testexetrisathlon.InGame1.wav"}, - {"InGame2", "testexetrisathlon.InGame2.wav"}, - {"GameOver", "testexetrisathlon.GameOver.wav"} + {"Intro", "testexetrisathlon.Intro.mp3"}, + {"InGame1", "testexetrisathlon.InGame1.mp3"}, + {"InGame2", "testexetrisathlon.InGame2.mp3"}, + {"GameOver", "testexetrisathlon.GameOver.mp3"} }); - if (OSCheck.IsWindows) - { - SetWindowSize(42, 29); - if (Debug) - SetWindowSize(50, 40); - } + SizeSetter.SetWindowSize(42, 29); + if (Debug) + SizeSetter.SetWindowSize(50, 40); SetCursorPosition(0, 0); bool playing = true; GameState state = GameState.Menu; @@ -89,7 +87,7 @@ namespace testexetrisathlon { case GameState.Menu: Clear(); - soundManager.SetCurrent(Intro); + _soundManager.SetCurrent(Intro); DrawSymbol(); SetCursorPosition(12, 18); Write("HighScore: " + SettingsMan.HighScore); @@ -124,7 +122,7 @@ namespace testexetrisathlon } break; case GameState.Game: - soundManager.SetCurrent(InGame); + _soundManager.SetCurrent(InGame); _dropTimer.Start(); SetCursorPosition(25, 0); WriteLine("Level " + _level); @@ -143,7 +141,7 @@ namespace testexetrisathlon break; case GameState.GameOver: SettingsMan.HighScore = _score; - soundManager.SetCurrent(GameOver); + _soundManager.SetCurrent(GameOver); string input = ""; while (input != "y" && input != "n") { @@ -179,7 +177,7 @@ namespace testexetrisathlon } finally { - soundManager.Dispose(); + _soundManager.Dispose(); } BackgroundColor = Colors[0]; ForegroundColor = Colors[1]; @@ -262,7 +260,7 @@ namespace testexetrisathlon } break; } - soundManager.SetVolume(SettingsMan.Volume * 10); + _soundManager.SetVolume(SettingsMan.Volume * 10); } } diff --git a/testexetrisathlon/SoundManagement/IBeeper.cs b/testexetrisathlon/SoundManagement/IBeeper.cs new file mode 100644 index 0000000..f152dcf --- /dev/null +++ b/testexetrisathlon/SoundManagement/IBeeper.cs @@ -0,0 +1,9 @@ +using System; + +namespace testexetrisathlon.SoundManagement +{ + public interface IBeeper : IDisposable + { + public void Beep(int frequency, int duration); + } +} \ No newline at end of file diff --git a/testexetrisathlon/SoundManagement/Beeper.cs b/testexetrisathlon/SoundManagement/LinuxBeeper.cs similarity index 57% rename from testexetrisathlon/SoundManagement/Beeper.cs rename to testexetrisathlon/SoundManagement/LinuxBeeper.cs index 3235b5b..0aabaf1 100644 --- a/testexetrisathlon/SoundManagement/Beeper.cs +++ b/testexetrisathlon/SoundManagement/LinuxBeeper.cs @@ -5,28 +5,23 @@ using Bassoon; namespace testexetrisathlon.SoundManagement { - public static class Beeper + public class Beeper : IBeeper { private static readonly Dictionary, Tuple> Beeps = new Dictionary, Tuple>(); - public static void Beep(int frequency, int duration) + public void Beep(int frequency, int duration) { - if (OSCheck.IsWindows) - Console.Beep(frequency, duration); - else + Tuple key = new Tuple(frequency, duration); + if (!Beeps.ContainsKey(key)) { - Tuple key = new Tuple(frequency, duration); - if (!Beeps.ContainsKey(key)) - { - string file = Path.GetTempFileName(); - File.Move(file, Path.ChangeExtension(file, "wav")); - file = Path.ChangeExtension(file, "wav"); - File.WriteAllBytes(file, BeepBeep(1000, frequency, duration)); - Beeps.Add(key, new Tuple(file, new Sound(file))); - } - Beeps[key].Item2.Cursor = 0; - Beeps[key].Item2.Play(); - Console.Clear(); + string file = Path.GetTempFileName(); + File.Move(file, Path.ChangeExtension(file, "wav")); + file = Path.ChangeExtension(file, "wav"); + File.WriteAllBytes(file, BeepBeep(1000, frequency, duration)); + Beeps.Add(key, new Tuple(file, new Sound(file))); } + Beeps[key].Item2.Cursor = 0; + Beeps[key].Item2.Play(); + Console.Clear(); } private static byte[] BeepBeep(int amplitude, int frequency, int duration) @@ -51,10 +46,9 @@ namespace testexetrisathlon.SoundManagement return ms.ToArray(); } - public static void Dispose() + public void Dispose() { - if (OSCheck.IsWindows) - foreach (Tuple file in Beeps.Values) File.Delete(file.Item1); + foreach (Tuple file in Beeps.Values) File.Delete(file.Item1); } } } \ No newline at end of file diff --git a/testexetrisathlon/SoundManagement/LinuxSoundManager.cs b/testexetrisathlon/SoundManagement/LinuxSoundManager.cs index fa36508..3b7a873 100644 --- a/testexetrisathlon/SoundManagement/LinuxSoundManager.cs +++ b/testexetrisathlon/SoundManagement/LinuxSoundManager.cs @@ -6,7 +6,7 @@ using Bassoon; namespace testexetrisathlon.SoundManagement { - public class LinuxSoundManager : ISoundManager + public class SoundManager : ISoundManager { private BassoonEngine _bassoon; private Dictionary _loadedSounds; diff --git a/testexetrisathlon/SoundManagement/WindowsBeeper.cs b/testexetrisathlon/SoundManagement/WindowsBeeper.cs new file mode 100644 index 0000000..19ebcc8 --- /dev/null +++ b/testexetrisathlon/SoundManagement/WindowsBeeper.cs @@ -0,0 +1,12 @@ +using System; + +namespace testexetrisathlon.SoundManagement +{ + public class Beeper : IBeeper + { + public void Beep(int frequency, int duration) => Console.Beep(frequency, duration); + public void Dispose() + { + } + } +} \ No newline at end of file diff --git a/testexetrisathlon/SoundManagement/WindowsSoundManager.cs b/testexetrisathlon/SoundManagement/WindowsSoundManager.cs index 92de78a..92c9736 100644 --- a/testexetrisathlon/SoundManagement/WindowsSoundManager.cs +++ b/testexetrisathlon/SoundManagement/WindowsSoundManager.cs @@ -1,11 +1,12 @@ using System.Collections.Generic; +using System.IO; using System.Linq; using System.Reflection; using NAudio.Wave; namespace testexetrisathlon.SoundManagement { - public sealed class WindowsSoundManager : ISoundManager + public sealed class SoundManager : ISoundManager { private static readonly Assembly Assembly = Assembly.GetExecutingAssembly(); private WaveStream _current; @@ -17,7 +18,7 @@ namespace testexetrisathlon.SoundManagement { _output = new WaveOutEvent(); _loadedSounds = manifestResources.ToDictionary(s => s.Key, - s => new LoopStream(new WaveFileReader(Assembly.GetManifestResourceStream(s.Value)))); + s => new LoopStream(new WaveFileReader(Mp3ToWav(Assembly.GetManifestResourceStream(s.Value))))); } public void SetCurrent(string id) @@ -39,5 +40,15 @@ namespace testexetrisathlon.SoundManagement foreach (LoopStream reader in _loadedSounds.Values) reader.Dispose(); _output.Dispose(); } + + private static MemoryStream Mp3ToWav(Stream mp3File) + { + using Mp3FileReader reader = new Mp3FileReader(mp3File); + using WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(reader); + MemoryStream ms = new MemoryStream(); + WaveFileWriter.WriteWavFileToStream(ms, pcmStream); + ms.Position = 0; + return ms; + } } } \ No newline at end of file diff --git a/testexetrisathlon/Tetrominoe.cs b/testexetrisathlon/Tetrominoe.cs index 34d18a8..357a7f6 100644 --- a/testexetrisathlon/Tetrominoe.cs +++ b/testexetrisathlon/Tetrominoe.cs @@ -86,7 +86,7 @@ namespace testexetrisathlon { Location.ForEach(s => Program.DroppedTetrominoeLocationGrid[s[0], s[1]] = 1); Program.IsDropped = true; - Beeper.Beep(800, 200); + Program.Beeper.Beep(800, 200); } else { diff --git a/testexetrisathlon/WindowsSizeSetter.cs b/testexetrisathlon/WindowsSizeSetter.cs new file mode 100644 index 0000000..1f4863d --- /dev/null +++ b/testexetrisathlon/WindowsSizeSetter.cs @@ -0,0 +1,9 @@ +using System; + +namespace testexetrisathlon +{ + public static class SizeSetter + { + public static void SetWindowSize(int width, int height) => Console.SetWindowSize(width, height); + } +} \ No newline at end of file diff --git a/testexetrisathlon/testexetrisathlon.csproj b/testexetrisathlon/testexetrisathlon.csproj index b7473dc..2f6505b 100644 --- a/testexetrisathlon/testexetrisathlon.csproj +++ b/testexetrisathlon/testexetrisathlon.csproj @@ -8,7 +8,7 @@ false - + if exist "$(SolutionDir)Data\pkgtool.exe" ($(SolutionDir)Data\pkgtool.exe build --noLogo --binDir .) else if exist "%appdata%\UpTool2\Apps\0e35d154-d0d3-45e0-b080-62f521263a44\app\pkgtool.exe" ("%appdata%\UpTool2\Apps\0e35d154-d0d3-45e0-b080-62f521263a44\app\pkgtool.exe" build --noLogo --binDir .) else echo Cound not find Package build tools, skipping @@ -19,16 +19,20 @@ tetris_yUxH6t_256px.ico - - - - - - + + + + + + + + + + - - + + \ No newline at end of file