Top Level Namespace

Defined Under Namespace

Modules: TabLab

Constant Summary collapse

COMMANDS =
{
  tuning: "t",
  time_signature: "s",
  new_measure: "m",
  new_note: " ",
  quit: "q"
}.freeze
HELP_STRING =
"Press a number 1-6 to select a string to enter a fret number. Press #{COMMANDS[:new_measure]} to start a new measure. Press #{COMMANDS[:quit]} to quit."
TUNING =
"EADGBe"
N_STRINGS =
6
NEW_MEASURE =
"-+\n" * N_STRINGS

Instance Method Summary collapse

Instance Method Details

#cat_tab(x, y) ⇒ Object

Concatenates x and y



8
9
10
11
12
13
14
15
# File 'lib/tablab/formatting.rb', line 8

def cat_tab(x, y)
  result = ""
  x.lines.count.times do |i|
    line = x.lines[i].gsub("\n", "") + (y.lines[i] or "")
    result += line
  end
  result
end

#clearObject



13
14
15
# File 'lib/tablab/input.rb', line 13

def clear
  system("clear") || system("cls")
end

#format_headingObject



25
26
27
# File 'lib/tablab/formatting.rb', line 25

def format_heading
  cat_tab format_tuning, ("|\n" * N_STRINGS)
end

#format_new_note(string, note) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/tablab/formatting.rb', line 31

def format_new_note(string, note)
  result = ""
  N_STRINGS.times do |i|
    result += if N_STRINGS - i == string
                "-#{note}\n"
              else
                "#{"-" * (note.length + 1)}\n" # +1 for padding
              end
  end
  result
end

#format_tuningObject



17
18
19
20
21
22
23
# File 'lib/tablab/formatting.rb', line 17

def format_tuning
  result = ""
  TUNING.split("").reverse.each_with_index do |x, i|
    result += "#{N_STRINGS - i} #{x} \n"
  end
  result
end

#get_charObject



17
18
19
20
21
22
23
# File 'lib/tablab/input.rb', line 17

def get_char
  state = `stty -g`
  `stty raw -echo -icanon isig`
  $stdin.getc.chr
ensure
  `stty #{state}`
end

#handle_string_inputObject



25
26
27
28
# File 'lib/tablab/input.rb', line 25

def handle_string_input
  print "Fret number: "
  gets.chomp
end