music_theory 0.0.1 → 0.1.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: c15cd87fabd67ca0ede6f68605d580bc3cc7ba2d
4
- data.tar.gz: 0e93f91ed13aca5f3fc89e35b5084571bf3b7333
3
+ metadata.gz: 00ba460c39f1666763146ade0d33e4d99db9c925
4
+ data.tar.gz: ceaf0e9f7bedb00e62cb97cdfa8957f5d52e7327
5
5
  SHA512:
6
- metadata.gz: 6b92d549db767e82445777e9224badc158750ec740a2eaf292fc5071f2ffc944b6355907423b1e0e8c4269a6c6f52614f1d3db8c6c4f21a9ef53be316d7cf19d
7
- data.tar.gz: 7b52db9f8d81ed3bce32b9ce275b81087e8d388a92a196f0691c78a4651ce883497eabc73638002fe91d26383d40113a26c7c7c7f7f38b1789c6ba6c1385c59d
6
+ metadata.gz: 70b088280057088c6cdc6967d4ee73412f7f5f9a884ef4e8e52226774de354c6aa42ad64cad00e3046b0385b0154a75ff25c0aaa156fc4993a3262cba697d4d6
7
+ data.tar.gz: 81f5c99a4d3c7147f90579a1b8608cb264c05a3659487d479b000c0cd7bb56a4c512ddbe899a32b712414c5a5a909821ff27dc359d46cd7dc0736f1bee5d95dc
@@ -22,12 +22,14 @@ module MusicTheory
22
22
  new_samples[i] += value
23
23
  end
24
24
  end
25
+ normalize_samples(new_samples)
26
+ end
25
27
 
28
+ def normalize_samples(new_samples)
26
29
  max = new_samples.map {|s| s.abs }.max
27
30
  multiplier = 1.0 / max
28
31
  new_samples.map!{ |s| multiplier * s }
29
- end
30
-
32
+ end
31
33
 
32
34
  def samples
33
35
  flatten_third
@@ -1,8 +1,5 @@
1
- require 'music_theory/output'
2
-
3
1
  module MusicTheory
4
2
  class Modes
5
- include MusicTheory::Output
6
3
  S = 1
7
4
  T = 2
8
5
  I = [T, T, S, T, T, T, S]
@@ -18,15 +15,28 @@ module MusicTheory
18
15
 
19
16
  def self.ionian; I; end
20
17
  self.singleton_class.send(:alias_method, :major, :ionian)
18
+ self.singleton_class.send(:alias_method, :i, :ionian)
19
+
21
20
  def self.dorian; II; end
21
+ self.singleton_class.send(:alias_method, :ii, :dorian)
22
+
22
23
  def self.phrygian; III; end
24
+ self.singleton_class.send(:alias_method, :iii, :phrygian)
25
+
23
26
  def self.lydian; IV; end
27
+ self.singleton_class.send(:alias_method, :iv, :lydian)
28
+
24
29
  def self.mixolydian; V; end
30
+ self.singleton_class.send(:alias_method, :v, :mixolydian)
31
+
25
32
  def self.aeolian; VI; end
26
33
  self.singleton_class.send(:alias_method, :minor, :aeolian)
34
+ self.singleton_class.send(:alias_method, :vi, :aeolian)
35
+
27
36
  def self.locrian; VII; end
28
- def self.chromatic; CHROMATIC; end
37
+ self.singleton_class.send(:alias_method, :vii, :locrian)
29
38
 
39
+ def self.chromatic; CHROMATIC; end
30
40
 
31
41
  end
32
42
 
@@ -6,7 +6,8 @@ module MusicTheory
6
6
  attr_accessor :frequency, :duration, :output_file_name, :distort
7
7
 
8
8
  def initialize(options = {})
9
- @frequency = options[:frequency].to_f || 220.0 # Note frequency in Hz
9
+ @frequency = options[:frequency] || 440.0 # Note frequency in Hz
10
+ @frequency = @frequency.to_f
10
11
  @duration = options[:duration] || 1.0 # Number of seconds per note
11
12
  @distort = options[:distort] || false
12
13
  @output_file_name = options[:output_file_name] || 'note' # File name to write (without extension)
@@ -41,7 +42,7 @@ module MusicTheory
41
42
 
42
43
  def distort!(samples)
43
44
  samples.map do |sample|
44
- negative = (sample) < 0
45
+ negative = sample < 0
45
46
  sample *= 8.to_f
46
47
  if sample.abs > 5
47
48
  sample = 5
@@ -51,9 +52,6 @@ module MusicTheory
51
52
  end
52
53
  end
53
54
 
54
- def scale
55
-
56
- end
57
55
  end
58
56
 
59
57
  end
@@ -3,16 +3,19 @@ require 'music_theory/output'
3
3
  module MusicTheory
4
4
  class Octave
5
5
  include MusicTheory::Output
6
- attr_accessor :starting_note, :number_of_octaves, :direction, :output_file_name, :all_notes
6
+ attr_accessor :starting_note, :amount, :direction, :output_file_name, :all_notes
7
7
 
8
8
  def initialize(options = {})
9
9
  @starting_note = options[:starting_note] || MusicTheory::Note.new # Note to start on
