-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecording.cs
More file actions
67 lines (58 loc) · 1.84 KB
/
Recording.cs
File metadata and controls
67 lines (58 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace PianoEnhancer
{
[JsonConverter(typeof(RecordingSerializer))]
internal class Recording
{
public IList<Chord> Track { get; }
public IDictionary<int,VoiceComposition> VoiceSwitchPoints { get; }
public Recording(IList<Chord> track)
{
Track = track;
VoiceSwitchPoints = new Dictionary<int, VoiceComposition>();
}
public Recording(IList<Chord> track, IDictionary<int, VoiceComposition> switchPoints)
{
Track = track;
VoiceSwitchPoints = switchPoints;
}
public static Recording LoadFromFile(string filename)
{
string jsonText;
using (var reader = new StreamReader(filename))
{
jsonText = reader.ReadToEnd();
}
var result = JsonSerializer.Deserialize<Recording>(jsonText);
return result;
}
public void SaveToFile(string filename)
{
using var writer = new StreamWriter(filename);
writer.Write(JsonSerializer.Serialize(this));
}
public IEnumerable<KeyValuePair<int, VoiceComposition>> GetSwitchPoints()
{
return VoiceSwitchPoints.OrderBy(x=>x.Key);
}
public void SetVoice(int point, VoiceComposition voice)
{
if (VoiceSwitchPoints.ContainsKey(point))
{
VoiceSwitchPoints[point] = voice;
}
else
{
VoiceSwitchPoints.Add(point,voice);
}
}
public void RemoveVoice(int point)
{
if (VoiceSwitchPoints.ContainsKey(point)) VoiceSwitchPoints.Remove(point);
}
}
}