Skip to content

Commit

Permalink
Eliminates separation between Track and Recording records. Adds Thumb…
Browse files Browse the repository at this point in the history
…nails

Reset of DB is required.

Closes #10
  • Loading branch information
tstavropoulos committed May 9, 2019
1 parent c33aacf commit 173ee87
Show file tree
Hide file tree
Showing 50 changed files with 1,065 additions and 1,218 deletions.
2 changes: 1 addition & 1 deletion MusicPlayer/AlbumArtPicker/AlbumArtPickerMockTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public AlbumArtPickerMockTree()

parent = new AlbumArtAlbumDTO {
Name = "Test 4 - Collapsed With Image",
Album = new Database.Album() { Image = LoadImage(@"MockDBResources\0.jpg") }
Album = new Database.Album() { Image = LoadImage(@"MockDBResources\0.jpg"), Thumbnail = LoadImage(@"MockDBResources\0.jpg") }
};
parent.Children.Add(new AlbumArtArtDTO() { IsChecked = false, Image = LoadImage(@"MockDBResources\0.jpg"), Name = @"MockDBResources\0.jpg" });
parent.Children.Add(new AlbumArtArtDTO() { IsChecked = false, Image = LoadImage(@"MockDBResources\1.jpg"), Name = @"MockDBResources\1.jpg" });
Expand Down
6 changes: 3 additions & 3 deletions MusicPlayer/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
</entityFramework>

<connectionStrings>
<add name="MusegicianDataEntities" connectionString="metadata=res://*/MusegicianData.csdl|res://*/MusegicianData.ssdl|res://*/MusegicianData.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\MusegicianData.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework&quot;"
<add name="MusegicianDataEntities" connectionString="metadata=res://*/MusegicianData.csdl|res://*/MusegicianData.ssdl|res://*/MusegicianData.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\MusegicianData.mdf;integrated security=False;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework&quot;"
providerName="System.Data.EntityClient" />
<add name="MusegicianData" connectionString="data source=(LocalDb)\MSSQLLocalDB;initial catalog=Musegician.MusegicianData;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"
<add name="MusegicianData" connectionString="data source=(LocalDb)\MSSQLLocalDB;initial catalog=Musegician.MusegicianData;integrated security=False;MultipleActiveResultSets=True;App=EntityFramework"
providerName="System.Data.SqlClient" />
<add name="Musegician.Properties.Settings.Musegician_MusegicianDataConnectionString"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=&quot;~\Documents\Musegician.MusegicianData.mdf&quot;;Integrated Security=True;Connect Timeout=30"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=&quot;~\Documents\Musegician.MusegicianData.mdf&quot;;Integrated Security=False;Connect Timeout=30"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
4 changes: 0 additions & 4 deletions MusicPlayer/AudioUtilities/NVorbisSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ public void Dispose()
{
_vorbisReader.Dispose();
}
else
{
throw new ObjectDisposedException("NVorbisSource");
}

_disposed = true;
}
Expand Down
21 changes: 7 additions & 14 deletions MusicPlayer/AudioUtilities/PhaseVocoderStream.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CSCore;
using CSCore.DSP;
using CSCore.Streams.Effects;
using CSCore.Utils;
using Musegician.Spatializer;
using System.IO;

