music_set_theory 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a54615c8b9ddf6ecabe27b78c6d84d76fb9c618fb3120267eadd21ed67e7267
4
- data.tar.gz: 9d56b5499b87e6eed6e6c36cf3d396885b6cfb28340f855e79ae8ce2e8fecc0c
3
+ metadata.gz: ebde4ba3edcbccaba9146b39ee39fbe29757cb5283924768c953a517782e09f8
4
+ data.tar.gz: be3cfa795e830ce5f5f0534eb3f62368127dfa70e3abcb5055815dc63cad822c
5
5
  SHA512:
6
- metadata.gz: ffabf6585aade8f22055f93594e9b0f265f4da8fc110917a0460072abb67b2b82953a72c4d31dab145ea9bccdf91bb51743d26f371a1e112f41a201c82b62831
7
- data.tar.gz: d5e6d8ed0e69e4e9a865cb233ff96efe92ba48690ae5ac3a7a087ec03e6a8b77e4d3d57e46d96a43528fce92985b6111cba4c86252f0f0dab033591f8a63d45f
6
+ metadata.gz: d03972156c15ecc210b0fcb02df239e743e96e6b22f415d3ec153e4769b9e07d44b5bd721b5c5417ef91e836d1c4fa847e7d5c4abfb28840ab4a87d064d2cc8a
7
+ data.tar.gz: 697638e92311f8f085c4d82537169c6a80fe38df64224df8ab597b77f86c22626c36f69cd47c393454ad3260ae575d155c27b61cc00dd019ef08acd9b1add1af
data/README.md CHANGED
@@ -9,20 +9,19 @@ The music theory treats notes and the relationships among them, i.e., temperamen
9
9
 
10
10
  ## Installation
11
11
 
12
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
13
-
14
12
  Install the gem and add to the application's Gemfile by executing:
15
13
 
16
14
  ```bash
17
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ bundle add music_set_theory
18
16
  ```
19
17
 
20
18
  If bundler is not being used to manage dependencies, install the gem by executing:
21
19
 
22
20
  ```bash
23
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ gem install music_set_theory
24
22
  ```
25
23
 
24
+
26
25
  ## Usage
27
26
 
28
27
  See the `examples/` directory. The scripts for listing chords and scales are there.
@@ -43,13 +42,13 @@ If you want to test all:
43
42
  bundle exec rake test
44
43
  ```
45
44
 
46
- test a specified one:
45
+ test a specified test case:
47
46
 
48
47
  ```bash
49
48
  TEST=./test/something_test.rb bundle exec rake test
50
49
  ```
51
50
 
52
- If you want to test a test in a specified file, then:
51
+ If you want to test specified test method(s), then:
53
52
 
54
53
  ```bash
55
54
  TESTOPTS=--name=/pattern-matches-to-the-description/ TEST=./test/something_test.rb bundle exec rake test
@@ -264,17 +264,35 @@ end
264
264
 
265
265
  require 'active_support'
266
266
  require 'active_support/core_ext/object/deep_dup'
267
+ require 'ice_nine'
267
268
  module MusicSetTheory
268
269
  module MusUtility
269
270
 
270
271
  def deep_freeze( obj )
272
+ IceNine.deep_freeze(obj)
273
+ end
274
+
275
+ def deep_melt( obj )
271
276
  case obj
272
277
  when Hash
273
- obj.each { |k, v| deep_freeze(k); deep_freeze(v) }
278
+ obj.each_with_object({}) do |(key, value), new_hash|
279
+ new_hash[deep_melt(key)] = deep_melt(value)
280
+ end
274
281
  when Array
275
- obj.each { |e| deep_freeze(e) }
282
+ obj.map { |element| deep_melt(element) }
283
+ when Object
284
+ # インスタンス変数の解除
285
+ obj.instance_variables.each do |var|
286
+ deep_melt(var)
287
+ value = obj.instance_variable_get(var)
288
+ obj.remove_instance_variable(var)
289
+ obj.instance_variable_set(var, deep_melt(value))
290
+ end
291
+ obj.dup rescue obj # 凍結状態を解除
292
+ else
293
+ obj.dup rescue obj
276
294
  end
