1 /**
2 * Copyright 2017 Cut Through Recordings
3 * License: MIT License
4 * Author(s): Ethan Reker
5 */
6 module ddsp.util.time;
7 
8 import ddsp.util.functions;
9 
10 static immutable float sixtyfourth = 0.015625f;
11 static immutable float thirtysecond = 0.03125f;
12 static immutable float sixteenth = 0.0625f;
13 static immutable float eight = 0.125;
14 static immutable float quarter = 0.25f;
15 static immutable float half = 0.5f;
16 static immutable float whole = 1;
17 
18 
19 /*struct Note
20 {
21     float tempo;
22     float length;
23     
24     float getTimeInMilliseconds()
25     {
26         return (1 / tempo) * length * 60000;
27     }
28     
29     float getTimeInSeconds()
30     {
31         return (1 / tempo) * length * 60;
32     }
33     
34     float getTimeInMinutes()
35     {
36         return (1 / tempo) * length;
37     }
38 }*/
39 struct Note
40 {
41     float baseLength;
42     int multiplier;
43     
44     float getTimeInMilliseconds(float tempo)
45     {
46         return (1 / tempo) * baseLength * cast(float)multiplier * 60000;
47     }
48     
49     float getTimeInSamples(float sampleRate, float tempo)
50     {
51         return msToSamples(getTimeInMilliseconds(tempo), sampleRate);
52     }
53 }
54 
55 struct TimeCursor
56 {
57     float _tempo;
58     float _currentSample;
59     float _isPlaying;
60     float _sampleRate;
61     
62     void initialize(float sampleRate)
63     {
64         _sampleRate = sampleRate;
65     }
66     
67     void updateTimeInfo(float tempo, float currentSample, bool isPlaying)
68     {
69         _tempo = tempo;
70         _currentSample = currentSample;
71         _isPlaying = isPlaying;
72     }
73     
74     bool currentPosIsNoteMultiple(float noteLength)
75     {
76         float noteTimeInSamples = msToSamples((1 / _tempo) * noteLength * 60000, _sampleRate);
77         bool isMultiple;
78         _currentSample % noteTimeInSamples == 0 ? isMultiple = true : isMultiple = false;
79         return isMultiple;
80     }
81 }
82 
83 unittest
84 {
85     
86 }