Skip to content

Commit

Permalink
Updated grammar to be clearner, and have NoteLetters cover a double o…
Browse files Browse the repository at this point in the history
…ctave.
  • Loading branch information
pgeerkens committed May 9, 2016
1 parent c7bd44c commit b01e95d
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 334 deletions.
35 changes: 18 additions & 17 deletions Music/IMusicParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public static string AsString(this SharpFlat sharpFlat) {
#endregion SharpFlat extensions

#region OctaveShift extensions
/// <summary>TODO</summary>
/// <summary>TODO</summary>
public static OctaveShift FromString(this OctaveShift octaveShift, string value) {
switch (value.Trim(new char[] {'o','O'})) {
case "<": return OctaveShift.Down;
Expand All @@ -183,29 +183,30 @@ public static OctaveShift FromString(this OctaveShift octaveShift, string value)
"input string must end in '<' or '>'.");
}
}
/// <summary>TODO</summary>
/// <summary>TODO</summary>
public static string AsString(this OctaveShift shift) { return shift.ToString(); }
#endregion OctaveShift extensions

#region NoteLettter extensions
/// <summary>TODO</summary>
/// <summary>TODO</summary>
public static NoteLetter Parse (this NoteLetter letter, string s) {
return (NoteLetter)System.Enum.Parse(typeof(NoteLetter),s);
}
/// <summary>
/// Returns the index for the base note according to:
/// <b>F</b>ather <b>C</b>harles <b>G</b>oes <b>D</b>own <b>A</b>nd <b>E</b>nds <B>B</B>attle.
/// </summary>
/// <param name="baseNote"></param>
/// <returns></returns>
public static Int16 FCGDAEB(this NoteLetter baseNote) {
return (Int16)"FCGDAEB".IndexOf(baseNote.ToString()[0]);
/// <summary>
/// Returns the index for the base note according to:
/// <b>F</b>ather <b>C</b>harles <b>G</b>oes <b>D</b>own <b>A</b>nd <b>E</b>nds <B>B</B>attle.
/// </summary>
/// <param name="baseNote"></param>
/// <returns></returns>
public static Int16 FCGDAEB(this NoteLetter baseNote) {
return (Int16)"FCGDAEB".IndexOf(baseNote.ToString()[0]);
}
/// <summary>TODO</summary>
/// <summary>TODO</summary>
public static int SemitonesFromC (this NoteLetter note) {
return (new int[] {0, 2, 4, 5, 7, 9,11}) [(int)note];
return (new int[] { 0, 2, 4, 5, 7, 9,11
,12,14,16,17,19,21,23}) [(int)note];
}
/// <summary>TODO</summary>
/// <summary>TODO</summary>
public static int NoteIndex (this NoteLetter note) {
return "CDEFGABcdefgab".IndexOf(note.ToString());
}
Expand Down Expand Up @@ -247,19 +248,19 @@ public static NoteLetter BaseNote(this Mode mode) {
#endregion Mode extensions

#region PianoKey extensions
/// <summary>TODO</summary>
/// <summary>TODO</summary>
public static int Octave(this PianoKey @this) {
return ((int)@this + 8) / 12;
}
/// <summary>TODO</summary>
/// <summary>TODO</summary>
public static NoteLetter Letter(this PianoKey @this, int countSharps = 0) {
var noteNo = ((new int[] {4,5,6,6,0,0,1,2,2,3,3,4}) [((int)@this) % 12]);
// C D E F G A B // favour G# in sharp keys; A_ otherwise
if ((new int[] {7,0,0,4,0,6,0,0,1,0,5,0})[noteNo] >= countSharps && countSharps>0) noteNo--;
if ((new int[] {0,4,0,0,7,0,5,0,0,0,0,6})[noteNo] >=-countSharps && countSharps<0) noteNo++;
return (NoteLetter)noteNo;
}
/// <summary>TODO</summary>
/// <summary>TODO</summary>
public static SharpFlat Accidental(this PianoKey key) {
var index = ((int)key) % 12;
return (SharpFlat)((new int[] {-1,0,-1,0,0,1,0,-1,0,0,1,0})[index]);
Expand Down
4 changes: 2 additions & 2 deletions Music/Note.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ private static Double Freq(PianoKey noteNum) {
/// <summary>TODO</summary>
public static PianoKey KeyNumber(NoteLetter noteLetter, Int16 octave, SharpFlat sharpFlat) {
int keyNo = (4 + (octave-1) * 12 + (int)noteLetter.SemitonesFromC() + (int)sharpFlat);
if (!Enum.IsDefined(typeof(PianoKey),keyNo)) throw new ArgumentOutOfRangeException(
"KeyNo",keyNo,"Must be between 1 and 88.");
//if (!Enum.IsDefined(typeof(PianoKey),keyNo)) throw new ArgumentOutOfRangeException(
// "KeyNo",keyNo,"Must be between 1 and 88.");
return checked((PianoKey)keyNo);
}
/// <inherited/>
Expand Down
39 changes: 0 additions & 39 deletions PInvoke/PInvoke.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,6 @@
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<NoWarn>1607</NoWarn>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
Expand Down
11 changes: 3 additions & 8 deletions QABCIronyParser/QabcAstNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ public virtual SharpFlat SharpFlat {
}
private Int16 Octave { get; set; }
}
public class MusicBarAstNode : PitchAstNode {
public override PianoKey PianoKey { get { return PianoKey.Bar; } }
public override NoteLetter NoteLetter { get { return NoteLetter.C; } }
public override SharpFlat SharpFlat { get { return SharpFlat.Natural; } }
}
public class RestAstNode : PitchAstNode {
public override PianoKey PianoKey { get { return PianoKey.Rest; } }
public override NoteLetter NoteLetter { get { return NoteLetter.C; } }
Expand All @@ -125,8 +120,8 @@ public class RestAstNode : PitchAstNode {
public class DotsAstNode : ValueNode<QabcAstContext,byte> {
public override byte Value { get { return (byte)ChildNodes.Count; } }
}
#endregion Note Nodes
#endregion Note Nodes

public class BeamAstNode : QabcAstNode {}
public class MusicLineAstNode : QabcAstNode {}
public class BeamAstNode : QabcAstNode {}
public class MusicBarAstNode : QabcAstNode {}
}
Loading

0 comments on commit b01e95d

Please sign in to comment.