277
- obj.freeze
295
+ obj.dup rescue obj
278
296
  end
279
297
 
280
298
  end
@@ -121,6 +121,9 @@ module MusicSetTheory
121
121
  # Note: it is easier to define scales using the noteseq_scale class (this
122
122
  # file) and chord using the noteseq_chord class (in chords.py)
123
123
  #
124
+ # ==== Warning
125
+ # - ! This method updates `nseq_temp`.
126
+ #
124
127
  attr_accessor :nseq_name, :nseq_type, :nseq_temp, :nseq_posn
125
128
  attr_accessor :nseq_nat_posns, :nseq_abbrev, :nseq_synonyms,
126
129
  :nseq_other_abbrevs
@@ -132,7 +135,10 @@ module MusicSetTheory
132
135
  nseq_other_abbrevs: [] )
133
136
  self.nseq_name = nseq_name
134
137
  self.nseq_type = nseq_type
138
+
135
139
  self.nseq_temp = nseq_temp
140
+ # self.nseq_temp = deep_melt(nseq_temp.deep_dup)
141
+
136
142
  self.nseq_posn = nseq_posn
137
143
 
138
144
  self.nseq_nat_posns = nseq_nat_posns
@@ -140,7 +146,8 @@ module MusicSetTheory
140
146
  self.nseq_synonyms = nseq_synonyms
141
147
  self.nseq_other_abbrevs = nseq_other_abbrevs
142
148
 
143
- self.register_with_temp()
149
+ #
150
+ self.register_with_temp(self.nseq_temp)
144
151
  end
145
152
 
146
153
  #
@@ -189,8 +196,10 @@ module MusicSetTheory
189
196
 
190
197
  # Registers this note sequence with the underlying temperament, so
191
198
  # that it can be looked up by name, by abbreviation or by sequence.
199
+ # ==== Warning
200
+ # - This methods updates `self.nseq_temp`
192
201
  #
193
- def register_with_temp
202
+ def register_with_temp( nseq_temp = self.nseq_temp )
194
203
  if self.nseq_synonyms
195
204
  #if self.nseq_name not in self.nseq_synonyms
196
205
  if !(self.nseq_synonyms.include? self.nseq_name)
@@ -212,7 +221,9 @@ module MusicSetTheory
212
221
  else
213
222
  our_abbrevs = [self.nseq_abbrev]
214
223
  end
