Skip to content

Commit

Permalink
[Release] Comment public API
Browse files Browse the repository at this point in the history
  • Loading branch information
melanchall committed Jun 18, 2023
1 parent 6a42170 commit fd6ae29
Show file tree
Hide file tree
Showing 23 changed files with 603 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,28 +342,6 @@ public void GetChords_TrackChunks_OneNote_1([Values] bool wrapToFile) => GetChor

[Test]
public void GetChords_TrackChunks_OneNote_2([Values] bool wrapToFile) => GetChords_TrackChunks(
wrapToFile,
midiEvents: new[]
{
new MidiEvent[]
{
new TextEvent("A"),
new NoteOnEvent(),
new TextEvent("B"),
new NoteOffEvent { DeltaTime = 100 }
},
new MidiEvent[]
{
new ControlChangeEvent(),
},
},
expectedChords: new[]
{
new Chord(new Note(SevenBitNumber.MinValue, 100) { Velocity = SevenBitNumber.MinValue }),
});

[Test]
public void GetChords_TrackChunks_OneNote_3([Values] bool wrapToFile) => GetChords_TrackChunks(
wrapToFile,
midiEvents: new[]
{
Expand All @@ -385,7 +363,7 @@ public void GetChords_TrackChunks_OneNote_3([Values] bool wrapToFile) => GetChor
});