namespace Musegician.AudioUtilities
{
Expand All @@ -19,12 +12,12 @@ public class PhaseVocoderStream : SampleAggregatorBase
/// <summary>
/// Holds samples from underlying stream
/// </summary>
private float[] localSampleBuffer;
private readonly float[] localSampleBuffer;

/// <summary>
/// Store computed samples ready to deliver
/// </summary>
private float[] cachedSampleBuffer;
private readonly float[] cachedSampleBuffer;

private readonly int _halfFFTSamples;
private readonly int _baseFFTSamples;
Expand All @@ -35,11 +28,11 @@ public class PhaseVocoderStream : SampleAggregatorBase
private readonly int _stepSize;
private readonly int _overlap;

private Complex[] phasors;
private float[][] inputBuffers;
private Complex[] fftBuffer;
private Complex[] ifftBuffer;
private float[] outputAccumulation;
private readonly Complex[] phasors;
private readonly float[][] inputBuffers;
private readonly Complex[] fftBuffer;
private readonly Complex[] ifftBuffer;
private readonly float[] outputAccumulation;

private float _speed = 1f;

Expand Down
22 changes: 11 additions & 11 deletions MusicPlayer/AudioUtilities/SpectralPowerStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@ public class SpectralPowerStream : SampleAggregatorBase
{
#region Data

private float[] freqs;
private int[] freqIndices;
private readonly float[] freqs;
private readonly int[] freqIndices;

private int[] freqBandLB;
private int[] freqBandUB;
private readonly int[] freqBandLB;
private readonly int[] freqBandUB;

private RingBuffer<Complex> bufferL;
private RingBuffer<Complex> bufferR;
private Complex[] fftBufferL;
private Complex[] fftBufferR;
private readonly RingBuffer<Complex> bufferL;
private readonly RingBuffer<Complex> bufferR;
private readonly Complex[] fftBufferL;
private readonly Complex[] fftBufferR;

private double powerCoeff;
private readonly double powerCoeff;

private static readonly float[] defaultFrequencies = new float[]
{
32, 64, 125, 250, 500, 1000, 2000, 4000, 8000, 16000
};

private int samplesToProcess;
private readonly int samplesToProcess;
//2^12 = 4096
private const int FFT_EXP_MIN = 12;
private const int MIN_PERIOD = 4;
private const int SAMPLE_STRIDE = 2;
private int _fftSize = 12;
private readonly int _fftSize = 12;

private int _blocksToProcess = 0;
private int _blocksProcessed = 0;
Expand Down
123 changes: 80 additions & 43 deletions MusicPlayer/Core/Containers/DepletableBag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,29 @@ namespace TASAgency.Collections.Generic
/// An unstable-sort set structure that acts as a select-without-replace bag.
/// </summary>
[Serializable]
public class DepletableBag<T> : IDepletable<T>
public sealed class DepletableBag<T> : IDepletable<T>
{
protected List<T> values;
protected int availableCount;

Random _randomizer = null;
private readonly List<T> values;
private readonly Random _randomizer = null;

Random Randomizer => _randomizer ?? ThreadSafeRandom.Rand;

public DepletableBag(Random randomizer = null)
{
values = new List<T>();
availableCount = 0;

if (randomizer == null)
{
randomizer = new Random();
}
Count = 0;

_randomizer = randomizer;
}

public DepletableBag(IEnumerable<T> values, bool autoRefill = false, Random randomizer = null)
public DepletableBag(
IEnumerable<T> values,
bool autoRefill = false,
Random randomizer = null)
{
this.values = new List<T>(values);
AutoRefill = autoRefill;
availableCount = this.values.Count;
Count = this.values.Count;

_randomizer = randomizer;
}
Expand All @@ -47,11 +43,11 @@ public DepletableBag(IEnumerable<T> values, bool autoRefill = false, Random rand

public T PopNext()
{
if (availableCount == 0)
if (Count == 0)
{
if (AutoRefill)
{
availableCount = values.Count;
Count = values.Count;
}
else
{
Expand All @@ -60,28 +56,28 @@ public T PopNext()
}
}

int index = _randomizer.Next(0, availableCount);
int index = Randomizer.Next(0, Count);
T temp = values[index];

//Swap the position of the highest available value with the randomly chosen index.
values[index] = values[availableCount - 1];
values[availableCount - 1] = temp;
values[index] = values[Count - 1];
values[Count - 1] = temp;

//Decrement availableCount. Now that we have swapped those values,
//Decrement Count. Now that we have swapped those values,
//all unusedValues will be below unusedCount.
availableCount--;
Count--;

//return our chosen value.
return temp;
}

public bool TryPopNext(out T value)
{
if (availableCount == 0)
if (Count == 0)
{
if (AutoRefill)
{
availableCount = values.Count;
Count = values.Count;
}
else
{
Expand All @@ -90,16 +86,16 @@ public bool TryPopNext(out T value)
}
}

int index = _randomizer.Next(0, availableCount);
int index = Randomizer.Next(0, Count);
value = values[index];

//Swap the position of the highest available value with the randomly chosen index.
values[index] = values[availableCount - 1];
values[availableCount - 1] = value;
values[index] = values[Count - 1];
values[Count - 1] = value;

//Decrement availableCount. Now that we have swapped those values,
//Decrement Count. Now that we have swapped those values,
//all unusedValues will be below unusedCount.
availableCount--;
Count--;

//return our chosen value.
return true;
Expand All @@ -110,15 +106,15 @@ public bool TryPopNext(out T value)
/// </summary>
public void Reset()
{
availableCount = values.Count;
Count = values.Count;
}

public bool DepleteValue(T value)
{
const int NOT_FOUND = -1;
int index = NOT_FOUND;

for (int i = 0; i < availableCount; i++)
for (int i = 0; i < Count; i++)
{
if (values[i].Equals(value))
{
Expand All @@ -134,10 +130,10 @@ public bool DepleteValue(T value)

T temp = values[index];

values[index] = values[availableCount - 1];
values[availableCount - 1] = temp;
values[index] = values[Count - 1];
values[Count - 1] = temp;

availableCount--;
Count--;

return true;
}
Expand All @@ -154,8 +150,49 @@ public bool DepleteAllValue(T value)
return success;
}

public bool ReplenishValue(T value)
{
const int NOT_FOUND = -1;
int index = NOT_FOUND;

for (int i = Count; i < TotalCount; i++)
{
if (values[i].Equals(value))
{
index = i;
break;
}
}

if (index == NOT_FOUND)
{
return false;
}

T temp = values[index];

values[index] = values[Count];
values[Count] = temp;

Count++;

return true;
}

public bool ReplenishAllValue(T value)
{
bool success = false;

while (ReplenishValue(value))
{
success = true;
}

return success;
}

public bool ContainsAnywhere(T value) => values.Contains(value);
public IList<T> GetAvailable() => values.GetRange(0, availableCount);
public IList<T> GetAvailable() => values.GetRange(0, Count);

public void CopyAllTo(T[] array, int arrayIndex)
{
Expand All @@ -177,33 +214,33 @@ public void AddRange(IEnumerable<T> values)
#endregion IDepletable<T>
#region ICollection<T>

public int Count => availableCount;
public int Count { get; private set; } = 0;

bool ICollection<T>.IsReadOnly => false;

public void Add(T value)
{
if (availableCount < values.Count)
if (Count < values.Count)
{
values.Add(values[availableCount]);
values[availableCount] = value;
values.Add(values[Count]);
values[Count] = value;
}
else
{
values.Add(value);
}
availableCount++;
Count++;
}

public void Clear()
{
values.Clear();
availableCount = 0;
Count = 0;
}

public bool Contains(T value)
{
for (int i = 0; i < availableCount; i++)
for (int i = 0; i < Count; i++)
{
if (values[i].Equals(value))
{
Expand All @@ -220,7 +257,7 @@ public void CopyTo(T[] dest, int destIndex)
index: 0,
array: dest,
arrayIndex: destIndex,
count: System.Math.Min(availableCount, dest.Length - destIndex));
count: System.Math.Min(Count, dest.Length - destIndex));
}

public bool Remove(T item)
Expand All @@ -231,9 +268,9 @@ public bool Remove(T item)
{
values.RemoveAt(index);

if (index < availableCount)
if (index < Count)
{
availableCount--;
Count--;
}

}
Expand Down
Loading

0 comments on commit 173ee87

Please sign in to comment.