-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
25,074 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using MusicCore; | ||
|
||
namespace MusicComposer | ||
{ | ||
public static class Compositions | ||
{ | ||
public static Melody12Tone OggyMelody() | ||
{ | ||
RhythmPattern rhythm = new RhythmPattern(3, 2, "hh11"); | ||
MelodyBase melody = new MelodyAtomic(rhythm, new object[] { 0, 1, 2, 0 }); | ||
MelodyBase melodyEnd = new MelodyAtomic(new RhythmPattern(3, 2, "3"), new object[] { 0 }); | ||
|
||
MelodyComposite melody2 = new MelodyComposite("AA-A--B", melody, melodyEnd); | ||
|
||
Melody12Tone m12tone = new Melody12Tone(melody2, MusicalModes.Minor, 64); | ||
return m12tone; | ||
} | ||
|
||
public static Melody12Tone MrSandman() | ||
{ | ||
RhythmPattern r = new RhythmPattern(4, 2, "hhhh2"); | ||
MelodyBase melody = new MelodyAtomic(r, new object[] { 0, 2, 4, 6, 5 }); | ||
MelodyComposite melodyComp = new MelodyComposite("AA+", melody); | ||
Melody12Tone m12tone = new Melody12Tone(melodyComp, MusicalModes.Major, 64); | ||
return m12tone; | ||
} | ||
|
||
public static Melody12Tone Albinoni() | ||
{ | ||
RhythmPattern rhythm = new RhythmPattern(3, 4, "1h.qh.q 1 2"); | ||
MelodyBase melody = new MelodyAtomic(rhythm, new object[] { 4, 3, 2, 1, 0, 0, -1 }); | ||
MelodyComposite melodyComp = new MelodyComposite("AA+", melody); | ||
Melody12Tone m12tone = new Melody12Tone(melodyComp, MusicalModes.MinorHarmonic, 64); | ||
return m12tone; | ||
} | ||
|
||
public static Melody12Tone Rach2ndSymphAdagio() | ||
{ | ||
MelodyAtomic melodyCEGB = new MelodyAtomic(new object[] { null, 0, 2, 4, 6, 7, 5, null }, 4); | ||
MelodyAtomic melodyEnd = new MelodyAtomic(new object[] { 1, null, null, 2, 1, null, 0, null }, 4); | ||
melodyEnd.anacrusis = new List<NoteWithDuration>() | ||
{ | ||
new NoteWithDuration() { note = 4, duration = new Fraction(1, 2) } | ||
}; | ||
MelodyComposite melodyComp = new MelodyComposite("A--B", melodyCEGB, melodyEnd); | ||
return new Melody12Tone(melodyComp, MusicalModes.Major, 64); | ||
} | ||
|
||
public static Melody12Tone GabrielaImprov() | ||
{ | ||
MelodyAtomic melody = new MelodyAtomic(new object[] { 2, null, 2, null, 2, null, 1, 0, 1, null, null, null}, 3); | ||
melody.anacrusis = new List<NoteWithDuration>() | ||
{ | ||
new NoteWithDuration() { note = 0, duration = new Fraction(1, 4) }, | ||
new NoteWithDuration() { note = 1, duration = new Fraction(1, 4) } | ||
}; | ||
MelodyComposite melodyComp = new MelodyComposite("AA+A++", melody); | ||
return new Melody12Tone(melodyComp, MusicalModes.Minor, 64); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{3BE5F334-0961-431A-8B73-8EFDBDE03D51}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>MusicComposer</RootNamespace> | ||
<AssemblyName>MusicComposer</AssemblyName> | ||
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<TargetFrameworkProfile /> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="NAudio"> | ||
<HintPath>..\NAudio\NAudio.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Compositions.cs" /> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="RhythmMaker.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\MusicCore\MusicCore.csproj"> | ||
<Project>{c9220672-1467-4b4e-829c-459b9c5226a1}</Project> | ||
<Name>MusicCore</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using System; | ||
using MusicCore; | ||
using NAudio.Midi; | ||
using System.Threading; | ||
|
||
namespace MusicComposer | ||
{ | ||
class Program | ||
{ | ||
static MidiOut midiOut = new MidiOut(0); | ||
|
||
static void Play(TwelveToneSet chord, int startFrom) | ||
{ | ||
for (int i=startFrom; i< TwelveToneSet.TWELVE + startFrom; i++) | ||
{ | ||
if (chord[(i+10*TwelveToneSet.TWELVE) % TwelveToneSet.TWELVE]) | ||
{ | ||
midiOut.Send(MidiMessage.StartNote(48 + i, 100, 1).RawData); | ||
Thread.Sleep(100); | ||
} | ||
} | ||
} | ||
|
||
static void Main2(string[] args) | ||
{ | ||
Random rand = new Random(); | ||
TwelveToneSet chord = TwelveToneSet.major7; | ||
TwelveToneSet scale = new TwelveToneSet(TwelveToneSet.majorScale); | ||
int dist = 0; | ||
Console.WriteLine($"Chord: {chord.ToString()}"); | ||
int startFrom = chord.First; | ||
do | ||
{ | ||
Play(chord, startFrom); | ||
Thread.Sleep(2000); | ||
TwelveToneSet chordNew = new TwelveToneSet(rand, 4, scale.ShiftRight(rand.Next(TwelveToneSet.TWELVE))); | ||
dist = Distance(chord, chordNew); | ||
for (int i=0; i<10; i++) | ||
{ | ||
TwelveToneSet chord2 = new TwelveToneSet(rand, 4, scale.ShiftRight(rand.Next(TwelveToneSet.TWELVE))); | ||
if (chord.Equals(chord2)) | ||
continue; | ||
|
||
int dist2 = Distance(chord, chord2); | ||
if (dist2 < dist) | ||
{ | ||
dist = dist2; | ||
chordNew = chord2; | ||
} | ||
} | ||
Console.Write($"Distance: {dist}={chord.DistanceScales(chordNew)}+{chord.DistanceCommonTones(chordNew)}+{chordNew.InScale()} "); | ||
Console.WriteLine($"Chord: { chordNew.ToString()}"); | ||
|
||
chord = chordNew; | ||
} while (true); | ||
} | ||
|
||
static void Main3(string[] args) | ||
{ | ||
RhythmPatternBase pattern = new RhytmPatternComposite("AAAA", RhythmMaker.CreateRhytmPattern()); | ||
|
||
int tempo = 60; | ||
|
||
foreach (var fract in pattern.Notes()) | ||
{ | ||
midiOut.Send(MidiMessage.StartNote(48, 100, 1).RawData); | ||
Console.Write(fract + " "); | ||
Thread.Sleep(60 * 1000 * fract.p / fract.q / tempo); | ||
} | ||
} | ||
|
||
static void Main(string[] args) | ||
{ | ||
Melody12Tone m12tone = Compositions.Rach2ndSymphAdagio(); | ||
int tempo = 40; | ||
foreach (var nwd in m12tone.Notes()) | ||
{ | ||
if (!nwd.IsPause) | ||
midiOut.Send(MidiMessage.StartNote(nwd.note, 100, 1).RawData); | ||
Fraction fract = nwd.duration; | ||
Console.Write(fract + " "); | ||
Thread.Sleep(60 * 1000 * fract.p / fract.q / tempo); | ||
} | ||
} | ||
|
||
static int Distance(TwelveToneSet chord1, TwelveToneSet chord2) | ||
{ | ||
return chord1.TotalDistance(chord2) + chord2.InScale(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// 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("MusicComposer")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("MusicComposer")] | ||
[assembly: AssemblyCopyright("Copyright © 2016")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("3be5f334-0961-431a-8b73-8efdbde03d51")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// 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("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using MusicCore; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace MusicComposer | ||
{ | ||
public class RhythmMaker | ||
{ | ||
static public void FindTwoOfSameLength(RhythmPatternBase[] patterns, out RhythmPatternBase pattern1, out RhythmPatternBase pattern2) | ||
{ | ||
RhythmPatternBase p1, p2; | ||
do | ||
{ | ||
p1 = patterns[rand.Next(patterns.Length)]; | ||
} while (patterns.Count(p => (p.Length == p1.Length)) < 2); | ||
|
||
do | ||
{ | ||
p2 = patterns[rand.Next(patterns.Length)]; | ||
if (p1 != p2 && p1.Length == p2.Length) | ||
break; | ||
} while (true); | ||
pattern1 = p1; | ||
pattern2 = p2; | ||
} | ||
|
||
static Random rand = new Random(); | ||
|
||
static public RhythmPatternBase CreateRhytmPattern(int beatsPerMeasure=3, int minLenght = 15) | ||
{ | ||
HashSet<RhythmPatternBase> patterns = new HashSet<RhythmPatternBase>(); | ||
|
||
for (int i = 0; i < 5; i++) | ||
patterns.Add(new RhythmPattern(beatsPerMeasure, 2, rand)); | ||
|
||
while (true) | ||
{ | ||
string st = RhytmPatternComposite.sts[rand.Next(RhytmPatternComposite.sts.Length)]; | ||
RhythmPatternBase pattern1, pattern2; | ||
FindTwoOfSameLength(patterns.ToArray(), out pattern1, out pattern2); | ||
RhythmPatternBase patternNew = new RhytmPatternComposite(st, pattern1, pattern2); | ||
Console.WriteLine($"{st} = {patternNew.MeasuresCount}"); | ||
if (patternNew.MeasuresCount >= minLenght) | ||
return patternNew; | ||
patterns.Add(patternNew); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using MusicCore; | ||
|
||
namespace Tests.MusicCore | ||
{ | ||
[TestClass] | ||
public class FractionTest | ||
{ | ||
[TestMethod] | ||
public void Ctrs() | ||
{ | ||
Fraction fract = new Fraction(4, 6); | ||
Assert.AreEqual(2, fract.p); | ||
Assert.AreEqual(3, fract.q); | ||
} | ||
|
||
[TestMethod] | ||
public void TestGCD() | ||
{ | ||
Assert.AreEqual(5, Fraction.GCD(20, 15)); | ||
Assert.AreEqual(1, Fraction.GCD(17, 25)); | ||
Assert.AreEqual(2, Fraction.GCD(4, 6)); | ||
} | ||
} | ||
} |
Oops, something went wrong.