[Test]
public void GetChords_TrackChunks_OneNote_4([Values] bool wrapToFile) => GetChords_TrackChunks(
public void GetChords_TrackChunks_OneNote_3([Values] bool wrapToFile) => GetChords_TrackChunks(
wrapToFile,
midiEvents: new[]
{
Expand All @@ -407,7 +385,7 @@ public void GetChords_TrackChunks_OneNote_4([Values] bool wrapToFile) => GetChor
});

[Test]
public void GetChords_TrackChunks_OneNote_5([Values] bool wrapToFile) => GetChords_TrackChunks(
public void GetChords_TrackChunks_OneNote_4([Values] bool wrapToFile) => GetChords_TrackChunks(
wrapToFile,
midiEvents: new[]
{
Expand All @@ -427,7 +405,7 @@ public void GetChords_TrackChunks_OneNote_5([Values] bool wrapToFile) => GetChor
});

[Test]
public void GetChords_TrackChunks_OneNote_6([Values] bool wrapToFile) => GetChords_TrackChunks(
public void GetChords_TrackChunks_OneNote_5([Values] bool wrapToFile) => GetChords_TrackChunks(
wrapToFile,
midiEvents: new[]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,7 @@ public void ChangeDenominator()

#region FromDouble

[TestCase(0.00000001, "0/1")]
[TestCase(1.0, "1/1")]
[TestCase(1.0 / 2, "1/2")]
[TestCase(1.0 / 4, "1/4")]
Expand Down
10 changes: 6 additions & 4 deletions DryWetMidi.Tests/Multimedia/Playback/PlaybackTests.Speed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ public sealed partial class PlaybackTests
{
#region Test methods

// TODO
[Retry(RetriesNumber)]
[Test]
//[Test]
public void CheckPlaybackCurrentTimeAfterSpeedChange(
[Values(0.5, 1, 10)] double speed,
[Values(1, 10, 100)] int waitAfterSpeedChangeMs) =>
CheckPlaybackCurrentTimeAfterSpeedChanges(speed, waitAfterSpeedChangeMs, false);

// TODO
[Retry(RetriesNumber)]
[Test]
//[Test]
public void CheckPlaybackCurrentTimeAfterMultipleSpeedChanges(
[Values(0.5, 1, 10)] double speed,
[Values(1, 10, 100)] int waitAfterSpeedChangeMs) =>
Expand Down Expand Up @@ -101,7 +103,7 @@ public void CheckPlaybackCurrentTimeAfterSpeedChanges(double speed, int waitAfte
playback.Stop();
stopwatch.Stop();

var delta = (long)(currentTimeAfterSpeedChange - currentTimeAfterSpeedChange).TotalMilliseconds;
var delta = (long)Math.Round((currentTimeAfterSpeedChange - currentTimeBeforeSpeedChange).TotalMilliseconds);
var reference = waitTimes[0] * speeds[0];
if (variateSpeed)
{
Expand All @@ -111,7 +113,7 @@ public void CheckPlaybackCurrentTimeAfterSpeedChanges(double speed, int waitAfte

Assert.LessOrEqual(
delta,
MathUtilities.AddRelativeMargin(reference, 0.1),
MathUtilities.AddRelativeMargin(reference, 0.2),
"Invalid current time delta after speed change.");
}
}
Expand Down
2 changes: 1 addition & 1 deletion DryWetMidi/Common/MathUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static IEnumerable<RationalNumber> GetRationalizations(double number, dou

public static double AddRelativeMargin(double value, double margin)
{
return value * margin;
return value + value * margin;
}

public static T GetLastElementBelowThreshold<T>(T[] elements, long keyThreshold, Func<T, long> keySelector)
Expand Down
5 changes: 3 additions & 2 deletions DryWetMidi/Composing/PatternActionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
/// </summary>
/// <remarks>
/// Pattern actions correspond to methods on <see cref="PatternBuilder"/>. For example,
/// <see cref="PatternBuilder.Note(MusicTheory.Interval)"/> creates 'Add note' action,
/// so the state will define whether a note will be enabled, disabled or excluded from pattern at all.
/// <see cref="PatternBuilder.Note(MusicTheory.Interval, Interaction.ITimeSpan, Common.SevenBitNumber?)"/>
/// creates 'Add note' action, so the state will define whether a note will be enabled, disabled or excluded
/// from pattern at all.
/// </remarks>
public enum PatternActionState
{
Expand Down
11 changes: 7 additions & 4 deletions DryWetMidi/Composing/PatternBuilder.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ public PatternBuilder(Pattern pattern)
/// <para>
/// There are methods to add notes and chords that don't take velocity as an argument. In these
/// cases the value of the <see cref="Velocity"/> property will be used. For example,
/// <see cref="Note(MusicTheory.Note)"/> or <see cref="Chord(IEnumerable{Interval}, MusicTheory.Note)"/>.
/// <see cref="Note(MusicTheory.Note, ITimeSpan, SevenBitNumber?)"/> or
/// <see cref="Chord(IEnumerable{Interval}, MusicTheory.Note, ITimeSpan, SevenBitNumber?)"/>.
/// </para>
/// </remarks>
public SevenBitNumber Velocity { get; private set; } = DefaultVelocity;
Expand All @@ -191,7 +192,8 @@ public PatternBuilder(Pattern pattern)
/// <para>
/// There are methods to add notes and chords that don't take length as an argument. In these
/// cases the value of the <see cref="NoteLength"/> property will be used. For example,
/// <see cref="Note(MusicTheory.Note)"/> or <see cref="Chord(IEnumerable{Interval}, MusicTheory.Note)"/>.
/// <see cref="Note(MusicTheory.Note, ITimeSpan, SevenBitNumber?)"/> or
/// <see cref="Chord(IEnumerable{Interval}, MusicTheory.Note, ITimeSpan, SevenBitNumber?)"/>.
/// </para>
/// </remarks>
public ITimeSpan NoteLength { get; private set; } = DefaultNoteLength;
Expand All @@ -217,7 +219,8 @@ public PatternBuilder(Pattern pattern)
/// <para>
/// There are methods to add notes and chords where octave is not specified explicitly. In these
/// cases the value of the <see cref="Octave"/> property will be used. For example,
/// <see cref="Note(NoteName)"/> or <see cref="Chord(IEnumerable{Interval}, NoteName)"/>.
/// <see cref="Note(NoteName, ITimeSpan, SevenBitNumber?)"/> or
/// <see cref="Chord(IEnumerable{Interval}, NoteName, ITimeSpan, SevenBitNumber?)"/>.
/// </para>
/// </remarks>
public Octave Octave { get; private set; } = DefaultOctave;
Expand All @@ -230,7 +233,7 @@ public PatternBuilder(Pattern pattern)
/// <para>
/// There are methods to add notes by interval where root note is not specified explicitly.
/// In these cases the value of the <see cref="RootNote"/> property will be used. For example,
/// <see cref="Note(Interval)"/>.
/// <see cref="Note(Interval, ITimeSpan, SevenBitNumber?)"/>.
/// </para>
/// </remarks>
public MusicTheory.Note RootNote { get; private set; } = DefaultRootNote;
Expand Down
3 changes: 3 additions & 0 deletions DryWetMidi/Core/Events/Channel/PitchBendEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public sealed class PitchBendEvent : ChannelEvent
/// </summary>
public const ushort MaxPitchValue = (1 << 14) - 1;

/// <summary>
/// Represents the default pitch value which means no pitch bend applied.
/// </summary>
public const ushort DefaultPitchValue = 1 << 13;

#endregion
Expand Down
8 changes: 7 additions & 1 deletion DryWetMidi/Core/Lazy/MidiToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ protected MidiToken(MidiTokenType tokenType)
#region Properties

/// <summary>
/// Gets the type of the current MIDI token.
/// Gets the type of a MIDI token.
/// </summary>
public MidiTokenType TokenType { get; }

/// <summary>
/// Gets the position of a MIDI token within an input data stream.
/// </summary>
public long Position { get; internal set; }

/// <summary>
/// Gets the length of a MIDI token in bytes within an input data stream.
/// </summary>
public long Length { get; internal set; }

#endregion
Expand Down
6 changes: 6 additions & 0 deletions DryWetMidi/Core/ReadingSettings/ReadingSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public class ReadingSettings

#region Properties

/// <summary>
/// Gets or sets a value indicating whether the reading engine should stop or not when
/// the count of read chunks is equal to the value defined in a file's header. The
/// default value is <c>false</c> which means all chunks will be read.
/// </summary>
/// <seealso cref="UnexpectedTrackChunksCountPolicy"/>
public bool StopReadingOnExpectedTrackChunksCountReached { get; set; }

/// <summary>
Expand Down
38 changes: 38 additions & 0 deletions DryWetMidi/Interaction/Chords/ChordProcessingHint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,53 @@

namespace Melanchall.DryWetMidi.Interaction
{
/// <summary>
/// Defines a hint which tells the chord processing algorithm how it can optimize its performance.
/// </summary>
/// <remarks>
/// If you want to get the maximum performance of a chord processing (for example,
/// <see cref="ChordsManagingUtilities.ProcessChords(Core.MidiFile, Action{Chord}, Predicate{Chord}, ChordDetectionSettings, ChordProcessingHint)"/>),
/// choose a hint carefully. Note that you can always use <see href="xref:a_managers">an object manager</see> to
/// perform any manipulations with chords but dedicated methods of the <see cref="ChordsManagingUtilities"/> will
/// always be faster and will consume less memory.
/// </remarks>
[Flags]
public enum ChordProcessingHint
{
/// <summary>
/// <see cref="Chord.Time"/> or <see cref="Chord.Length"/> of a chord can be changed.
/// </summary>
TimeOrLengthCanBeChanged = 1,

/// <summary>
/// <see cref="Chord.Notes"/> can be changed, i.e. a note can be added to or removed from
/// a chord.
/// </summary>
NotesCollectionCanBeChanged = 2,

/// <summary>
/// <see cref="Note.Time"/> or <see cref="Note.Length"/> can be changed on a note within
/// a chord's notes (<see cref="Chord.Notes"/>).
/// </summary>
NoteTimeOrLengthCanBeChanged = 4,

/// <summary>
/// The processing algorithm will consider that only properties that don't affect underlying MIDI
/// events positions will be changed. This hint means maximum performance, i.e. the processing will
/// take less time and consume less memory.
/// </summary>
None = 0,

/// <summary>
/// Default hint. Equals to <see cref="TimeOrLengthCanBeChanged"/>.
/// </summary>
Default = TimeOrLengthCanBeChanged,

/// <summary>
/// The processing algorithm will consider that everything related to a chord can be changed.
/// this hint means minimum performance, i.e. the processing will take more time and consume more memory.
/// For maximum performance see <see cref="None"/> option.
/// </summary>
AllPropertiesCanBeChanged =
TimeOrLengthCanBeChanged |
NotesCollectionCanBeChanged |
Expand Down
Loading

0 comments on commit fd6ae29

Please sign in to comment.