music_theory 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fbcc50c0ee55faff0c747fa2312e37fdf91690fd
4
- data.tar.gz: 41bf16f428f46e92f9c98671a3e0c178b425a9b1
3
+ metadata.gz: c0a12e58d6e7753a000bad198c0470d692296b49
4
+ data.tar.gz: 61836a453a80181bd3448d8a4eaeb0c790fe8682
5
5
  SHA512:
6
- metadata.gz: 8b0789452cd2456771e98936218cfffd9e068928fc74a23239d1228638b7bff90cf1b200a6bdd904325276323ec9fda4e0c80bf8e905b27f6b7b09e72d2ceda4
7
- data.tar.gz: f485e44ce864a1d2ca1cf92b5aba5f45514c246b4f20db74919fafe382e462a35af7c576859a2f67266dbf68bc6ba333fadecf619608c47b04c71af9b7769e92
6
+ metadata.gz: dc01cc1408d653b964b2821ff47cd946ecb921dbe233c4f4e5f2898b69c1cd372ea1608dcd73f5a48c0ef8b4d9dad9710dcb82f2802a98c26de0fa7a0ff07d36
7
+ data.tar.gz: 205323367f84d29931f8d3b6ebef701c8f48647d8cc8a522800edd2e62770494fc2e92a0046d23b2ea56fa7c561fc5f282556da1e05735c1aafb5386448b984f
data/.gitignore CHANGED
@@ -17,4 +17,3 @@ mkmf.log
17
17
 
18
18
  *.wav
19
19
  presentation*
