Skip to content

Commit

Permalink
feature: subtune support!
Browse files Browse the repository at this point in the history
  • Loading branch information
MetalHexx committed Jul 9, 2024
1 parent ba05d7b commit b3c6bea
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TeensyRom.Core.Commands.File.LaunchFile;
using TeensyRom.Core.Serial.State;
using TeensyRom.Core.Serial;

namespace TeensyRom.Core.Commands.PlaySubtune
{
public class PlaySubtuneCommand (int subtuneIndex) : IRequest<PlaySubtuneResult>
{
public int SubtuneIndex { get; } = subtuneIndex;
}

public class PlaySubtuneResult : TeensyCommandResult;

public class PlaySubtuneHandler(ISerialStateContext serialState) : IRequestHandler<PlaySubtuneCommand, PlaySubtuneResult>
{
public async Task<PlaySubtuneResult> Handle(PlaySubtuneCommand request, CancellationToken cancellationToken)

Check warning on line 22 in Source/Windows/TeensyRom.Ui/src/TeensyRom.Core/Commands/PlaySubtune/PlaySubtuneHandler.cs

View workflow job for this annotation

GitHub Actions / build (Release)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
serialState.ClearBuffers();
serialState.SendIntBytes(TeensyToken.PlaySubtune, 2);
serialState.SendIntBytes((uint)request.SubtuneIndex - 1, 1);
serialState.HandleAck();
return new PlaySubtuneResult();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ private void EnrichWithHsvcMetadata(SongItem song, SidRecord? sidRecord)
song.Creator = sidRecord.Author;
song.Title = sidRecord.Title;
song.PlayLength = sidRecord.SongLengthSpan;
song.StartSubtuneNum = sidRecord.StartSong;
song.SubtuneLengths = sidRecord.SubTuneSongLengths.Select(s => s).ToList();
song.ReleaseInfo = sidRecord.Released;
song.Meta1 = sidRecord.Clock;
song.Meta2 = sidRecord.SidModel;
Expand Down Expand Up @@ -194,8 +196,9 @@ private static Dictionary<string, SidRecord> ParseSids(Dictionary<string, SidRec
continue;
}
var songLengths = ParseTimeSegments(sid.Value.SongLength);

sid.Value.SongLengthSpan = songLengths.Any() ? songLengths.First() : MusicConstants.DefaultLength;
sid.Value.SubTuneSongLengths = songLengths;
}
return sids;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ public class SidRecord
public string Author { get; set; } = string.Empty;
public string Released { get; set; } = string.Empty;
//public int Songs { get; set; }
//public int StartSong { get; set; }
public int StartSong { get; set; }
public string SongLength { get; set; } = string.Empty;
public TimeSpan SongLengthSpan { get; set; } = TimeSpan.FromMinutes(3);
public List<TimeSpan> SubTuneSongLengths = [];
public int SizeInBytes { get; set; }
//public string InitAddr { get; set; } = string.Empty;
//public string PlayAddr { get; set; } = string.Empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public SidRecordMap()
Map(m => m.Author).Name("AUTHOR");
Map(m => m.Released).Name("RELEASED");
//Map(m => m.Songs).Name("SONGS");
//Map(m => m.StartSong).Name("STARTSONG");
Map(m => m.StartSong).Name("STARTSONG");
Map(m => m.SongLength).Name("SONGLEN (per tune)");
Map(m => m.SizeInBytes).Name("SIZE (in bytes)");
//Map(m => m.InitAddr).Name("INITADDR");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public sealed class TeensyToken : SmartEnum<TeensyToken, ushort>
public static readonly TeensyToken StartDirectoryList = new(0x5A5A, nameof(StartDirectoryList));
public static readonly TeensyToken EndDirectoryList = new(0xA5A5, nameof(EndDirectoryList));
public static readonly TeensyToken LaunchFile = new(0x6444, nameof(LaunchFile));
public static readonly TeensyToken PlaySubtune = new(0x6488, nameof(PlaySubtune));
public static readonly TeensyToken SendFile = new(0x64BB, nameof(SendFile));
public static readonly TeensyToken CopyFile = new(0x64FF, nameof(CopyFile));
public static readonly TeensyToken GetFile = new(0x64B0, nameof(GetFile));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using System;
using System.Numerics;
using System.Text.Json.Serialization;
using TeensyRom.Core.Common;

namespace TeensyRom.Core.Storage.Entities
{
public class SongItem : FileItem, ILaunchableItem, IViewableItem
{
public TimeSpan PlayLength { get; set; } = TimeSpan.FromMinutes(3);
public List<TimeSpan> SubtuneLengths { get; set; } = [];
public int StartSubtuneNum { get; set; }
public List<ViewableItemImage> Images { get; init; } = [];

public SongItem()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<Grid Grid.Row="1" Margin="10 10 0 10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
Expand Down Expand Up @@ -134,7 +135,48 @@

</StackPanel>

<Grid Grid.Column="2"
<StackPanel
Visibility="{Binding SubtunesEnabled, Converter={StaticResource BoolToVisibilityConvertor}}"
Orientation="Horizontal" Grid.Column="2"
Margin="20 0 0 0">
<Button
Command="{Binding PreviousSubtuneCommand}"
IsEnabled="{Binding SubtunePreviousButtonEnabled}"
Style="{StaticResource MaterialDesignIconForegroundButton}"
Foreground="{DynamicResource PrimaryHueLightBrush }"
Height="30" Width="30"
ToolTip="Previous Subtune"
VerticalAlignment="Center"
Margin="0 0 2 0">
<materialDesign:PackIcon Kind="SkipPrevious"/>
</Button>

<ComboBox
x:Name="SubtubeComboBox"
ItemsSource="{Binding SubtuneIndex}"
SelectedItem="{Binding CurrentSubtuneIndex, Mode=TwoWay}"
materialDesign:TextFieldAssist.UnderlineBrush="{DynamicResource PrimaryHueLightBrush }"
FontFamily="Arial"
Height="30"
materialDesign:TextFieldAssist.PrefixText="Subtune:"
ToolTip="Change to a different subtune."
Margin="0 0 0 0"/>

<Button
Command="{Binding NextSubtuneCommand}"
IsEnabled="{Binding SubtuneNextButtonEnabled}"
Style="{StaticResource MaterialDesignIconForegroundButton}"
Foreground="{DynamicResource PrimaryHueLightBrush }"
Height="30" Width="30"
ToolTip="Next Subtune"
VerticalAlignment="Center"
Margin="2 0 10 0">
<materialDesign:PackIcon Kind="SkipNext" />
</Button>

</StackPanel>

<Grid Grid.Column="3"
HorizontalAlignment="Right" VerticalAlignment="Top"
Margin="10 0 10 0">
<Grid.ColumnDefinitions>
Expand All @@ -146,7 +188,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>

<ComboBox Grid.Column="0"
<ComboBox Grid.Column="1"
x:Name="ScopeComboBox"
ItemsSource="{Binding ScopeOptions}"
SelectedItem="{Binding SelectedScope, Mode=TwoWay}"
Expand Down Expand Up @@ -184,6 +226,15 @@
</Button>

<Button Grid.Column="3"
x:Name="ShuffleModeButton"
Command="{Binding ToggleShuffleCommand}"
ToolTip="Shuffle Mode. &#x0a;Enabling this will cause the next button to play random file from your collection. &#x0a;Disabling will play the next file in the current directory. &#x0a;The filter selected will determine the file type that gets picked."
Style="{StaticResource ShuffleModeButtonStyle}"
Margin="10">
<materialDesign:PackIcon Kind="Shuffle"/>
</Button>

<Button Grid.Column="4"
x:Name="ShareButton"
Command="{Binding ShareCommand}"
Visibility="{Binding ShareVisible, Converter={StaticResource BoolToVisibilityConvertor}, Mode=OneWay}"
Expand All @@ -194,16 +245,6 @@
<materialDesign:PackIcon Kind="Share" Margin="0 0 0 3"/>
</Button>

<Button Grid.Column="4"
x:Name="ShuffleModeButton"
Command="{Binding ToggleShuffleCommand}"
ToolTip="Shuffle Mode. &#x0a;Enabling this will cause the next button to play random file from your collection. &#x0a;Disabling will play the next file in the current directory. &#x0a;The filter selected will determine the file type that gets picked."
Style="{StaticResource ShuffleModeButtonStyle}"
Margin="10">
<materialDesign:PackIcon Kind="Shuffle"/>
</Button>


<Button
Grid.Column="5"
x:Name="FavoriteButton"
Expand Down
Loading

0 comments on commit b3c6bea

Please sign in to comment.