-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from pavel-zhur/feature/key-detection-12
Feature/key detection 12
- Loading branch information
Showing
220 changed files
with
8,818 additions
and
1,400 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
HarmonyDB.Index/HarmonyDB.Index.Analysis.Em/HarmonyDB.Index.Analysis.Em.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<PackageReadmeFile>readme.md</PackageReadmeFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\nuget readme.md" Pack="true" Link="nuget readme.md" PackagePath="\readme.md" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
28 changes: 28 additions & 0 deletions
28
HarmonyDB.Index/HarmonyDB.Index.Analysis.Em/Models/Constants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace HarmonyDB.Index.Analysis.Em.Models; | ||
|
||
public static class Constants | ||
{ | ||
public const int TonicCount = 12; // Number of different tonics | ||
public const int ScaleCount = 2; // Major and Minor | ||
|
||
public static IReadOnlyList<(byte tonic, byte scale)> Indices { get; } | ||
= Enumerable | ||
.Range(0, TonicCount) | ||
.SelectMany(i => Enumerable.Range(0, ScaleCount).Select(j => ((byte)i, (byte)j))) | ||
.ToList(); | ||
|
||
public static IReadOnlyList<(byte tonic, Scale scale)> Pairs { get; } | ||
= Indices.Select(x => (x.tonic, (Scale)x.scale)).ToList(); | ||
|
||
public static int GetMajorTonic((byte tonic, Scale scale) scale, bool isSong) | ||
{ | ||
return scale.scale == Scale.Major ? scale.tonic : GetRelativeScale(scale, isSong).tonic; | ||
} | ||
|
||
public static (byte tonic, Scale scale) GetRelativeScale((byte tonic, Scale scale) scale, bool isSong) | ||
{ | ||
return scale.scale == Scale.Major | ||
? ((byte)((scale.tonic + (isSong ? -3 : 3) + TonicCount) % TonicCount), Scale.Minor) | ||
: ((byte)((scale.tonic + (isSong ? 3 : -3) + TonicCount) % TonicCount), Scale.Major); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
HarmonyDB.Index/HarmonyDB.Index.Analysis.Em/Models/EmContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace HarmonyDB.Index.Analysis.Em.Models; | ||
|
||
public sealed class EmContext | ||
{ | ||
public required ILookup<string, LoopLink> LoopLinksBySongId { get; init; } | ||
public required ILookup<string, LoopLink> LoopLinksByLoopId { get; init; } | ||
public required IReadOnlyDictionary<string, int> SongCounts { get; init; } | ||
} |
7 changes: 7 additions & 0 deletions
7
HarmonyDB.Index/HarmonyDB.Index.Analysis.Em/Models/IEmModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace HarmonyDB.Index.Analysis.Em.Models; | ||
|
||
public interface IEmModel | ||
{ | ||
IReadOnlyCollection<Song> Songs { get; } | ||
IReadOnlyCollection<Loop> Loops { get; } | ||
} |
8 changes: 8 additions & 0 deletions
8
HarmonyDB.Index/HarmonyDB.Index.Analysis.Em/Models/ISource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace HarmonyDB.Index.Analysis.Em.Models; | ||
|
||
public interface ISource | ||
{ | ||
string Id { get; } | ||
float[,] TonalityProbabilities { get; set; } // [TonicCount, ScaleCount] | ||
(float TonicScore, float ScaleScore) Score { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace HarmonyDB.Index.Analysis.Em.Models; | ||
|
||
public class Loop : ISource | ||
{ | ||
public required string Id { get; init; } | ||
public float[,] TonalityProbabilities { get; set; } = new float[Constants.TonicCount, Constants.ScaleCount]; | ||
public (float TonicScore, float ScaleScore) Score { get; set; } | ||
} |
11 changes: 11 additions & 0 deletions
11
HarmonyDB.Index/HarmonyDB.Index.Analysis.Em/Models/LoopLink.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace HarmonyDB.Index.Analysis.Em.Models; | ||
|
||
public record LoopLink | ||
{ | ||
public required Loop Loop { get; init; } | ||
public required Song Song { get; init; } | ||
public string SongId => Song.Id; | ||
public string LoopId => Loop.Id; | ||
public required byte Shift { get; init; } | ||
public required float Weight { get; init; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace HarmonyDB.Index.Analysis.Em.Models; | ||
|
||
public enum Scale : byte | ||
{ | ||
Major, | ||
Minor | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace HarmonyDB.Index.Analysis.Em.Models; | ||
|
||
public class Song : ISource | ||
{ | ||
public required string Id { get; init; } | ||
public float[,] TonalityProbabilities { get; set; } = new float[Constants.TonicCount, Constants.ScaleCount]; | ||
public (float TonicScore, float ScaleScore) Score { get; set; } | ||
public required (byte Tonic, Scale Scale)? KnownTonality { get; init; } | ||
} |
10 changes: 10 additions & 0 deletions
10
HarmonyDB.Index/HarmonyDB.Index.Analysis.Em/ServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using HarmonyDB.Index.Analysis.Em.Services; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace HarmonyDB.Index.Analysis.Em; | ||
|
||
public static class ServiceCollectionExtensions | ||
{ | ||
public static IServiceCollection AddIndexAnalysisEm(this IServiceCollection services) => services | ||
.AddSingleton<MusicAnalyzer>(); | ||
} |
Oops, something went wrong.