Module: Tonal::IRBHelpers

Defined in:
lib/tonal/irb_helpers.rb

Instance Method Summary collapse

Instance Method Details

#er(**kwargs) ⇒ Tonal::ExtendedRatio

Returns an extended ratio.

Examples:

er(partials: [4,5,6]) => Tonal::ExtendedRatio with partials 4,5,6

Returns:



43
44
45
# File 'lib/tonal/irb_helpers.rb', line 43

def er(**kwargs)
  Tonal::ExtendedRatio.new(**kwargs)
end

#i(*args, reduced: true) ⇒ Tonal::Interval

Returns the interval between the given args.

Examples:

i(3,2) => 3/2 (3/2 / 1/1)
i(3,2,4,3) => 9/8 (3/2 / 4/3)
i(3) => 3/2 (3/2 / 1/1)

Parameters:

  • args

    two arguments representing ratios or four arguments representing two pairs of numerator/denominator

  • reduced (defaults to: true)

    boolean determining whether to use Tonal::ReducedRatio or Tonal::Ratio

Returns:



35
36
37
# File 'lib/tonal/irb_helpers.rb', line 35

def i(*args, reduced: true)
  Tonal::Interval.new(*args, reduced:)
end

#r(*args) ⇒ Tonal::Ratio

Returns an unreduced ratio.

Examples:

r(3,3) => 3/3
r.ed(12,2) => 1.12

Parameters:

  • args

    the ratio if only argument provided, or the numerator and denominator if two arguments are provided

Returns:



10
11
12
# File 'lib/tonal/irb_helpers.rb', line 10

def r(*args)
  args.empty? ? Tonal::Ratio : Tonal::Ratio.new(*args)
end

#rr(*args) ⇒ Tonal::ReducedRatio

Returns a reduced ratio.

Examples:

rr(3,3) => 1/1
rr.ed(12,2) => 1.12

Parameters:

  • args

    the ratio if only argument provided, or the numerator and denominator if two arguments are provided

Returns:



21
22
23
# File 'lib/tonal/irb_helpers.rb', line 21

def rr(*args)
  args.empty? ? Tonal::ReducedRatio : Tonal::ReducedRatio.new(*args)
end

#ser(**kwargs) ⇒ Tonal::SubharmonicExtendedRatio

Returns a subharmonic extended ratio.

Examples:

ser(partials: [4,5,6]) => Tonal::SubharmonicExtendedRatio with partials 4,5,6

Returns:



51
52
53
# File 'lib/tonal/irb_helpers.rb', line 51

def ser(**kwargs)
  Tonal::SubharmonicExtendedRatio.new(**kwargs)
end