-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
92 lines (78 loc) · 3.76 KB
/
Copy pathProgram.cs
File metadata and controls
92 lines (78 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using SharpMod;
using SharpModConsolePlayer.Renderer;
namespace SharpModConsolePlayer {
internal static class Program {
static readonly string[] supportedExtensions = [".mod", ".stm", ".s3m", ".xm"];
static SoundFile? currentSoundFile;
static async Task Main(string[] args) {
Cli? cli = Cli.Parse(args);
if(cli == null) return;
List<string> filesToPlay = [];
foreach(string input in cli.ModFiles) {
if(File.Exists(input)) {
filesToPlay.Add(input);
} else if(input.Contains('?') || input.Contains('*')) {
string directory = Path.GetDirectoryName(input) ?? ".";
string pattern = Path.GetFileName(input);
if(!Directory.Exists(directory)) {
Console.WriteLine($"Directory not found: {directory}");
continue;
}
string[] files = [.. Directory.GetFiles(directory, pattern, SearchOption.AllDirectories).Where(f => supportedExtensions.Contains(Path.GetExtension(f).ToLowerInvariant()))];
if(cli.Randomize) {
Random rng = new();
files = [.. files.OrderBy(_ => rng.Next())];
}
if(files.Length == 0) {
Console.WriteLine($"No files found matching pattern '{pattern}' in directory: {directory}");
continue;
}
filesToPlay.AddRange(files);
} else if(Directory.Exists(input)) {
string[] files = [..Directory.GetFiles(input, "*.*", SearchOption.AllDirectories).Where(f => supportedExtensions.Contains(Path.GetExtension(f).ToLowerInvariant()))];
if(cli.Randomize) {
Random rng = new();
files = [.. files.OrderBy(_ => rng.Next())];
}
if(files.Length == 0) {
Console.WriteLine($"No files found in directory: {input}");
continue;
}
filesToPlay.AddRange(files);
} else {
Console.WriteLine($"File or directory not found: {input}");
}
}
if(filesToPlay.Count == 0) {
Console.WriteLine("No valid files to play.");
return;
}
ConsoleRenderer.InitializeConsole();
Samples.RowsPerSample = cli.SampleHeight;
Samples.ShowMetadata = cli.ShowMetadata;
_ = Task.Run(() => ConsoleRenderer.RenderLoop(() => currentSoundFile));
OpenAlStreamPlayer.PlaylistCount = filesToPlay.Count;
int idx = 0;
while(idx >= 0 && idx < filesToPlay.Count) {
OpenAlStreamPlayer.PlaylistIndex = idx;
cli.ModFile = filesToPlay[idx];
await PlayFile(cli);
PlaybackRequest req = OpenAlStreamPlayer.request;
OpenAlStreamPlayer.request = PlaybackRequest.None;
if(req == PlaybackRequest.Quit) break;
if(req == PlaybackRequest.Previous) idx--;
else idx++;
}
ConsoleRenderer.RestoreConsole();
}
static async Task PlayFile(Cli cli) {
SoundFile sf = OpenAlStreamPlayer.LoadSoundFile(cli);
if(cli.ExportPath.Length > 0) {
WavExporter.Export(sf, cli.ExportPath, cli.SampleRate, cli.BitDepth, cli.Channels);
return;
}
currentSoundFile = sf;
await OpenAlStreamPlayer.Play(sf, cli.SampleRate, cli.BitDepth, cli.Channels);
}
}
}