-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrackRecorder.cs
More file actions
62 lines (52 loc) · 1.59 KB
/
TrackRecorder.cs
File metadata and controls
62 lines (52 loc) · 1.59 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
using System;
using System.Collections.Generic;
namespace PianoEnhancer
{
internal class TrackRecorder
{
private long _recordStartTime;
private long _recordLength;
public bool IsRecording { get; private set; }
public Recording Recording
{
get { return _recording ??= new Recording(_track); }
}
private Recording _recording;
private IList<Chord> _track;
public TrackRecorder()
{
_track = new List<Chord>();
}
public void CreateNewRecording()
{
_track = new List<Chord>();
_recording = null;
IsRecording = false;
_recordLength = 0;
}
public void StartRecording()
{
IsRecording = true;
_recordStartTime = DateTime.Now.Ticks/ Configuration.TimeResolution;
}
public void StopRecording()
{
IsRecording = false;
_recordLength += DateTime.Now.Ticks / Configuration.TimeResolution - _recordStartTime;
}
public void SaveRecording(string filename)
{
Recording.SaveToFile(filename);
}
public void LoadRecording(string filename)
{
_recording = Recording.LoadFromFile(filename);
}
public void RecordChord(Chord chord)
{
if (!IsRecording) return;
var correctedChord = new Chord(_recordLength + DateTime.Now.Ticks/ Configuration.TimeResolution - _recordStartTime,chord.Notes);
_track.Add(correctedChord);
}
}
}