Skip to content

Commit b9d8381

Browse files
committed
Fix bugs & implement smarter playback
Fix bug where if you renamed an audio file, the previous doesn't get removed. Improve command recognition Change logfile extension to support more games Add smarter play command - can now play by name and tags Fix bug with error message
1 parent 4051edc commit b9d8381

File tree

7 files changed

+99
-37
lines changed

7 files changed

+99
-37
lines changed

.vs/STARK/v14/.suo

28 KB
Binary file not shown.

STARK/AudioFileManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ private void Watcher_Renamed(object sender, RenamedEventArgs e) {
123123

124124
if (IsAudioFile(ext)) {
125125
//yes i know i could just change the name, but i'm wayyyy to lazy and tired
126-
RemoveFromCollection(e.FullPath);
127-
AddToCollection(new AudioPlaybackItem("", e.FullPath, 100));
126+
ClearCollection();
127+
LoadCurrentFiles();
128128
App.Current.Dispatcher.Invoke(delegate {
129129
(App.Current.MainWindow as MainWindow).RenderConUI();
130130
});

STARK/Command.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ public class Command {
33

44
string command { get; set; }
55
string[] splitter { get; set; }
6+
bool hasArgs = false;
67

78
/// <summary>
89
/// Creates a command and it's splitter based on the command identifier given.
910
/// </summary>
1011
/// <param name="command">The command identifier</param>
11-
public Command(string command) {
12+
public Command(string command, bool hasArgs) {
13+
this.hasArgs = hasArgs;
1214
ConstructCommand(command);
1315
}
1416

@@ -28,7 +30,12 @@ public void changeCommand(string cmd) {
2830
/// <param name="cmd">The identifier that the splitter is based on.</param>
2931
private void ConstructCommand(string cmd) {
3032
command = cmd;
31-
splitter = new string[] { ": " + command, ": " + command };
33+
//Chat Splitter, command , args splitter
34+
if (hasArgs) {
35+
splitter = new string[] { ": " + command + " ", ": " + command + " " };
36+
} else {
37+
splitter = new string[] { ": " + command, ": " + command };
38+
}
3239
}
3340

3441
public string getCommand() {

STARK/CommandManager.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
namespace STARK {
22
public static class CommandManager {
3-
public static Command synthCmd = new Command("");
4-
public static Command playCmd = new Command(".play");
5-
public static Command pauseCmd = new Command(".pause");
6-
public static Command resumeCmd = new Command(".resume");
7-
public static Command stopCmd = new Command(".stop");
3+
public static Command synthCmd = new Command("", true);
4+
public static Command playCmd = new Command(".play", true);
5+
public static Command pauseCmd = new Command(".pause", false);
6+
public static Command resumeCmd = new Command(".resume", false);
7+
public static Command stopCmd = new Command(".stop", false);
88
}
99
}

STARK/CommandReader.cs

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CommandReader : IDisposable{
2626

2727
public CommandReader(ref QueuedSpeechSynthesizer qss, ref AudioPlaybackEngine ape, ref AudioFileManager afm, SourceGame selectedGame) {
2828
this.selectedGame = selectedGame;
29-
this.logFile = selectedGame.libDir + @"\!tts-axynos.slf";
29+
this.logFile = selectedGame.libDir + @"\!tts-axynos.txt";
3030
this.qss = qss;
3131
this.ape = ape;
3232
this.afm = afm;
@@ -53,20 +53,7 @@ private void parseCommand(string line) {
5353
}
5454
}
5555
else if (ContainsCommand(line, playCmd)) {
56-
if (ape != null) {
57-
var parts = getParts(line, playCmd);
58-
string player = getPlayer(parts[0]);
59-
//Removes the leading space from the command arg
60-
string arg1 = new StringBuilder(parts[1]).Remove(0, 1).ToString();
61-
62-
int id;
63-
if (int.TryParse(arg1, out id) && id >= 0) {
64-
if (id < afm.getCollection().Count) {
65-
ape.Stop(); //you can't stop Harambe
66-
ape.Play(id);
67-
}
68-
}
69-
}
56+
TryParsePlay(line);
7057
}
7158
else if (ContainsCommand(line, pauseCmd)) {
7259
ape.Pause();
@@ -124,6 +111,71 @@ private void Loop_Elapsed(object sender, ElapsedEventArgs e) {
124111
loop.Start();
125112
}
126113

114+
private void TryParsePlay(string line) {
115+
if (ape != null) {
116+
var parts = getParts(line, playCmd);
117+
string player = getPlayer(parts[0]);
118+
string arg = parts[1];
119+
120+
Func<bool> tryPlayByTitle = () => {
121+
if (!string.IsNullOrEmpty(arg) && !string.IsNullOrWhiteSpace(arg)) {
122+
foreach (AudioPlaybackItem item in afm.getCollection()) {
123+
if (item.name.ToLower() == arg.ToLower()) {
124+
return true;
125+
}
126+
}
127+
}
128+
129+
return false;
130+
};
131+
bool canPlayByTitle = tryPlayByTitle();
132+
133+
Func<bool> tryPlayByTag = () => {
134+
if (!string.IsNullOrEmpty(arg) && !string.IsNullOrWhiteSpace(arg)) {
135+
foreach (AudioPlaybackItem item in afm.getCollection()) {
136+
foreach (string tag in item.tags) {
137+
if (tag.ToLower() == arg.ToLower()) {
138+
return true;
139+
}
140+
}
141+
}
142+
}
143+
144+
145+
return false;
146+
};
147+
bool canPlayByTag = tryPlayByTag();
148+
149+
string arg1 = new StringBuilder(parts[1]).ToString();
150+
int id;
151+
if (int.TryParse(arg1, out id) && id >= 0) {
152+
if (id < afm.getCollection().Count) {
153+
ape.Stop(); //you can't stop Harambe
154+
ape.Play(id);
155+
}
156+
} else if (canPlayByTitle) {
157+
foreach (AudioPlaybackItem item in afm.getCollection()) {
158+
if (item.name.ToLower() == parts[1].ToLower()) {
159+
ape.Stop();
160+
ape.Play(item.id);
161+
}
162+
}
163+
} else if (canPlayByTag) {
164+
foreach (AudioPlaybackItem item in afm.getCollection()) {
165+
foreach (string tag in item.tags) {
166+
if (tag.ToLower() == arg.ToLower()) {
167+
ape.Stop();
168+
ape.Play(item.id);
169+
}
170+
}
171+
}
172+
}
173+
174+
}
175+
}
176+
177+
178+
127179
//CHANGE METHODS
128180
#region "Change Methods"
129181
public void ChangePath(string path) {

STARK/ConsoleUI.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,32 @@ public void Render() {
4646
//Create help menu
4747
AddLines(ref helpContent, new string[] {
4848
"clear",
49-
"echo \"============ STARK by axynos ============\"",
49+
"echo \"================ STARK by axynos ================\"",
5050
"echo \"\"",
5151
"echo \" + Available *CONSOLE* commands:\"",
5252
"echo \"\"",
5353
"echo \" * Media\"",
5454
"echo \" - exec s_play_<id> - play file by id\"",
55-
"echo \" - s_pause - pause playback\"",
56-
"echo \" - s_resume - resume playback\"",
57-
"echo \" - s_stop - stop playback\"",
58-
"echo \" - s_tracklist - show tracklist\"",
59-
"echo \" - s_help - show this menu\"",
55+
"echo \" - s_pause - pause playback\"",
56+
"echo \" - s_resume - resume playback\"",
57+
"echo \" - s_stop - stop playback\"",
58+
"echo \" - s_tracklist - show tracklist\"",
59+
"echo \" - s_help - show this menu\"",
6060
"echo \"\"",
6161
"echo \" + Available *CHAT* commands:\"",
6262
"echo \"\"",
6363
"echo \" * Media\"",
64-
"echo \" - .play <id> - play file by id\"",
65-
"echo \" - .pause - pause playback\"",
66-
"echo \" - .resume - resume playback\"",
67-
"echo \" - .stop - stop playback\"",
64+
"echo \" - .play <id> - play file by id\"",
65+
"echo \" - .play <name> - play file by name\"",
66+
"echo \" - .play <tag> - play file by tag\"",
67+
"echo \" - .pause - pause playback\"",
68+
"echo \" - .resume - resume playback\"",
69+
"echo \" - .stop - stop playback\"",
6870
"echo \"\"",
6971
"echo \" * Text-to-Speech\"",
7072
"echo \" - " + mw.TTS_CommandTextBox.Text + " <text> - say text from tts\"",
7173
"echo \"\"",
72-
"echo \"=========================================\""
74+
"echo \"=================================================\""
7375
});
7476

7577
//Create startup
@@ -86,7 +88,7 @@ public void Render() {
8688

8789
//Create list of tracks
8890
foreach (AudioPlaybackItem item in afm.getCollection()) {
89-
tracks.Add(new TrackListItem("echo \" " + item.id + " - " + item.name + "\"", item.id));
91+
tracks.Add(new TrackListItem("echo \" " + item.id + " :: " + item.name + " :: " + item.displayTags + "\"", item.id));
9092
}
9193

9294
//Create tracklist

STARK/MainWindow.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ public MainWindow() {
101101
//DEBUG
102102
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args) {
103103
Exception e = (Exception)args.ExceptionObject;
104+
104105
var message = new System.Text.StringBuilder();
105-
message.Append("Handler Caught: " + e.Message);
106+
message.AppendLine("Handler Caught: " + e.Message);
106107
message.AppendLine("Stacktrace: " + e.StackTrace);
107108
if (e.InnerException != null) {
108109
message.AppendLine("InnerException" + e.InnerException.Message);

0 commit comments

Comments
 (0)