Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Commit

Permalink
Optimize with Threading
Browse files Browse the repository at this point in the history
- Optimize code with threading tasks
- Set relative path to data file
- Remove Data.mdf connection string
- Clean up assembly
  • Loading branch information
hailstorm75 committed May 2, 2017
1 parent ce75d60 commit 75bfbae
Show file tree
Hide file tree
Showing 90 changed files with 4,585 additions and 308 deletions.
Binary file modified .vs/guitarToolsForm/v15/.suo
Binary file not shown.
6 changes: 4 additions & 2 deletions FretboardLibrary/FretNote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Xml.Linq;
using System.Text;
using System;

namespace FretboardLibrary
{
Expand All @@ -26,6 +27,8 @@ public class FretNote
private Viewbox box;
#endregion

private static readonly Object key = new Object();

public FretNote(int index, double size, bool isActive, int root, Point xy, Grid grid)
{
#region Defining variables
Expand Down Expand Up @@ -100,14 +103,13 @@ public void ShiftTuning(int ShiftBy)
private void SetToolTip()
{
IntLimited interval = new IntLimited(Index - Root, 0, 12);
noteBody.ToolTip = (from node in XDocument.Load(@"C:\Users\Denis\Documents\Visual Studio 2017\Projects\Guitar-Tools\guitarTools\Data\Data.xml")
noteBody.ToolTip = (from node in XDocument.Load(System.IO.Directory.GetCurrentDirectory() + @"\Data\Data.xml")
.Descendants("Ratios").Elements("Ratio")
where node.Attribute("id").Value == interval.Value.ToString()
select new StringBuilder(node.Element("Value").Value)
.Append(" ")
.Append(node.Element("Name").Value)
.ToString()).Single();

}
}
}
7 changes: 4 additions & 3 deletions FretboardLibrary/Fretboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
using System.Windows.Shapes;
using ServicesLibrary;
using System.Xml.Linq;
using System.IO;
using System.Threading;
using System;

namespace FretboardLibrary
{
Expand Down Expand Up @@ -40,7 +43,7 @@ public Fretboard(Grid mainGrid, ushort strings, ushort frets, List<List<FretNote
NoteGrid.ShowGridLines = false;
MainGrid.Children.Add(NoteGrid);

Doc = new XDocument(XDocument.Load(@"C:\Users\Denis\Documents\Visual Studio 2017\Projects\Guitar-Tools\guitarTools\Data\Data.xml"));
Doc = new XDocument(XDocument.Load(Directory.GetCurrentDirectory() + @"\Data\Data.xml"));
Strings = strings;
Frets = frets;
Width = mainGrid.Width / frets;
Expand Down Expand Up @@ -92,8 +95,6 @@ where node.Element("Name").Value == Scale

IntLimited a = new IntLimited(key.Value - Root, 0, 12);

//MessageBox.Show(a.Value.ToString());

// Checking if note fits scale
bool IsActive = scale.Contains(a.Value.ToString()) ? true : false;

Expand Down
Binary file modified FretboardLibrary/bin/Debug/FretboardLibrary.dll
Binary file not shown.
Binary file modified FretboardLibrary/bin/Debug/FretboardLibrary.pdb
Binary file not shown.
Binary file added FretboardLibrary/bin/Release/FretboardLibrary.dll
Binary file not shown.
Binary file added FretboardLibrary/bin/Release/FretboardLibrary.pdb
Binary file not shown.
Binary file not shown.
Binary file added FretboardLibrary/bin/Release/ServicesLibrary.pdb
Binary file not shown.
Binary file not shown.
Binary file modified FretboardLibrary/obj/Debug/FretboardLibrary.dll
Binary file not shown.
Binary file modified FretboardLibrary/obj/Debug/FretboardLibrary.pdb
Binary file not shown.
1 change: 1 addition & 0 deletions FretboardLibrary/obj/Release/CoreCompileInputs.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7bacab827e98257ab87983d814ff7fd9c2a05ffc
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
C:\Users\Denis\Documents\Visual Studio 2017\Projects\Guitar-Tools\FretboardLibrary\bin\Release\FretboardLibrary.dll
C:\Users\Denis\Documents\Visual Studio 2017\Projects\Guitar-Tools\FretboardLibrary\bin\Release\FretboardLibrary.pdb
C:\Users\Denis\Documents\Visual Studio 2017\Projects\Guitar-Tools\FretboardLibrary\bin\Release\ServicesLibrary.dll
C:\Users\Denis\Documents\Visual Studio 2017\Projects\Guitar-Tools\FretboardLibrary\bin\Release\ServicesLibrary.pdb
C:\Users\Denis\Documents\Visual Studio 2017\Projects\Guitar-Tools\FretboardLibrary\obj\Release\FretboardLibrary.csprojResolveAssemblyReference.cache
C:\Users\Denis\Documents\Visual Studio 2017\Projects\Guitar-Tools\FretboardLibrary\obj\Release\FretboardLibrary.dll
C:\Users\Denis\Documents\Visual Studio 2017\Projects\Guitar-Tools\FretboardLibrary\obj\Release\FretboardLibrary.pdb
Binary file not shown.
Binary file added FretboardLibrary/obj/Release/FretboardLibrary.dll
Binary file not shown.
Binary file added FretboardLibrary/obj/Release/FretboardLibrary.pdb
Binary file not shown.
Binary file not shown.
Binary file added ServicesLibrary/bin/Release/ServicesLibrary.pdb
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions ServicesLibrary/obj/Release/CoreCompileInputs.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d8550f8af35e5d891836c012e8ccc79c01a52e26
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
C:\Users\Denis\Documents\Visual Studio 2017\Projects\Guitar-Tools\ServicesLibrary\bin\Release\ServicesLibrary.dll
C:\Users\Denis\Documents\Visual Studio 2017\Projects\Guitar-Tools\ServicesLibrary\bin\Release\ServicesLibrary.pdb
C:\Users\Denis\Documents\Visual Studio 2017\Projects\Guitar-Tools\ServicesLibrary\obj\Release\ServicesLibrary.dll
C:\Users\Denis\Documents\Visual Studio 2017\Projects\Guitar-Tools\ServicesLibrary\obj\Release\ServicesLibrary.pdb
Binary file not shown.
Binary file added ServicesLibrary/obj/Release/ServicesLibrary.pdb
Binary file not shown.
6 changes: 1 addition & 5 deletions guitarTools/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="GuitarScales.Properties.Settings.DataConnectionString"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Data.mdf;Integrated Security=True;Connect Timeout=30"
providerName="System.Data.SqlClient" />
</connectionStrings>
<connectionStrings />
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
Expand Down
5 changes: 5 additions & 0 deletions guitarTools/GuitarScales.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>
</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<PropertyGroup>
<SignAssembly>false</SignAssembly>
</PropertyGroup>
<ItemGroup>
<Reference Include="FontAwesome.WPF, Version=4.7.0.37774, Culture=neutral, PublicKeyToken=0758b07a11a4f466, processorArchitecture=MSIL">
<HintPath>..\packages\FontAwesome.WPF.4.7.0.9\lib\net40\FontAwesome.WPF.dll</HintPath>
Expand Down
135 changes: 71 additions & 64 deletions guitarTools/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Windows;
using System.Collections.Generic;
using FretboardLibrary;
using FretboardLibrary;
using ServicesLibrary;
using System.Windows.Media.Animation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;
using System.Windows.Threading;
using System.Xml.Linq;
using System.Linq;

namespace GuitarScales
{
Expand Down Expand Up @@ -40,7 +42,7 @@ public MainWindow()
ushort frets = 12 * 1;
ushort strings = 6;
NoteList = new List<List<FretNote>>(); // Row is a string, column is a fret
Doc = new XDocument(XDocument.Load(@"C:\Users\Denis\Documents\Visual Studio 2017\Projects\Guitar-Tools\guitarTools\Data\Data.xml"));
Doc = new XDocument(XDocument.Load(System.IO.Directory.GetCurrentDirectory() + @"\Data\Data.xml"));

HiddenMenu = true;
SettingsPanel = null;
Expand All @@ -50,7 +52,6 @@ public MainWindow()
fretboard = new Fretboard(mainGrid, strings, frets, NoteList, 4, "Standard E", "Ionian");

SetupControls(4, 0, strings);

SetupSearchScale();
}

Expand All @@ -60,9 +61,8 @@ private void SetupControls(int root, int scale, int strings)
// The root notes are constant - no need to fetch from database
cbRoot.SelectedIndex = root; // Setting default root note to "E"

FillTunings(strings);

FillScales(scale);
Dispatcher.Invoke(() => { FillTunings(strings); });
Dispatcher.Invoke(() => { FillScales(scale); });
}

private void FillTunings(int strings)
Expand Down Expand Up @@ -95,22 +95,29 @@ private void FillScales(int scale)

private void SetupSearchScale()
{
foreach (var item in MusicKeys)
{
tbOne.Items.Add(item);
tbTwo.Items.Add(item);
tbThree.Items.Add(item);
}

var chords = from node in Doc.Descendants("Chords").Elements("Chord")
select node.Element("Name").Value;

foreach (var item in chords)
Dispatcher.Invoke(() =>
{
cbOne.Items.Add(item);
cbTwo.Items.Add(item);
cbThree.Items.Add(item);
}
foreach (var item in MusicKeys)
{
tbOne.Items.Add(item);
tbTwo.Items.Add(item);
tbThree.Items.Add(item);
}
}, DispatcherPriority.ContextIdle);

Dispatcher.Invoke(() =>
{
foreach (var item in chords)
{
cbOne.Items.Add(item);
cbTwo.Items.Add(item);
cbThree.Items.Add(item);
}
}, DispatcherPriority.ContextIdle);

Menu = new ComboBox[,] { { tbOne, tbTwo, tbThree }, { cbOne, cbTwo, cbThree } };
init = true;
}
Expand Down Expand Up @@ -147,15 +154,9 @@ public void cbScale_SelectionChanged(object sender, System.Windows.Controls.Sele

private void Menu_Click(object sender, RoutedEventArgs e)
{
Storyboard sb;
if (HiddenMenu)
{
sb = Resources["sbShowLeftMenu"] as Storyboard;
}
else
{
sb = Resources["sbHideLeftMenu"] as Storyboard;
}
Storyboard sb = HiddenMenu ? Resources["sbShowLeftMenu"] as Storyboard :
Resources["sbHideLeftMenu"] as Storyboard;

sb.Begin(pnlLeftMenu);
HiddenMenu = !HiddenMenu;
}
Expand Down Expand Up @@ -186,30 +187,38 @@ private void btnSearch_Click(object sender, RoutedEventArgs e)
lbResults.Items.Clear();
List<int> chordNotes = new List<int>();
int pointA = Array.IndexOf(MusicKeys, tbOne.SelectedItem);
Semaphore sem = new Semaphore(1, Environment.ProcessorCount);

for (int row = 0; row < Menu.GetLength(1) - Active; row++)
{
string[] chord = (from node in Doc.Descendants("Chords").Elements("Chord")
where node.Element("Name").Value == (string)Menu[1, row].SelectedValue
select node.Element("Interval").Value).Single().Split(' ');

int pointB = Array.IndexOf(MusicKeys, Menu[1, row]);
if (pointA - pointB != 0)
{
IntLimited shiftBy = new IntLimited(pointA + pointB, 0, 12);
}
foreach (var item in chord)
if (!chordNotes.Contains(int.Parse(item)))
chordNotes.Add(int.Parse(item));
Dispatcher.Invoke(() => {
sem.WaitOne();
string[] chord = (from node in Doc.Descendants("Chords").Elements("Chord")
where node.Element("Name").Value == (string)Menu[1, row].SelectedValue
select node.Element("Interval").Value).Single().Split(' ');

int pointB = Array.IndexOf(MusicKeys, Menu[1, row]);
if (pointA - pointB != 0)
{
IntLimited shiftBy = new IntLimited(pointA + pointB, 0, 12);
}
foreach (var item in chord)
if (!chordNotes.Contains(int.Parse(item)))
chordNotes.Add(int.Parse(item));
sem.Release();
}, DispatcherPriority.ContextIdle);
}

chordNotes.Sort();
try
{
var scales = from node in Doc.Descendants("Scales").Elements("Scale")
select node.Element("Interval").Value;

List<string> found = new List<string>();
foreach (var item in scales)
{
var scales = from node in Doc.Descendants("Scales").Elements("Scale")
select node.Element("Interval").Value;

List<string> found = new List<string>();
foreach (var item in scales)
{
(new Thread(() => {
sem.WaitOne();
for (int note = 0; note < chordNotes.Count; note++)
{
if (item.IndexOf(note.ToString()) != -1)
Expand All @@ -221,20 +230,18 @@ where node.Element("Name").Value == (string)Menu[1, row].SelectedValue
}
else break;
}
}
if (found.Count > 0)
foreach (var item in found)
lbResults.Items.Add(
(from node in Doc.Descendants("Scales").Elements("Scale")
where node.Element("Interval").Value == item
select node.Element("Name").Value).Single()
);
else lbResults.Items.Add("Unknown scale");
}
catch
{
MessageBox.Show("OOOPS");
sem.Release();
})).Start();
}

if (found.Count > 0)
foreach (var item in found)
lbResults.Items.Add(
(from node in Doc.Descendants("Scales").Elements("Scale")
where node.Element("Interval").Value == item
select node.Element("Name").Value).Single()
);
else lbResults.Items.Add("Unknown scale");
}

private void SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand Down
8 changes: 5 additions & 3 deletions guitarTools/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("guitarTools")]
[assembly: AssemblyTitle("Guitar Tools")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("guitarTools")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyProduct("Guitar Tools")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down Expand Up @@ -53,3 +53,5 @@
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: NeutralResourcesLanguage("en")]

11 changes: 0 additions & 11 deletions guitarTools/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 2 additions & 11 deletions guitarTools/Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="GuitarScales.Properties" GeneratedClassName="Settings">
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles />
<Settings>
<Setting Name="DataConnectionString" Type="(Connection string)" Scope="Application">
<DesignTimeValue Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;ConnectionString&gt;Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Data.mdf;Integrated Security=True;Connect Timeout=30&lt;/ConnectionString&gt;
&lt;ProviderName&gt;System.Data.SqlClient&lt;/ProviderName&gt;
&lt;/SerializableConnectionString&gt;</DesignTimeValue>
<Value Profile="(Default)">Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Data.mdf;Integrated Security=True;Connect Timeout=30</Value>
</Setting>
</Settings>
<Settings />
</SettingsFile>
Binary file removed guitarTools/bin/Debug/Data.mdf
Binary file not shown.
Loading

0 comments on commit 75bfbae

Please sign in to comment.