Class: OutroRails::CagedController

Inherits:
ApplicationController show all
Includes:
InvalidParamsRedirectable, RootSelectable
Defined in:
app/controllers/outro_rails/caged_controller.rb

Defined Under Namespace

Classes: ChordEntry

Constant Summary collapse

DEFAULT_SHAPE =
"c"

Constants included from RootSelectable

RootSelectable::DEFAULT_ROOT

Instance Method Summary collapse

Instance Method Details

#showObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/outro_rails/caged_controller.rb', line 20

def show
  @root = root_from_params
  @letter = permitted!(
    (params[:shape].presence || DEFAULT_SHAPE).to_s.upcase,
    Instruments::Guitar::ChordShapes::CAGED_LETTERS,
    "shape"
  )

  @guitar = Instruments::Guitar.new
  @prefer = @root.accidental_offset.negative? ? :flats : :sharps

  @entries = Instruments::Guitar::ChordShapes
    .chords_for_letter(@letter)
    .map do |quality, extension, shape|
      positions = Instruments::Guitar::ChordShapes.positions(
        shape,
        @root,
        guitar: @guitar
      )

      ChordEntry.new(
        quality: quality,
        extension: extension,
        shape: shape,
        symbol: Theory::ChordVocabulary.symbol(
          root_name: @root,
          quality: quality,
          extension: extension
        ),
        positions: positions,
        root_positions: positions.select do |string, fret|
          @guitar.pitch_class_at(string, fret) == @root.pitch_class
        end
      )
    end
end