-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: units refactoring and minor improvements
- Loading branch information
1 parent
87ac47c
commit 93e432b
Showing
10 changed files
with
212 additions
and
363 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using SampleConsoleApp.Demos; | ||
using DarkMusicConcepts; | ||
using SampleConsoleApp.Demos; | ||
|
||
var demos = new Demo[] | ||
{ | ||
|
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 |
---|---|---|
@@ -1,37 +1,17 @@ | ||
namespace DarkMusicConcepts; | ||
|
||
public class Bpm : Unit<double, Bpm> | ||
/// <summary> | ||
/// <para>Beats per minute.</para> | ||
/// <para>In musical terminology, tempo (Italian, 'time'; plural tempos, or tempi from the Italian plural) also known as beats per minute, is the speed or pace of a given composition. In classical music, tempo is typically indicated with an instruction at the start of a piece (often using conventional Italian terms) and is usually measured in beats per minute (or bpm). In modern classical compositions, a "metronome mark" in beats per minute may supplement or replace the normal tempo marking, while in modern genres like electronic dance music, tempo will typically simply be stated in BPM.</para> | ||
/// </summary> | ||
public class Bpm : Unit<double, Bpm>, IUnit<double, Bpm> | ||
{ | ||
public const double MinValue = 0; | ||
public const double MaxValue = double.MaxValue; | ||
|
||
public static Bpm Min { get; } = From(MinValue); | ||
public static Bpm Max { get; } = From(MaxValue); | ||
public static double MinValue { get; } = 0; | ||
public static double MaxValue { get; } = double.MaxValue; | ||
|
||
private Bpm(double value) : base(value) | ||
{ | ||
} | ||
|
||
protected override double GetMinValue() => MinValue; | ||
protected override double GetMaxValue() => MaxValue; | ||
|
||
public static Bpm From(double value) | ||
{ | ||
var bpm = new Bpm(value); | ||
|
||
bpm.Validate(); | ||
|
||
return bpm; | ||
} | ||
|
||
public static bool TryFrom(double value, out Bpm bpm) | ||
{ | ||
var x = new Bpm(value); | ||
|
||
bpm = x.TryValidate() | ||
? x | ||
: null!; | ||
|
||
return bpm is not null; | ||
} | ||
static Bpm IUnit<double, Bpm>.Create(double value) => new(value); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace DarkMusicConcepts; | ||
|
||
public interface IUnit<TValue, TThis> | ||
where TValue : IComparable, IComparable<TValue>, IEquatable<TValue> | ||
{ | ||
public static abstract TValue MinValue { get; } | ||
public static abstract TValue MaxValue { get; } | ||
|
||
internal static abstract TThis Create(TValue value); | ||
public static abstract bool IsValidValue(TValue? value); | ||
} |
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
Oops, something went wrong.