20
- samples
@@ -1,3 +1,3 @@
1
1
  module MusicTheory
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,11 @@
1
+ require 'music_theory'
2
+
3
+ frequency = 293.665 # Middle D
4
+ scale = MusicTheory::Scale.new :major, distort: false, frequency: frequency, duration: 0.5
5
+ arpeggios = [scale.i.arpeggio, scale.iv.arpeggio, scale.v.arpeggio, scale.iv.arpeggio]
6
+ chords = [scale.i.chord, scale.iv.chord, scale.v.chord, scale.iv.chord]
7
+
8
+ harmony = MusicTheory::Harmonize.new arpeggios.map(&:samples).flatten, chords.map(&:samples).flatten
9
+
10
+
11
+ p = MusicTheory::Play.new arpeggios + [harmony] + [scale.i.chord]
data/samples/demo.rb ADDED
@@ -0,0 +1,90 @@
1
+ require 'music_theory'
2
+
3
+ low_a = 220 # Middle A
4
+ middle_c = 261.6 # Middle C
5
+ middle_d = 293.665 # Middle D
6
+ middle_f = 349.228 # Middle F
7
+ middle_g_sharp = 415.30 # Middle G#
8
+ middle_a = 440 # A
9
+
10
+ frequency = middle_g_sharp
11
+ # frequency = [low_a, middle_c, middle_d, middle_f, middle_g_sharp, middle_a ].sample
12
+
13
+ base_pattern = [
14
+ { notes: 2, duration: 0.25 },
15
+ { notes: 8, duration: 0.25 },
16
+ { notes: 6, duration: 0.25 },
17
+ { notes: 5, duration: 0.25 },
18
+ { notes: 6, duration: 0.25 },
19
+ { notes: 5, duration: 0.125 },
20
+ { notes: 4, duration: 0.375 },
21
+ { notes: 5, duration: 0.25 }
22
+ ]
23
+
24
+ pattern_1 = [
25
+ { notes: 6, duration: 0.5 },
26
+ { notes: 4, duration: 0.5 },
27
+ { notes: 1, duration: 0.5 },
28
+ { notes: 5, duration: 0.25 },
29
+ { notes: 4, duration: 0.25 }
30
+ ]
31
+ pattern_2 = [
32
+ { notes: 6, duration: 0.125 },
33
+ { notes: 5, duration: 0.125 },
34
+ { notes: 6, duration: 0.125 },
35
+ { notes: 5, duration: 0.125 },
36
+ { notes: 6, duration: 0.125 },
37
+ { notes: 5, duration: 0.375 },
38
+ { notes: 6, duration: 0.125 },
39
+ { notes: 5, duration: 0.125 },
40
+ { notes: 6, duration: 0.125 },
41
+ { notes: 5, duration: 0.125 },
42
+ { notes: 6, duration: 0.125 },
43
+ { notes: 7, duration: 0.375 }
44
+
45
+ ]
46
+ pattern = (base_pattern + pattern_1 + base_pattern + pattern_2)
47
+
48
+
49
+ base_note = MusicTheory::Scale.new :mixolydian, frequency: frequency
50
+ base_note_2 = MusicTheory::Scale.new :mixolydian, frequency: frequency * 2
51
+
52
+ melody = pattern.map {|note| MusicTheory::Note.new( frequency: base_note.scale_notes[ note[:notes] - 1].frequency, duration: note[:duration] ) }
53
+ melody_2 = pattern_2.map {|note| MusicTheory::Note.new( frequency: base_note.scale_notes[ note[:notes] - 1].frequency, duration: note[:duration] ) }
54
+
55
+ distorted_melody = pattern.map {|note| MusicTheory::Note.new( frequency: base_note.scale_notes[ note[:notes] - 1].frequency, duration: note[:duration], distort: true ) }
56
+ distorted_melody_2 = pattern.map {|note| MusicTheory::Note.new( frequency: base_note_2.scale_notes[ note[:notes] - 1].frequency, duration: note[:duration], distort: true ) }
57
+
58
+ scale = MusicTheory::Scale.new :mixolydian, distort: false, frequency: frequency, duration: 0.5
59
+ distorted_scale = MusicTheory::Scale.new :mixolydian, distort: true, frequency: frequency, duration: 0.5
60
+
61
+ chord_progression = [scale.iv.chord, scale.i.chord, scale.v.chord, scale.iv.chord]
62
+ distorted_chord_progression = [distorted_scale.iv.chord, distorted_scale.i.chord, distorted_scale.v.chord, distorted_scale.iv.chord]
63
+
64
+
65
+ melody_samples = melody.map(&:samples).flatten
66
+ melody_samples_2 = melody_2.map(&:samples).flatten
67
+ melodies = [melody_samples, melody_samples_2]
68
+
69
+ first_chords = chord_progression.map(&:samples).flatten
70
+
71
+ first_harmony = MusicTheory::Harmonize.new(melody_samples, first_chords)
72
+
73
+ distorted_melody_samples = distorted_melody.map(&:samples).flatten
74
+ distorted_melody_samples_2 = distorted_melody_2.map(&:samples).flatten
75
+ distorted_melodies = [distorted_melody_samples, distorted_melody_samples_2]
76
+
77
+ distorted_first_chords = distorted_chord_progression.map(&:samples).flatten
78
+
79
+ mixed_first_harmony = MusicTheory::Harmonize.new distorted_melodies.sample, first_chords
80
+ mixed_second_harmony = MusicTheory::Harmonize.new distorted_melodies.sample, first_chords
81
+ mixed_harmonys = [mixed_first_harmony ]
82
+
83
+
84
+ distorted_first_harmony = MusicTheory::Harmonize.new distorted_melodies.sample, distorted_first_chords
85
+ distorted_second_harmony = MusicTheory::Harmonize.new distorted_melodies.sample, distorted_first_chords
86
+ distorted_harmonys = [distorted_first_harmony, distorted_second_harmony]
87
+
88
+ song = melody + [first_harmony] + mixed_harmonys + distorted_harmonys + distorted_chord_progression.map {|x| x.duration = 0.50; x } + [scale.i.chord]
89
+
90
+ p = MusicTheory::Play.new song
data/samples/happy.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'music_theory'
2
+
3
+
4
+ frequency = 349.228 # Middle F
5
+
6
+ pattern = [
7
+ { notes: 4, duration: 0.25 },
8
+ { notes: 3, duration: 0.25 },
9
+ { notes: 4, duration: 0.75 },
10
+ { notes: 5, duration: 0.5 },
11
+ { notes: 3, duration: 0.5 },
12
+ { notes: 3, duration: 0.5 },
13
+ { notes: 1, duration: 0.5 },
14
+ { notes: 4, duration: 0.25 },
15
+ { notes: 3, duration: 0.25 },
16
+ { notes: 4, duration: 0.75 },
17
+ { notes: 4, duration: 0.5 },
18
+ { notes: 3, duration: 0.25 },
19
+ { notes: 4, duration: 1.0 },
20
+ { notes: 1, duration: 0.25 },
21
+ { notes: 1, duration: 0.5 },
22
+ { notes: 3, duration: 0.75 }
23
+ ];
24
+
25
+ base_note = MusicTheory::Scale.new :mixolydian, frequency: frequency;
26
+
27
+ melody = pattern.map {|note| MusicTheory::Note.new( frequency: base_note.scale_notes[ note[:notes] ].frequency, duration: note[:duration] ) };
28
+ scale = MusicTheory::Scale.new :major, distort: false, frequency: frequency, duration: 0.5;
29
+
30
+ chord_progression = [scale.vi.chord, scale.v.chord, scale.v.chord, scale.i.chord];
31
+
32
+ melody_samples = melody.map(&:samples).flatten;
33
+
34
+ chord_progression_samples = chord_progression.map(&:samples).flatten;
35
+
36
+ harmonization = MusicTheory::Harmonize.new(melody_samples, chord_progression_samples);
37
+
38
+ song = melody + [harmonization]
39
+
40
+ p = MusicTheory::Play.new song
@@ -0,0 +1,36 @@
1
+ require 'music_theory'
2
+ frequency = 349.228 # Middle F
3
+
4
+ pattern = [
5
+ { notes: 4, duration: 0.25 },
6
+ { notes: 3, duration: 0.25 },
7
+ { notes: 1, duration: 0.25 },
8
+ { notes: 4, duration: 0.5 },
9
+ { notes: 4, duration: 0.5 },
10
+ { notes: 5, duration: 0.5 },
11
+ { notes: 4, duration: 0.25 },
12
+ { notes: 5, duration: 0.25 },
13
+ { notes: 6, duration: 0.25 },
14
+ { notes: 5, duration: 0.25 },
15
+ { notes: 4, duration: 0.25 },
16
+ { notes: 3, duration: 0.25 },
17
+ { notes: 4, duration: 0.25 }
18
+ ]
19
+
20
+ base_note = MusicTheory::Scale.new :major, frequency: frequency
21
+
22
+ melody = pattern.map {|note| MusicTheory::Note.new( frequency: base_note.scale_notes[ note[:notes] - 1].frequency, duration: note[:duration] ) }
23
+
24
+ scale = MusicTheory::Scale.new :major, distort: false, frequency: frequency, duration: 0.5
25
+ clean = [scale.i.chord, scale.v.chord, scale.vi.chord, scale.iv.chord]
26
+
27
+ melody_samples = melody.map(&:samples).flatten
28
+
29
+ first_chords = scale.i.chord.samples + scale.v.chord.samples
30
+ second_chords = scale.vi.chord.samples + scale.iv.chord.samples
31
+
32
+ first_harmony = MusicTheory::Harmonize.new melody_samples, first_chords
33
+ second_harmony = MusicTheory::Harmonize.new melody_samples, second_chords
34
+ harmonies = [first_harmony, second_harmony]
35
+
36
+ p = MusicTheory::Play.new melody + harmonies + harmonies + clean.map {|x| x.duration = 0.50; x } + [scale.i.chord]
data/samples/song.rb ADDED
@@ -0,0 +1,115 @@
1
+ require 'music_theory'
2
+
3
+
4
+ low_a = 220 # Middle A
5
+ middle_c = 261.6 # Middle C
6
+ middle_d = 293.665 # Middle D
7
+ middle_f = 349.228 # Middle F
8
+ middle_g_sharp = 415.30 # Middle G#
9
+ middle_a = 440 # A
10
+
11
+ frequency = [low_a, middle_c, middle_d, middle_f, middle_g_sharp, middle_a ].sample
12
+
13
+ pattern = [
14
+ { notes: 4, duration: 0.25 },
15
+ { notes: 3, duration: 0.25 },
16
+ { notes: 1, duration: 0.25 },
17
+ { notes: 4, duration: 0.5 },
18
+ { notes: 4, duration: 0.5 },
19
+ { notes: 5, duration: 0.5 },
20
+ { notes: 4, duration: 0.25 },
21
+ { notes: 5, duration: 0.25 },
22
+ { notes: 6, duration: 0.25 },
23
+ { notes: 5, duration: 0.25 },
24
+ { notes: 4, duration: 0.25 },
25
+ { notes: 3, duration: 0.25 },
26
+ { notes: 4, duration: 0.25 }
27
+ ]
28
+
29
+ pattern_2 = [
30
+ { notes: 4, duration: 0.25 },
31
+ { notes: 3, duration: 0.25 },
32
+ { notes: 1, duration: 0.25 },
33
+ { notes: 4, duration: 0.5 },
34
+ { notes: 4, duration: 0.5 },
35
+ { notes: 3, duration: 0.5 },
36
+ { notes: 1, duration: 0.25 },
37
+ { notes: 3, duration: 0.25 },
38
+ { notes: 4, duration: 0.25 },
39
+ { notes: 3, duration: 0.125 },
40
+ { notes: 4, duration: 0.125 },
41
+ { notes: 3, duration: 0.125 },
42
+ { notes: 4, duration: 0.125 },
43
+ { notes: 3, duration: 0.25 },
44
+ { notes: 1, duration: 0.25 } ]
45
+
46
+ pattern_3 = [
47
+ { notes: 4, duration: 0.25 },
48
+ { notes: 3, duration: 0.25 },
49
+ { notes: 1, duration: 0.25 },
50
+ { notes: 4, duration: 0.5 },
51
+ { notes: 4, duration: 0.5 },
52
+ { notes: 3, duration: 0.5 },
53
+ { notes: 1, duration: 0.25 },
54
+ { notes: 3, duration: 0.25 },
55
+ { notes: 4, duration: 0.25 },
56
+ { notes: 3, duration: 0.125 },
57
+ { notes: 4, duration: 0.125 },
58
+ { notes: 6, duration: 0.125 },
59
+ { notes: 4, duration: 0.125 },
60
+ { notes: 3, duration: 0.25 },
61
+ { notes: 1, duration: 0.25 } ]
62
+
63
+ patterns = [pattern, pattern_2, pattern_3]
64
+
65
+ base_note = MusicTheory::Scale.new :major, frequency: frequency
66
+ base_note_2 = MusicTheory::Scale.new :major, frequency: frequency * 2
67
+ base_note_3 = MusicTheory::Scale.new :major, frequency: frequency * 3
68
+
69
+ melody = pattern.map {|note| MusicTheory::Note.new( frequency: base_note.scale_notes[ note[:notes] - 1].frequency, duration: note[:duration] ) }
70
+ melody_2 = pattern_2.map {|note| MusicTheory::Note.new( frequency: base_note.scale_notes[ note[:notes] - 1].frequency, duration: note[:duration] ) }
71
+ melody_3 = pattern_3.map {|note| MusicTheory::Note.new( frequency: base_note.scale_notes[ note[:notes] - 1].frequency, duration: note[:duration] ) }
72
+
73
+ distorted_melody = pattern.map {|note| MusicTheory::Note.new( frequency: base_note.scale_notes[ note[:notes] - 1].frequency, duration: note[:duration], distort: true ) }
74
+ distorted_melody_2 = pattern_2.map {|note| MusicTheory::Note.new( frequency: base_note_2.scale_notes[ note[:notes] - 1].frequency, duration: note[:duration], distort: true ) }
75
+ distorted_melody_3 = pattern_3.map {|note| MusicTheory::Note.new( frequency: base_note_3.scale_notes[ note[:notes] - 1].frequency, duration: note[:duration], distort: true ) }
76
+
77
+ scale = MusicTheory::Scale.new :major, distort: false, frequency: frequency, duration: 0.5
78
+ distorted_scale = MusicTheory::Scale.new :major, distort: true, frequency: frequency, duration: 0.5
79
+
80
+ clean_chord_progression = [scale.i.chord, scale.v.chord, scale.vi.chord, scale.iv.chord]
81
+ distorted_chord_progression = [distorted_scale.i.chord, distorted_scale.v.chord, distorted_scale.vi.chord, distorted_scale.iv.chord]
82
+
83
+
84
+ melody_samples = melody.map(&:samples).flatten
85
+ melody_samples_2 = melody_2.map(&:samples).flatten
86
+ melody_samples_3 = melody_3.map(&:samples).flatten
87
+ melodies = [melody_samples, melody_samples_2, melody_samples_3]
88
+
89
+ first_chords = scale.i.chord.samples + scale.v.chord.samples
90
+ second_chords = scale.vi.chord.samples + scale.iv.chord.samples
91
+
92
+ first_harmony = MusicTheory::Harmonize.new melodies.sample, first_chords
93
+ second_harmony = MusicTheory::Harmonize.new melodies.sample, second_chords
94
+ harmonies = [first_harmony, second_harmony]
95
+
96
+ distorted_melody_samples = distorted_melody.map(&:samples).flatten
97
+ distorted_melody_samples_2 = distorted_melody_2.map(&:samples).flatten
98
+ distorted_melody_samples_3 = distorted_melody_3.map(&:samples).flatten
99
+ distorted_melodies = [distorted_melody_samples, distorted_melody_samples_2, distorted_melody_samples_3]
100
+
101
+ distorted_first_chords = distorted_scale.i.chord.samples + distorted_scale.v.chord.samples
102
+ distorted_second_chords = distorted_scale.vi.chord.samples + distorted_scale.iv.chord.samples
103
+
104
+ mixed_first_harmony = MusicTheory::Harmonize.new distorted_melodies.sample, first_chords
105
+ mixed_second_harmony = MusicTheory::Harmonize.new distorted_melodies.sample, second_chords
106
+ mixed_harmonys = [mixed_first_harmony, mixed_second_harmony]
107
+
108
+
109
+ distorted_first_harmony = MusicTheory::Harmonize.new distorted_melodies.sample, distorted_first_chords
110
+ distorted_second_harmony = MusicTheory::Harmonize.new distorted_melodies.sample, distorted_second_chords
111
+ distorted_harmonys = [distorted_first_harmony, distorted_second_harmony]
112
+
113
+ song = melody + harmonies + mixed_harmonys + distorted_harmonys + distorted_chord_progression.map {|x| x.duration = 0.50; x } + [scale.i.chord]
114
+
115
+ p = MusicTheory::Play.new song
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: music_theory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Eggett
@@ -108,6 +108,11 @@ files:
108
108
  - lib/music_theory/version.rb
109
109
  - music_theory.gemspec
110
110
  - note-charted.html
111
+ - samples/arpeggios.rb
112
+ - samples/demo.rb
113
+ - samples/happy.rb
114
+ - samples/simple_song.rb
115
+ - samples/song.rb
111
116
  homepage: ''
112
117
  licenses:
113
118
  - MIT