Skip to content

Commit

Permalink
Moved code to C# 6 and changed target framework to 4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
melanchall committed Dec 3, 2017
1 parent ac4dee8 commit df21e5d
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 63 deletions.
5 changes: 4 additions & 1 deletion DryWetMidi/Melanchall.DryWetMidi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Melanchall.DryWetMidi</RootNamespace>
<AssemblyName>Melanchall.DryWetMidi</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -21,6 +22,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\Melanchall.DryWetMidi.xml</DocumentationFile>
<LangVersion>6</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -30,6 +32,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\Melanchall.DryWetMidi.xml</DocumentationFile>
<LangVersion>6</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion DryWetMidi/Melanchall.DryWetMidi.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>Melanchall.DryWetMidi</id>
<version>2.0.0</version>
<version>2.0.1</version>
<title>DryWetMIDI</title>
<authors>melanchall</authors>
<owners>melanchall</owners>
Expand Down
4 changes: 2 additions & 2 deletions DryWetMidi/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyVersion("2.0.1.0")]
[assembly: AssemblyFileVersion("2.0.1.0")]
12 changes: 6 additions & 6 deletions DryWetMidi/Smf.Interaction/ChordsManager/Chord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ public long Length
/// -or- Unable to get channel since chord's notes have different <see cref="Note.Velocity"/>.</exception>
public FourBitNumber Channel
{
get => GetNotesProperty(ChannelPropertySelector);
set => SetNotesProperty(ChannelPropertySelector, value);
get { return GetNotesProperty(ChannelPropertySelector); }
set { SetNotesProperty(ChannelPropertySelector, value); }
}

/// <summary>
Expand All @@ -163,8 +163,8 @@ public FourBitNumber Channel
/// -or- Unable to get velocity since chord's notes have different <see cref="Note.Velocity"/>.</exception>
public SevenBitNumber Velocity
{
get => GetNotesProperty(VelocityPropertySelector);
set => SetNotesProperty(VelocityPropertySelector, value);
get { return GetNotesProperty(VelocityPropertySelector); }
set { SetNotesProperty(VelocityPropertySelector, value); }
}

/// <summary>
Expand All @@ -174,8 +174,8 @@ public SevenBitNumber Velocity
/// -or- Unable to get off velocity since chord's notes have different <see cref="Note.OffVelocity"/>.</exception>
public SevenBitNumber OffVelocity
{
get => GetNotesProperty(OffVelocityPropertySelector);
set => SetNotesProperty(OffVelocityPropertySelector, value);
get { return GetNotesProperty(OffVelocityPropertySelector); }
set { SetNotesProperty(OffVelocityPropertySelector, value); }
}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions DryWetMidi/Smf.Interaction/NotesManager/Note.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ public long Length
/// </summary>
public SevenBitNumber NoteNumber
{
get => _noteDefinition.NoteNumber;
set => _noteDefinition = NoteDefinition.Get(value);
get { return _noteDefinition.NoteNumber; }
set { _noteDefinition = NoteDefinition.Get(value); }
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,12 @@ public static IntervalDefinition Get(SevenBitNumber interval, IntervalDirection
{
ThrowIfArgument.IsInvalidEnumValue(nameof(direction), direction);

if (!_cache.TryGetValue(interval, out Dictionary<IntervalDirection, IntervalDefinition> intervalDefinitions))
Dictionary<IntervalDirection, IntervalDefinition> intervalDefinitions;
if (!_cache.TryGetValue(interval, out intervalDefinitions))
_cache.Add(interval, intervalDefinitions = new Dictionary<IntervalDirection, IntervalDefinition>());

if (!intervalDefinitions.TryGetValue(direction, out IntervalDefinition intervalDefinition))
IntervalDefinition intervalDefinition;
if (!intervalDefinitions.TryGetValue(direction, out intervalDefinition))
intervalDefinitions.Add(direction, intervalDefinition = new IntervalDefinition(interval, direction));

return intervalDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,21 @@ public ITimeSpan ConvertTo(long timeSpan, long time, TempoMap tempoMap)
var firstTimeSignature = timeSignatureLine.AtTime(time);
var lastTimeSignature = timeSignatureLine.AtTime(lastTime);

long barsBefore, beatsBefore, ticksBefore;
CalculateComponents(firstTime - time,
firstTimeSignature,
ticksPerQuarterNote,
out var barsBefore,
out var beatsBefore,
out var ticksBefore);
out barsBefore,
out beatsBefore,
out ticksBefore);

long barsAfter, beatsAfter, ticksAfter;
CalculateComponents(time + timeSpan - lastTime,
lastTimeSignature,
ticksPerQuarterNote,
out var barsAfter,
out var beatsAfter,
out var ticksAfter);
out barsAfter,
out beatsAfter,
out ticksAfter);

bars += barsBefore + barsAfter;

Expand Down Expand Up @@ -124,12 +126,13 @@ public long ConvertFrom(ITimeSpan timeSpan, long time, TempoMap tempoMap)
var lastTimeSignature = firstTimeSignatureChange?.Value ?? startTimeSignature;
var lastTime = firstTimeSignatureChange?.Time ?? time;

long barsBefore, beatsBefore, ticksBefore;
CalculateComponents(lastTime - time,
startTimeSignature,
ticksPerQuarterNote,
out var barsBefore,
out var beatsBefore,
out var ticksBefore);
out barsBefore,
out beatsBefore,
out ticksBefore);

