-
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.
- Loading branch information
1 parent
4529bbb
commit 41e453e
Showing
4 changed files
with
56 additions
and
2 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
41 changes: 41 additions & 0 deletions
41
HarmonyDB.Index/HarmonyDB.Index.Api/Services/InputParser.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,41 @@ | ||
using HarmonyDB.Common.Representations.OneShelf; | ||
using HarmonyDB.Index.Analysis.Models; | ||
using HarmonyDB.Index.Analysis.Services; | ||
|
||
namespace HarmonyDB.Index.Api.Services; | ||
|
||
public class InputParser | ||
{ | ||
private readonly ProgressionsBuilder _progressionsBuilder; | ||
private readonly ChordDataParser _chordDataParser; | ||
|
||
public InputParser(ProgressionsBuilder progressionsBuilder, ChordDataParser chordDataParser) | ||
{ | ||
_progressionsBuilder = progressionsBuilder; | ||
_chordDataParser = chordDataParser; | ||
} | ||
|
||
public HarmonyMovementsSequence Parse(string input) | ||
{ | ||
var html = new NodeHtml | ||
{ | ||
Name = "pre", | ||
Children = input | ||
.Split(' ', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) | ||
.Select(c => new NodeChord | ||
{ | ||
Children = [new NodeText(c).AsChild()] | ||
}.AsChild()) | ||
.ToList(), | ||
}; | ||
var chordsProgression = | ||
_progressionsBuilder.BuildProgression(html.AsChords(new()).Select(_chordDataParser.GetProgressionData) | ||
.ToList()); | ||
|
||
var sequence = chordsProgression.ExtendedHarmonyMovementsSequences.Single(); | ||
|
||
Console.WriteLine(string.Join(" ", sequence.Movements.Select(m => m.Title))); | ||
|
||
return sequence; | ||
} | ||
} |
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