215
- self.nseq_temp.seq_maps.add_elem(
224
+
225
+ #
226
+ nseq_temp.seq_maps.add_elem(
216
227
  self, self.nseq_type, our_names, our_abbrevs, self.nseq_posn)
217
228
  end
218
229
 
@@ -344,55 +355,114 @@ module MusicSetTheory
344
355
  DISC_MIN_NOTE_POS = [0, 2, 3, 5, 6, 9, 11]
345
356
  HUNGARIAN_NOTE_POS = [0, 3, 4, 6, 7, 9, 10]
346
357
 
358
+
347
359
  # For ease of comprehension, we have the list of modes as arrays which
348
360
  # can be browsed from outside.
349
- MAJORMODES = [ "Ionian",
361
+ MAJOR_MODES = [ "Ionian",
350
362
  "Dorian",
351
363
  "Phrygian",
352
364
  "Lydian",
353
365
  "Mixolydian",
354
366
  "Aeolian",
355
367
  "Locrian", ]
368
+ MAJORMODES = MAJOR_MODES
356
369
 
357
- MELMINORMODES = [ "Jazz Minor",
370
+ MEL_MINOR_MODES = [ "Jazz Minor",
358
371
  "Dorian " + M_FLAT + "9",
359
372
  "Lydian Augmented",
360
373
  "Lydian Dominant",
361
374
  "Mixolydian " + M_FLAT + "13",
362
375
  "Semilocrian",
363
376
  "Superlocrian", ]
377
+ MELMINORMODES = MEL_MINOR_MODES
364
378
 
365
- HARMINORMODES = [ "Harmonic Minor",
379
+ HARM_MINOR_MODES = [ "Harmonic Minor",
366
380
  "Locrian " + M_SHARP + "6",
367
381
  "Ionian Augmented",
368
382
  "Romanian",
369
383
  "Phrygian Dominant",
370
384
  "Lydian " + M_SHARP + "2",
371
385
  "Ultralocrian", ]
386
+ HARMINORMODES = HARM_MINOR_MODES # for compatibility... typo?
372
387
 
373
- HARMMAJORMODES = [ "Harmonic Major",
388
+ HARM_MAJOR_MODES = [ "Harmonic Major",
374
389
  "Dorian " + M_FLAT + "6",
375
390
  "Phrygian " + M_FLAT + "4",
376
391
  "Lydian " + M_FLAT + "3",
377
392
  "Mixolydian " + M_FLAT + "9",
378
393
  "Lydian " + M_SHARP + "2 " + M_SHARP + "5",
379
394
  "Locrian " + M_FLAT + M_FLAT + "7", ]
395
+ HARMMAJORMODES = HARM_MAJOR_MODES
380
396
 
381
- DISCORDMINMODES = [ "Melodic Minor " + M_FLAT + "5",
397
+ DISCORD_MIN_MODES = [ "Melodic Minor " + M_FLAT + "5",
382
398
  "Dorian " + M_FLAT + "9 " + M_FLAT + "4",
383
399
  "Minor Lydian Augmented",
384
400
  "Lydian Dominant " + M_FLAT + "9",
385
401
  "Lydian Augmented " + M_SHARP + "2 " + M_SHARP + "3",
386
402
  "Semilocrian " + M_FLAT + M_FLAT + "7",
387
403
  "Superlocrian " + M_FLAT + M_FLAT + "6", ]
404
+ DISCORDMINMODES = DISCORD_MIN_MODES
388
405
 
389
- HUNGARIANMODES = [ "Hungarian",
406
+ HUNGARIAN_MODES = [ "Hungarian",
390
407
  "Superlocrian " + M_FLAT + M_FLAT + "6 " + M_FLAT + M_FLAT + "7",
391
408
  "Harmonic Minor " + M_FLAT + "5",
392
409
  "Superlocrian " + M_SHARP + "6",
393
410
  "Melodic Minor " + M_SHARP + "5",
394
411
  "Dorian " + M_FLAT + "9 " + M_SHARP + "11",
395
412
  "Lydian Augmented " + M_SHARP + "3", ]
413
+ HUNGARIANMODES = HUNGARIAN_MODES
414
+
415
+ MODE_ARRAY = [
416
+ MAJOR_MODES,
417
+ MEL_MINOR_MODES,
418
+ HARM_MINOR_MODES,
419
+ HARM_MAJOR_MODES,
420
+ DISCORD_MIN_MODES,
421
+ HUNGARIAN_MODES,
422
+ ]
423
+ end
424
+
425
+ module MusicSetTheory
426
+
427
+ #
428
+ #
429
+ #
430
+ Pentatonic_NAT_POSNS = (0...5).to_a # 5音音階
431
+ Hexatonic_NAT_POSNS = (0...6).to_a # 6音音階
432
+ Heptatonic_NAT_POSNS = HEPT_NAT_POSNS # 7音音階
433
+ Octatonic_NAT_POSNS = (0...8).to_a # 8音音階
434
+
435
+ # Pentatonic.
436
+ #
437
+ #
438
+ MAJOR_PENTA_NOTE_POS = [ 0, 2, 4, 7, 9, ]
439
+ MINOR_PENTA_NOTE_POS = [ 0, 3, 5, 7, 10, ]
440
+ RYUKYU_PENTA_NOTE_POS = [ 0, 4, 5, 7, 11, ]
441
+
442
+ BLUES_HEXA_NOTE_POS = [ 0, 3, 5, 6, 7, 10, ]
443
+
444
+ def self.def_scale( const_name, name: , tment: ,
445
+ note_pos: , modes: [],
446
+ scale_array: :ScaleArray )
447
+ posns = (0...(note_pos.size)).to_a
448
+
449
+ tmp = NoteSeqScale.new(name, tment, note_pos, posns, modes)
450
+ self.const_set(const_name, tmp)
451
+ ret = self.const_get(const_name)
452
+
453
+ self.const_get(scale_array).const_set(const_name,ret)
454
+
455
+ ret
456
+ end
457
+
458
+ def self.undef_scale( const_name, scale_array: :ScaleArray )
459
+ self.const_get(scale_array).send(:remove_const, const_name)
460
+ self.send(:remove_const, const_name)
461
+ end
462
+
463
+ def self.scales( scale_array: :ScaleArray )
464
+ self.const_get(scale_array).constants
465
+ end
396
466
 
397
467
  end
398
468
 
@@ -401,23 +471,51 @@ end
401
471
  #
402
472
  #
403
473
  module MusicSetTheory
404
- MajorScale = NoteSeqScale.new("Major", WestTemp,
405
- CHROM_NAT_NOTE_POS, HEPT_NAT_POSNS, MAJORMODES)
406
-
407
- MelMinorScale = NoteSeqScale.new("Melodic Minor", WestTemp,
408
- MEL_MIN_NOTE_POS, HEPT_NAT_POSNS, MELMINORMODES)
409
-
410
- HarmMinorScale = NoteSeqScale.new("Harmonic Minor", WestTemp,
411
- HARM_MIN_NOTE_POS, HEPT_NAT_POSNS, HARMINORMODES)
412
-
413
- HarmMajorScale = NoteSeqScale.new("Harmonic Major", WestTemp,
414
- HARM_MAJ_NOTE_POS, HEPT_NAT_POSNS, HARMMAJORMODES)
415
-
416
- DiscMinorScale = NoteSeqScale.new("Discordant Minor", WestTemp,
417
- DISC_MIN_NOTE_POS, HEPT_NAT_POSNS, DISCORDMINMODES)
474
+ #ScaleArray = []
475
+ module ScaleArray; end
476
+
477
+ #MajorScale = NoteSeqScale.new("Major", WestTemp,
478
+ # CHROM_NAT_NOTE_POS, HEPT_NAT_POSNS, MAJORMODES)
479
+ #MelMinorScale = NoteSeqScale.new("Melodic Minor", WestTemp,
480
+ # MEL_MIN_NOTE_POS, HEPT_NAT_POSNS, MELMINORMODES)
481
+ #HarmMinorScale = NoteSeqScale.new("Harmonic Minor", WestTemp,
482
+ # HARM_MIN_NOTE_POS, HEPT_NAT_POSNS, HARMINORMODES)
483
+ #HarmMajorScale = NoteSeqScale.new("Harmonic Major", WestTemp,
484
+ # HARM_MAJ_NOTE_POS, HEPT_NAT_POSNS, HARMMAJORMODES)
485
+ #DiscMinorScale = NoteSeqScale.new("Discordant Minor", WestTemp,
486
+ # DISC_MIN_NOTE_POS, HEPT_NAT_POSNS, DISCORDMINMODES)
487
+ #HungarianScale = NoteSeqScale.new("Hungarian", WestTemp,
488
+ # HUNGARIAN_NOTE_POS, HEPT_NAT_POSNS, HUNGARIANMODES)
489
+ def_scale :MajorScale, name: "Major", tment: WestTemp,
490
+ note_pos: CHROM_NAT_NOTE_POS, modes: MAJOR_MODES
491
+
492
+ def_scale :MelMinorScale, name: "Melodic Minor", tment: WestTemp,
493
+ note_pos: MEL_MIN_NOTE_POS, modes: MEL_MINOR_MODES
494
+
495
+ def_scale :HarmMinorScale, name: "Harmonic Minor", tment: WestTemp,
496
+ note_pos: HARM_MIN_NOTE_POS, modes: HARM_MINOR_MODES
497
+
498
+ def_scale :HarmMajorScale, name: "Harmonic Major", tment: WestTemp,
499
+ note_pos: HARM_MAJ_NOTE_POS, modes: HARM_MAJOR_MODES
500
+
501
+ def_scale :DiscMinorScale, name: "Discordant Minor", tment: WestTemp,
502
+ note_pos: DISC_MIN_NOTE_POS, modes: DISCORD_MIN_MODES
503
+
504
+ def_scale :HungarianScale, name: "Hungarian", tment: WestTemp,
505
+ note_pos: HUNGARIAN_NOTE_POS, modes: HUNGARIAN_MODES
506
+
507
+ # Pentatonic scales.
508
+ def_scale :MajorPentaScale, name: "Major Pentatonic", tment: WestTemp,
509
+ note_pos: MAJOR_PENTA_NOTE_POS
510
+ def_scale :MinorPentaScale, name: "Minor Pentatonic", tment: WestTemp,
511
+ note_pos: MINOR_PENTA_NOTE_POS
512
+ def_scale :RyukyuPentaScale, name: "Ryukyu Pentatonic", tment: WestTemp,
513
+ note_pos: RYUKYU_PENTA_NOTE_POS
514
+
515
+ # Hexatonic scales.
516
+ def_scale :BluesHexaScale, name: "Blues", tment: WestTemp,
517
+ note_pos: BLUES_HEXA_NOTE_POS
418
518
 
419
- HungarianScale = NoteSeqScale.new("Hungarian", WestTemp,
420
- HUNGARIAN_NOTE_POS, HEPT_NAT_POSNS, HUNGARIANMODES)
421
519
  end
422
520
 
423
521
 
@@ -760,8 +760,14 @@ end
760
760
  module MusicSetTheory
761
761
  module Temperament
762
762
 
763
+ #
764
+ # CHROM_SIZE:: number of semitones.
765
+ # CHROM_NAT_NOTE_POS:: position in number of semitones.
766
+ # ex. D = 2 (i.e., C + #*2), E = 4 (C + #*4), etc.
767
+ # CHROM_NAT_NOTES:: natural notes.
768
+ #
763
769
  CHROM_NAT_NOTES = ["C", "D", "E", "F", "G", "A", "B"]
764
- CHROM_NAT_NOTE_POS = [0, 2, 4, 5, 7, 9, 11]
770
+ CHROM_NAT_NOTE_POS = [ 0, 2, 4, 5, 7, 9, 11]
765
771
  CHROM_SIZE = 12
766
772
  def self.WestTempNew
767
773
  Temperament.new(CHROM_SIZE, CHROM_NAT_NOTES, CHROM_NAT_NOTE_POS)
@@ -772,9 +778,13 @@ module MusicSetTheory
772
778
 
773
779
  #WestTemp = deep_freeze(WestTempNew()) # the last failed in chords_test(1).
774
780
  #WestTemp = WestTempNew() # the last failed in chords_test(1).
775
- WestTemp = MusicSetTheory.deep_freeze(WestTempNew())
776
781
  #ng. WestTemp.deep_freeze
777
782
 
783
+ ### freeze for debug.
784
+ # WestTemp = MusicSetTheory.deep_freeze(WestTempNew())
785
+ WestTemp = WestTempNew() # ok. (dependancied removed in test cases).
786
+ WestTment = WestTemp # alias.
787
+
778
788
  end
779
789
  end
780
790
 
@@ -4,7 +4,7 @@
4
4
  #
5
5
 
6
6
  module MusicSetTheory
7
- VERSION = "0.0.2"
7
+ VERSION = "0.0.4"
8
8
  end
9
9
 
10
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: music_set_theory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - YAMAMOTO, Masayuki
@@ -23,6 +23,20 @@ dependencies:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
25
  version: '0.2'
26
+ - !ruby/object:Gem::Dependency
27
+ name: ice_nine
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '0.11'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.11'
26
40
  description: A music theory library based on Python's `musictheory` package.
27
41
  email:
28
42
  - mephistobooks@users.noreply.github.com