bars -= barsBefore;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public long ConvertFrom(ITimeSpan timeSpan, long time, TempoMap tempoMap)
{
var mathTimeSpan = (MathTimeSpan)timeSpan;

if (Converters.TryGetValue(mathTimeSpan.Mode, out var converter))
Func<MathTimeSpan, long, TempoMap, long> converter;
if (Converters.TryGetValue(mathTimeSpan.Mode, out converter))
return converter(mathTimeSpan, time, tempoMap);
else
throw new ArgumentException($"{mathTimeSpan.Mode} mode is not supported by the converter.", nameof(timeSpan));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ internal static ParsingResult TryParse(string input, out BarBeatTimeSpan timeSpa
if (match == null)
return ParsingResult.NotMatched;

if (!ParsingUtilities.ParseLong(match, BarsGroupName, 0, out var bars))
long bars;
if (!ParsingUtilities.ParseLong(match, BarsGroupName, 0, out bars))
return new ParsingResult(BarsIsOutOfRange);

if (!ParsingUtilities.ParseLong(match, BeatsGroupName, 0, out var beats))
long beats;
if (!ParsingUtilities.ParseLong(match, BeatsGroupName, 0, out beats))
return new ParsingResult(BeatsIsOutOfRange);

if (!ParsingUtilities.ParseLong(match, TicksGroupName, 0, out var ticks))
long ticks;
if (!ParsingUtilities.ParseLong(match, TicksGroupName, 0, out ticks))
return new ParsingResult(BeatsIsOutOfRange);

timeSpan = new BarBeatTimeSpan(bars, beats, ticks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,20 @@ internal static ParsingResult TryParse(string input, out MetricTimeSpan timeSpan
if (match == null)
return ParsingResult.NotMatched;

if (!ParsingUtilities.ParseInt(match, HoursGroupName, 0, out var hours))
int hours;
if (!ParsingUtilities.ParseInt(match, HoursGroupName, 0, out hours))
return new ParsingResult(HoursIsOutOfRange);

if (!ParsingUtilities.ParseInt(match, MinutesGroupName, 0, out var minutes))
int minutes;
if (!ParsingUtilities.ParseInt(match, MinutesGroupName, 0, out minutes))
return new ParsingResult(MinutesIsOutOfRange);

if (!ParsingUtilities.ParseInt(match, SecondsGroupName, 0, out var seconds))
int seconds;
if (!ParsingUtilities.ParseInt(match, SecondsGroupName, 0, out seconds))
return new ParsingResult(SecondsIsOutOfRange);

if (!ParsingUtilities.ParseInt(match, MillisecondsGroupName, 0, out var milliseconds))
int milliseconds;
if (!ParsingUtilities.ParseInt(match, MillisecondsGroupName, 0, out milliseconds))
return new ParsingResult(MillisecondsIsOutOfRange);

timeSpan = new MetricTimeSpan(hours, minutes, seconds, milliseconds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ internal static ParsingResult TryParse(string input, out MidiTimeSpan timeSpan)
if (match == null)
return ParsingResult.NotMatched;

if (!ParsingUtilities.ParseLong(match, TimeSpanGroupName, 0, out var midiTimeSpan))
long midiTimeSpan;
if (!ParsingUtilities.ParseLong(match, TimeSpanGroupName, 0, out midiTimeSpan))
return new ParsingResult(OutOfRange);

timeSpan = new MidiTimeSpan(midiTimeSpan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ internal static ParsingResult TryParse(string input, out MusicalTimeSpan timeSpa

// Fraction

if (!ParsingUtilities.ParseLong(match, NumeratorGroupName, 1, out var numerator))
long numerator;
if (!ParsingUtilities.ParseLong(match, NumeratorGroupName, 1, out numerator))
return new ParsingResult(NumeratorIsOutOfRange);

if (!ParsingUtilities.ParseLong(match, DenominatorGroupName, 1, out var denominator))
long denominator;
if (!ParsingUtilities.ParseLong(match, DenominatorGroupName, 1, out denominator))
return new ParsingResult(DenominatorIsOutOfRange);

var fractionMnemonicGroup = match.Groups[FractionMnemonicGroupName];
Expand All @@ -84,10 +86,12 @@ internal static ParsingResult TryParse(string input, out MusicalTimeSpan timeSpa

// Tuplet

if (!ParsingUtilities.ParseInt(match, TupletNotesCountGroupName, 1, out var tupletNotesCount))
int tupletNotesCount;
if (!ParsingUtilities.ParseInt(match, TupletNotesCountGroupName, 1, out tupletNotesCount))
return new ParsingResult(TupletNotesCountIsOutOfRange);

if (!ParsingUtilities.ParseInt(match, TupletSpaceSizeGroupName, 1, out var tupletSpaceSize))
int tupletSpaceSize;
if (!ParsingUtilities.ParseInt(match, TupletSpaceSizeGroupName, 1, out tupletSpaceSize))
return new ParsingResult(TupletSpaceSizeIsOutOfRange);

var tupletMnemonicGroup = match.Groups[TupletMnemonicGroupName];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public static bool TryParse(string input, out BarBeatTimeSpan timeSpan)
/// <paramref name="input"/>.</returns>
public static BarBeatTimeSpan Parse(string input)
{
var parsingResult = BarBeatTimeSpanParser.TryParse(input, out var timeSpan);
BarBeatTimeSpan timeSpan;
var parsingResult = BarBeatTimeSpanParser.TryParse(input, out timeSpan);
if (parsingResult.Status == ParsingStatus.Parsed)
return timeSpan;

Expand Down Expand Up @@ -207,7 +208,8 @@ private static void CalculateDifferencies(BarBeatTimeSpan timeSpan1,
ThrowIfArgument.IsNull(nameof(timeSpan1), timeSpan1);
ThrowIfArgument.IsNull(nameof(timeSpan2), timeSpan2);

CalculateDifferencies(timeSpan1, timeSpan2, out var barsDelta, out var beatsDelta, out var ticksDelta);
long barsDelta, beatsDelta, ticksDelta;
CalculateDifferencies(timeSpan1, timeSpan2, out barsDelta, out beatsDelta, out ticksDelta);
return barsDelta < 0 || (barsDelta == 0 && (beatsDelta < 0 || (beatsDelta == 0 && ticksDelta < 0)));
}

Expand All @@ -225,7 +227,8 @@ private static void CalculateDifferencies(BarBeatTimeSpan timeSpan1,
ThrowIfArgument.IsNull(nameof(timeSpan1), timeSpan1);
ThrowIfArgument.IsNull(nameof(timeSpan2), timeSpan2);

CalculateDifferencies(timeSpan1, timeSpan2, out var barsDelta, out var beatsDelta, out var ticksDelta);
long barsDelta, beatsDelta, ticksDelta;
CalculateDifferencies(timeSpan1, timeSpan2, out barsDelta, out beatsDelta, out ticksDelta);
return barsDelta > 0 || (barsDelta == 0 && (beatsDelta > 0 || (beatsDelta == 0 && ticksDelta > 0)));
}

Expand All @@ -244,7 +247,8 @@ private static void CalculateDifferencies(BarBeatTimeSpan timeSpan1,
ThrowIfArgument.IsNull(nameof(timeSpan1), timeSpan1);
ThrowIfArgument.IsNull(nameof(timeSpan2), timeSpan2);

CalculateDifferencies(timeSpan1, timeSpan2, out var barsDelta, out var beatsDelta, out var ticksDelta);
long barsDelta, beatsDelta, ticksDelta;
CalculateDifferencies(timeSpan1, timeSpan2, out barsDelta, out beatsDelta, out ticksDelta);
return barsDelta < 0 || (barsDelta == 0 && (beatsDelta < 0 || (beatsDelta == 0 && ticksDelta <= 0)));
}

Expand All @@ -263,7 +267,8 @@ private static void CalculateDifferencies(BarBeatTimeSpan timeSpan1,
ThrowIfArgument.IsNull(nameof(timeSpan1), timeSpan1);
ThrowIfArgument.IsNull(nameof(timeSpan2), timeSpan2);

CalculateDifferencies(timeSpan1, timeSpan2, out var barsDelta, out var beatsDelta, out var ticksDelta);
long barsDelta, beatsDelta, ticksDelta;
CalculateDifferencies(timeSpan1, timeSpan2, out barsDelta, out beatsDelta, out ticksDelta);
return barsDelta < 0 || (barsDelta == 0 && (beatsDelta < 0 || (beatsDelta == 0 && ticksDelta >= 0)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ public static bool TryParse(string input, out MetricTimeSpan timeSpan)
/// <paramref name="input"/>.</returns>
public static MetricTimeSpan Parse(string input)
{
var parsingResult = MetricTimeSpanParser.TryParse(input, out var timeSpan);
MetricTimeSpan timeSpan;
var parsingResult = MetricTimeSpanParser.TryParse(input, out timeSpan);
if (parsingResult.Status == ParsingStatus.Parsed)
return timeSpan;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public static bool TryParse(string input, out MidiTimeSpan timeSpan)
/// <paramref name="input"/>.</returns>
public static MidiTimeSpan Parse(string input)
{
var parsingResult = MidiTimeSpanParser.TryParse(input, out var timeSpan);
MidiTimeSpan timeSpan;
var parsingResult = MidiTimeSpanParser.TryParse(input, out timeSpan);
if (parsingResult.Status == ParsingStatus.Parsed)
return timeSpan;

Expand Down
Loading

9 comments on commit df21e5d

@Butjok
Copy link

@Butjok Butjok commented on df21e5d Dec 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GREAT JOB!

@mjbath
Copy link

@mjbath mjbath commented on df21e5d Dec 8, 2017 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Butjok
Copy link

@Butjok Butjok commented on df21e5d Dec 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Mark!
Yes, working on hobby project, trying to make it to work on unity, nothing really serious but DryWetMidi really helps.

@mjbath
Copy link

@mjbath mjbath commented on df21e5d Dec 8, 2017 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@melanchall
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Mark,

Thank you. Glad to hear you found the library useful!

I'm planning to extend the composition capabilities of the library. For example, introducing chord progressions or scales. Also I have plans to create set of tools for musicians on top of the DryWetMIDI, like notes quantizer or MIDI files merging tool.

Can you say what are you working on? You wrote you are developing tools for songwriters. Sounds very interesting :)

Max

@mjbath
Copy link

@mjbath mjbath commented on df21e5d Dec 10, 2017 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@melanchall
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds really interesting. Let's clarify some things:

  1. Are you working on software that will allow to generate melodies by specified rules (chord progressions and so on), aren't you? Such software is called auto-accompaniment software. I know at least one – Band-In-A-Box, but there are many others. You should ask yourself why your tools are special and why people should choose them instead of those already exist. When I started developing DryWetMIDI I kept in mind what this thing is – it is high-level MIDI data managing. And don't try to implement all ideas at the first release. Split all things into several iterations, create a list of required features for each of them and go ahead.
  2. I have some musical background since I write music too. But I haven't musical education, and things like chord progressions are unclear for me at now. But I sure it is something that can be easily known.
  3. If you will need some help with your tools or with integrating DryWetMIDI into your project, or if you just need a fresh view on your work, you can always ask me.
  4. I suggest to move our discussion to another place, since comments for a commit is not the best place to talk about things we are talking about :)

@mjbath
Copy link

@mjbath mjbath commented on df21e5d Dec 10, 2017 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@melanchall
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mark,

You can write me at [email protected].

Max

Please sign in to comment.