Class: MiltonsMachine::Core::Tuning

Inherits:
Object
  • Object
show all
Defined in:
lib/miltons_machine/core/tuning.rb

Overview

Note:

tunings can either be specified directly with this class, or can be loaded from an external file.

Class: Tuning

This class provides methods and services to load and manipulate temperaments both as alternatives to 12 tone equal temperaments scales and micro-tonality.

If loaded from an external file, the file must be in a "Scala" format. For a complete detail on this specification @see www.huygens-fokker.org/scala/

The site also provides over 4,000 alternative tuning files available for download. Here is a list:

You can download them @see www.huygens-fokker.org/docs/scales.zip

and then unzip them ()using the -a parameter if you have a mac)

Examples:

OSX

unzip -aa scales.zip

See Also:

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Tuning) initialize(file_path = '', cents = [], description = '')

A new instance of Tuning



40
41
42
43
44
45
# File 'lib/miltons_machine/core/tuning.rb', line 40

def initialize( file_path = '', cents = [], description = '' )
    @cents       = cents
    @file_path   = file_path
    @description = description
    load(file_path) unless file_path.eql? ''
end

Instance Attribute Details

- (Object) cents

Represents the tuning ratios (as cents) that we need to construct a scale or series.



30
31
32
# File 'lib/miltons_machine/core/tuning.rb', line 30

def cents
  @cents
end

- (Object) description

The description of the ratios



34
35
36
# File 'lib/miltons_machine/core/tuning.rb', line 34

def description
  @description
end

- (Object) file_path

The path and name of the file to load



38
39
40
# File 'lib/miltons_machine/core/tuning.rb', line 38

def file_path
  @file_path
end

Instance Method Details

- (Object) load(file_path)

This method will load a file of ratios that represent a specific tuning

Parameters:

  • file_path (String)

    the directory path and name of the file to load



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/miltons_machine/core/tuning.rb', line 52

def load( file_path )
  description_found = false
  length_found      = 0
  number_of_ratios  = 0

  @file_path = file_path
  file = File.new( file_path, 'r')
  file.each_line("\n") do |row|

    # cleanse and prepare

    row.lstrip!
    row.rstrip!
    row.squeeze!(' ')
    next if row[0] == '!'           # ignore comments

    unless description_found        # description is the first non commented line
      @description = row
      description_found = true
      next
    end

    unless number_of_ratios > 0      # total ratios comes next after description is found
      number_of_ratios = row.to_i
      next
    end

    # Cents or fraction then process

    tokens = row.split(' ')
    if tokens[0].include?('.')        # cents
      @cents << tokens[0].to_f
    elsif tokens[0].include?('/')     # if fraction then convert to cents
      parts = tokens[0].split('/')
      # cents <== log(n/d) * (1200/log(2))
      @cents << Math.log10( (parts[0].to_f / parts[1].to_f) ) * MiltonsMachine::Core::Constants::CENTS_CONVERSION
    end
  end

end