10
- @number_of_octaves= options[:number_of_octaves] || 2 # Number of octaves to repeat
10
+ @amount= options[:amount] || 2 # Number of octaves to repeat
11
11
  @direction = options[:direction] || 'asc' # Number of seconds per note
12
12
  @output_file_name = options[:output_file_name] || 'octave' # File name to write (without extension)
13
- @all_notes = []
14
- all_notes << starting_note
15
- number_of_octaves.to_i.times do
13
+ build_octave
14
+ end
15
+
16
+ def build_octave
17
+ @all_notes = [ starting_note ]
18
+ amount.to_i.times do
16
19
  new_note = all_notes.last.clone
17
20
  if direction == 'asc'
18
21
  new_note.frequency = all_notes.last.frequency * 2
@@ -27,9 +30,6 @@ module MusicTheory
27
30
  all_notes.map(&:samples).flatten
28
31
  end
29
32
 
30
- def sample_rate
31
- starting_note.sample_rate
32
- end
33
33
  end
34
34
 
35
35
  end
@@ -3,32 +3,21 @@ require 'music_theory/output'
3
3
  module MusicTheory
4
4
  class Scale
5
5
  include MusicTheory::Output
6
- attr_accessor :starting_note, :number_of_octaves, :direction, :output_file_name, :all_notes, :scale_type, :scale_notes, :distort, :duration, :frequency, :sample_rate
6
+ attr_accessor :starting_note, :number_of_octaves, :direction, :output_file_name, :all_notes, :scale_type, :scale_notes, :distort, :duration, :frequency
7
7
 
8
8
  def initialize(scale_type = :major, options = {})
9
- @scale_type = scale_type
9
+ @scale_type = scale_type
10
10
  @distort = options[:distort] || false
11
11
  @duration = options[:duration] || 0.5
12
12
  @frequency = options[:frequency] || 220.0
13
- @starting_note = create_new_note # Note to start on
14
-
15
- @number_of_octaves= options[:number_of_octaves] || 2 # Number of octaves to repeat
16
- @direction = options[:direction] || 'asc' # Number of seconds per note
13
+ @starting_note = create_new_note(frequency) # Note to start on
17
14
  @output_file_name = options[:output_file_name] || 'scale' # File name to write (without extension)
18
15
  set_all_notes
19
16
  set_scale_notes
20
17
  end
21
18
 
22
- def third
23
- third ||= MusicTheory::Third.new self
24
- end
25
-
26
- def chord
27
- third.chord
28
- end
29
-
30
- def twelth_root_of_two
31
- (2 ** (1.0/12))
19
+ def twelfth_root_of_two
20
+ 2 ** (1.0/12)
32
21
  end
33
22
 
34
23
  def mode
@@ -44,15 +33,14 @@ module MusicTheory
44
33
  end
45
34
  end
46
35
 
47
- def create_new_note
48
- MusicTheory::Note.new( frequency: frequency, duration: duration, distort: distort)
36
+ def create_new_note(note_frequency)
37
+ MusicTheory::Note.new( frequency: note_frequency, duration: duration, distort: distort)
49
38
  end
50
39
 
51
40
  def set_all_notes
52
41
  @all_notes = [@starting_note]
53
42
  12.times do
54
- new_note = create_new_note
55
- new_note.frequency = (all_notes.last.frequency * twelth_root_of_two)
43
+ new_note = create_new_note(all_notes.last.frequency * twelfth_root_of_two)
56
44
  all_notes << new_note
57
45
  end
58
46
  end
@@ -61,10 +49,13 @@ module MusicTheory
61
49
  scale_notes.map(&:samples).flatten
62
50
  end
63
51
 
64
- def sample_rate
65
- starting_note.sample_rate
52
+ def third
53
+ third ||= MusicTheory::Third.new self
66
54
  end
67
55
 
56
+ def chord
57
+ third.chord
58
+ end
68
59
  end
69
60
 
70
61
  end
@@ -3,15 +3,14 @@ require 'music_theory/output'
3
3
  module MusicTheory
4
4
  class Third
5
5
  include MusicTheory::Output
6
-
7
6
  attr_accessor :scale, :all_notes
8
7
 
9
8
  def initialize(scale)
10
9
  @scale = scale
11
- @all_notes = [@scale.scale_notes.first]
10
+ @all_notes = [scale.scale_notes.first]
12
11
  current = 0
13
- double_scale_notes = @scale.scale_notes * 2
14
- @scale.mode.in_groups_of(2, false) do |group|
12
+ double_scale_notes = scale.scale_notes * 2
13
+ scale.mode.in_groups_of(2, false) do |group|
15
14
  current += group.sum
16
15
  all_notes << double_scale_notes[current]
17
16
  end
@@ -19,19 +18,17 @@ module MusicTheory
19
18
  all_notes.sort_by! {|note| note.frequency}
20
19
  end
21
20
 
22
-
23
- def output_file_name
24
- scale.output_file_name || 'thirds'
25
- end
26
-
27
21
  def samples
28
22
  all_notes.map(&:samples).flatten
29
- # chord_samples
30
23
  end
31
24
 
32
25
  def chord
33
26
  chord ||= MusicTheory::Chord.new self
34
27
  end
35
28
 
29
+ def output_file_name
30
+ scale.output_file_name || 'thirds'
31
+ end
32
+
36
33
  end
37
34
  end
@@ -1,3 +1,3 @@
1
1
  module MusicTheory
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end