Skip to content

Commit

Permalink
Fix continue logic for battle and ambient tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
644 committed Oct 7, 2021
1 parent 3486144 commit 4442d16
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Config/config.default.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"MusicPath": "tracks",
"BattleTimer": 10,
"AmbientTimer": 60,
"RoomTracks": {
"0_1": "Battle_00.ogg",
"1_2": "Battle_03.ogg",
Expand All @@ -12,6 +14,7 @@
"110_4": "Battle_03.ogg",
"104_4": "Battle_01.ogg",
"111_4": "T_boss.ogg",
"101_5": "Battle_03.ogg",
"102_5": "Battle_03.ogg",
"110_5": "Battle_03.ogg",
"104_5": "Battle_01.ogg",
Expand Down
3 changes: 3 additions & 0 deletions Config/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"MusicPath": "tracks",
"BattleTimer": 10,
"AmbientTimer": 60,
"RoomTracks": {
"0_1": "Battle_00.ogg",
"1_2": "Battle_03.ogg",
Expand All @@ -12,6 +14,7 @@
"110_4": "Battle_03.ogg",
"104_4": "Battle_01.ogg",
"111_4": "T_boss.ogg",
"101_5": "Battle_03.ogg",
"102_5": "Battle_03.ogg",
"110_5": "Battle_03.ogg",
"104_5": "Battle_01.ogg",
Expand Down
4 changes: 4 additions & 0 deletions DMC3MusicConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public class DMC3MusicConfig
public bool Shuffle { get; set; }
public List<string> ShuffleRotation { get; set; }

public int BattleTimer { get; set; }

public int AmbientTimer { get; set; }

internal object GetEnumerator()
{
throw new NotImplementedException();
Expand Down
105 changes: 104 additions & 1 deletion Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ private void Form1_Load(object sender, EventArgs e)
{
shuffleCheckBox.Checked = Config.Shuffle;
changeShuffle.Enabled = shuffleCheckBox.Checked;
numericUpDown1.Value = Config.BattleTimer;
numericUpDown2.Value = Config.AmbientTimer;
}
void OnVolumeSliderChanged(object sender, EventArgs e)
{
Expand Down Expand Up @@ -201,6 +203,24 @@ private void EnableConfigControls()
pictureBox2.Enabled = true;
}

private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
if (Config.BattleTimer != (int)numericUpDown1.Value)
{
Config.BattleTimer = (int)numericUpDown1.Value;
ConfigChanged = true;
}
}

private void numericUpDown2_ValueChanged(object sender, EventArgs e)
{
if (Config.AmbientTimer != (int)numericUpDown2.Value)
{
Config.AmbientTimer = (int)numericUpDown2.Value;
ConfigChanged = true;
}
}

#endregion
}
}
9 changes: 9 additions & 0 deletions Form1.resx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@
<metadata name="toolTip3.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>211, 17</value>
</metadata>
<metadata name="toolTip7.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>599, 17</value>
</metadata>
<metadata name="toolTip6.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>502, 17</value>
</metadata>
<metadata name="toolTip8.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>696, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
Expand Down
39 changes: 36 additions & 3 deletions SongPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class SongPlayer

public int RoomId { get; set; }

public int oldMissionNumber { get; set; }

public int EnemiesGoneTimer { get; set; }

public bool AmbientIsPlaying { get; set; }
Expand All @@ -25,6 +27,8 @@ public class SongPlayer

public Dictionary<string, double> TrackPositions { get; set; } = new Dictionary<string, double>();

public Dictionary<string, long> TrackStartTime { get; set; } = new Dictionary<string, long>();

public string OldTrack { get; set; }

private DMC3MusicConfig Config { get; set; }
Expand All @@ -40,6 +44,13 @@ public SongPlayer(DMC3MusicConfig config)

public void PlayRoomSong(int roomId, int enemyCount, int missionNumber)
{
if(missionNumber != oldMissionNumber)
{
oldMissionNumber = missionNumber;
TrackPositions.Clear();
TrackStartTime.Clear();
}

if (Config.Shuffle)
{
if (OutputDevice.PlaybackState == PlaybackState.Playing)
Expand Down Expand Up @@ -130,10 +141,23 @@ public void PlayRoomSong(int roomId, int enemyCount, int missionNumber)

try
{
if (TrackPositions.TryGetValue(track, out double pos) && Convert.ToInt32(pos / 1000) < TrackLength && AmbientIsPlaying)
long currentTime = 0;
long startTime = 0;

if(TrackStartTime.TryGetValue(OldTrack, out startTime)){
currentTime = DateTimeOffset.Now.ToUnixTimeMilliseconds();
}

if (TrackPositions.TryGetValue(track, out double pos) && Convert.ToInt32(pos / 1000) < TrackLength)
{
Console.WriteLine(Convert.ToInt32(pos / 1000).ToString() + " " + TrackLength.ToString());
vorbis.Skip(Convert.ToInt32(pos / 1000));
if ((AmbientIsPlaying && currentTime - startTime < (Config.AmbientTimer * 1000)) || currentTime - startTime < (Config.BattleTimer * 1000))
{
vorbis.Skip(Convert.ToInt32(pos / 1000));
}
}
else
{
TrackPos = 0;
}
}
catch { }
Expand All @@ -142,6 +166,15 @@ public void PlayRoomSong(int roomId, int enemyCount, int missionNumber)
OutputDevice.Volume = OldVolume;
OutputDevice.Init(vorbis);
OutputDevice.Play();
long timeStarted = DateTimeOffset.Now.ToUnixTimeMilliseconds();
if (TrackStartTime.TryGetValue(OldTrack, out _))
{
TrackStartTime[OldTrack] = timeStarted;
}
else
{
TrackStartTime.Add(OldTrack, timeStarted);
}
Console.WriteLine(track);
}
}
Expand Down

0 comments on commit 4442d16

Please sign in to comment.