coltrane 3.4.2 → 4.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/.ruby-version +1 -0
  4. data/CHANGELOG.md +3 -0
  5. data/Gemfile.lock +15 -4
  6. data/bin/old-coltrane +29 -0
  7. data/coltrane.gemspec +4 -4
  8. data/exe/coltrane +77 -47
  9. data/lib/.DS_Store +0 -0
  10. data/lib/coltrane/.DS_Store +0 -0
  11. data/lib/coltrane/commands.rb +4 -9
  12. data/lib/coltrane/commands/available_chord_representations.rb +9 -0
  13. data/lib/coltrane/commands/available_classic_scales.rb +9 -0
  14. data/lib/coltrane/commands/available_notable_progressions.rb +9 -0
  15. data/lib/coltrane/commands/available_representations.rb +9 -0
  16. data/lib/coltrane/commands/command.rb +3 -54
  17. data/lib/coltrane/commands/find_chord_by_notes.rb +9 -0
  18. data/lib/coltrane/commands/find_common_chords.rb +9 -0
  19. data/lib/coltrane/commands/find_progressions_from_chords.rb +9 -0
  20. data/lib/coltrane/commands/find_scale_by_chords.rb +9 -0
  21. data/lib/coltrane/commands/find_scale_by_notes.rb +9 -0
  22. data/lib/coltrane/commands/get_chords_from_notable_progression.rb +9 -0
  23. data/lib/coltrane/commands/get_chords_from_progression.rb +9 -0
  24. data/lib/coltrane/commands/get_chords_from_scale.rb +9 -0
  25. data/lib/coltrane/commands/get_chords_from_string.rb +11 -0
  26. data/lib/coltrane/commands/get_classic_scale.rb +9 -0
  27. data/lib/coltrane/commands/get_notes.rb +9 -0
  28. data/lib/coltrane/commands/get_notes_from_string.rb +9 -0
  29. data/lib/coltrane/commands/get_representation_chords.rb +18 -0
  30. data/lib/coltrane/commands/get_representation_notes.rb +12 -0
  31. data/lib/coltrane/commands/render.rb +9 -0
  32. data/lib/coltrane/renderers/text_renderer/hash_drawer.rb +1 -0
  33. data/lib/coltrane/renderers/text_renderer/theory_chord_drawer.rb +1 -2
  34. data/lib/coltrane/theory/classic_scales.rb +1 -1
  35. data/lib/coltrane/ui.rb +9 -0
  36. data/lib/coltrane/ui/.DS_Store +0 -0
  37. data/lib/coltrane/ui/router.rb +87 -0
  38. data/lib/coltrane/ui/views.rb +4 -0
  39. data/lib/coltrane/ui/views/chords.rb +19 -0
  40. data/lib/coltrane/ui/views/custom_progression.rb +27 -0
  41. data/lib/coltrane/ui/views/find_chord_by_notes.rb +16 -0
  42. data/lib/coltrane/ui/views/find_chords_in_scale.rb +34 -0
  43. data/lib/coltrane/ui/views/find_common_chords_in_scales.rb +40 -0
  44. data/lib/coltrane/ui/views/find_progressions_from_chords.rb +14 -0
  45. data/lib/coltrane/ui/views/find_scale.rb +14 -0
  46. data/lib/coltrane/ui/views/find_scale_by_chords.rb +16 -0
  47. data/lib/coltrane/ui/views/find_scale_by_notes.rb +16 -0
  48. data/lib/coltrane/ui/views/index.rb +14 -0
  49. data/lib/coltrane/ui/views/notes.rb +20 -0
  50. data/lib/coltrane/ui/views/progressions.rb +18 -0
  51. data/lib/coltrane/ui/views/scales.rb +17 -0
  52. data/lib/coltrane/ui/views/show_chord.rb +21 -0
  53. data/lib/coltrane/ui/views/show_progression.rb +26 -0
  54. data/lib/coltrane/ui/views/show_scale.rb +26 -0
  55. data/lib/coltrane/ui/views/view.rb +47 -0
  56. data/lib/coltrane/version.rb +1 -1
  57. metadata +64 -28
  58. data/lib/coltrane/commands/chords.rb +0 -93
  59. data/lib/coltrane/commands/common_chords.rb +0 -33
  60. data/lib/coltrane/commands/errors.rb +0 -44
  61. data/lib/coltrane/commands/find_guitar_chord.rb +0 -25
  62. data/lib/coltrane/commands/find_progression.rb +0 -28
  63. data/lib/coltrane/commands/find_scale.rb +0 -39
  64. data/lib/coltrane/commands/notes.rb +0 -50
  65. data/lib/coltrane/commands/progression.rb +0 -28
  66. data/lib/coltrane/commands/scale.rb +0 -46
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32946013238830132b204f366ee7b647033bc899d46326634a51a639dcd29dbc
4
- data.tar.gz: b67609e215a09f1e9b2f4a4346e0f0b37f6d89f0cea3b06a4266f838f0e17cdc
3
+ metadata.gz: d2dce8fab34c2d90d0317a80349b7fd3bec643bd0f32c491a351a0251251349b
4
+ data.tar.gz: de1772b25200811627df8937663417db2c9a9ad5f8106e05ba0c6a41f6ccc96d
5
5
  SHA512:
6
- metadata.gz: 19aa9d773da33d5b2adf560071c0d3bd6ab3cb7e936014ff8065cda097b0d6ffb959f15eba5e26ca1bc0de3970fcb76a2e5b03a7ee9b01ff34dfccf9b7241cb8
7
- data.tar.gz: b3f307536e4a287135ace9901c7707cbb94c6138e05eaa7b1799c07e1162fc11eda8f854e06b0530fe9320d8e228e0de2f31072e0d275a7c1d0decc2c968081a
6
+ metadata.gz: 6d0ed0415983d75c7fce264111e014e2c2bb3d2f0ae949c7579743668ea09678e93df6e85c450f66c4543fd13f60c89dd6711bc023cfb08c00a83300228713c5
7
+ data.tar.gz: 45fe81700b815b8762c39ad4d365ccafebfc8d7afa4d5e225f6344f70de713ce23d9d601273ee08a38f59bdb696815d2dd27cfd7920eae9f15f36f6fb3feb9eb
Binary file
@@ -0,0 +1 @@
1
+ 2.5.1
@@ -5,6 +5,9 @@
5
5
  - Fix chords so that they generate a barre and a non-barre version and prevent
6
6
  barre chords from picking notes before the barre.
7
7
 
8
+ ## [4.0.0]
9
+ - Includes totally revamped, easy to use command line interface.
10
+
8
11
  ## [3.4.2]
9
12
  - Fixes guitar strings rendering order (#41)
10
13
 
@@ -1,18 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- coltrane (3.4.2)
4
+ coltrane (4.0.3)
5
+ activesupport (> 5.2)
6
+ cli-ui (~> 1.1)
5
7
  color (~> 1.8)
6
8
  dry-monads (~> 0.4)
7
9
  paint (~> 2.0)
8
- pedrozath-mercenary (= 0.3.8)
9
- tty-reader (~> 0.2)
10
10
 
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
+ activesupport (5.2.1)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 0.7, < 2)
17
+ minitest (~> 5.1)
18
+ tzinfo (~> 1.1)
14
19
  ast (2.4.0)
15
20
  byebug (10.0.2)
21
+ cli-ui (1.1.4)
16
22
  coderay (1.1.2)
17
23
  color (1.8)
18
24
  concurrent-ruby (1.0.5)
@@ -27,8 +33,11 @@ GEM
27
33
  equatable (0.5.0)
28
34
  hike (1.2.3)
29
35
  hitimes (1.2.6)
36
+ i18n (1.1.1)
37
+ concurrent-ruby (~> 1.0)
30
38
  json (2.1.0)
31
39
  method_source (0.9.0)
40
+ minitest (5.11.3)
32
41
  necromancer (0.4.0)
33
42
  opal (0.10.5)
34
43
  hike (~> 1.2)
@@ -44,7 +53,6 @@ GEM
44
53
  pastel (0.7.2)
45
54
  equatable (~> 0.5.0)
46
55
  tty-color (~> 0.4.0)
47
- pedrozath-mercenary (0.3.8)
48
56
  powerpack (0.1.1)
49
57
  pry (0.11.3)
50
58
  coderay (~> 1.1.0)
@@ -85,6 +93,7 @@ GEM
85
93
  sprockets (3.7.1)
86
94
  concurrent-ruby (~> 1.0)
87
95
  rack (> 1, < 3)
96
+ thread_safe (0.3.6)
88
97
  tilt (2.0.8)
89
98
  timers (4.1.2)
90
99
  hitimes
@@ -101,6 +110,8 @@ GEM
101
110
  tty-screen (~> 0.6.4)
102
111
  wisper (~> 2.0.0)
103
112
  tty-screen (0.6.4)
113
+ tzinfo (1.2.5)
114
+ thread_safe (~> 0.1)
104
115
  unicode-display_width (1.3.0)
105
116
  wisper (2.0.0)
106
117
 
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'old-coltrane' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("coltrane", "old-coltrane")
@@ -32,11 +32,11 @@ Gem::Specification.new do |spec|
32
32
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
33
  spec.require_paths = ["lib"]
34
34
 
35
- spec.add_runtime_dependency 'tty-reader', '~> 0.2'
36
35
  spec.add_runtime_dependency 'dry-monads', '~> 0.4'
37
36
  spec.add_runtime_dependency 'paint', '~> 2.0'
38
37
  spec.add_runtime_dependency 'color', '~> 1.8'
39
- spec.add_runtime_dependency 'pedrozath-mercenary', '0.3.8'
40
- spec.add_development_dependency "bundler", '~> 1.14'
41
- spec.add_development_dependency "rake", '~> 10.0'
38
+ spec.add_runtime_dependency 'cli-ui', '~> 1.1'
39
+ spec.add_runtime_dependency 'activesupport', '> 5.2'
40
+ spec.add_development_dependency "bundler", '~> 1.14'
41
+ spec.add_development_dependency "rake", '~> 10.0'
42
42
  end
@@ -1,65 +1,95 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
-
4
3
  $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
5
4
 
6
- require 'paint'
7
- require 'color'
5
+ require 'coltrane/ui'
8
6
 
9
- require 'pedrozath-mercenary'
10
- require 'coltrane/commands'
7
+ module Coltrane
8
+ module UI
9
+ class App
10
+ attr_reader :router
11
11
 
12
- if ENV['COLORTERM'] == 'truecolor'
13
- Paint.mode = 0xFFFFFF
14
- else
15
- Paint.mode = 0
16
- puts "This terminal doesn't seem to support true color. " \
17
- "Try something like iTerm2 (for macOS), VTE or Konsole (for linux) or Hyper" \
18
- " (for Windows) and you'll see the true magic!"
19
- end
12
+ def self.start(initial_route)
13
+ if ENV['COLORTERM'] == 'truecolor'
14
+ Paint.mode = 0xFFFFFF
15
+ else
16
+ Paint.mode = 0
17
+ puts "This terminal doesn't seem to support true color. " \
18
+ "Try something like iTerm2 (for macOS), VTE or Konsole (for linux) or Hyper" \
19
+ " (for Windows) and you'll see the true magic!"
20
+ end
20
21
 
21
- Mercenary.program(:Coltrane) do |p|
22
- p.version Coltrane::VERSION
23
- p.description <<~DESC
24
- A music querying interface
25
- by Pedro Maciel (pedro@pedromaciel.com)
22
+ path, params = initial_route.split(' ').each_with_object([nil, {}]) do |segment, memo|
23
+ if segment =~ /:/
24
+ key, value = segment.split(':')
25
+ memo[1].merge!([[key.to_sym, value.gsub('-', ' ')]].to_h)
26
+ else
27
+ memo[0] = [memo[0], segment].compact.join(' ')
28
+ end
29
+ end
26
30
 
27
- Check the chat room for project help/discussion/contribution: https://coltrane-ruby.herokuapp.com
28
- DESC
29
- p.syntax 'coltrane <subcommand> [options]'
31
+ response = {path: (path || ''), **params}
32
+ loop { response = app.flow(**response) }
33
+ end
30
34
 
31
- Coltrane::Commands::Command.subclasses.each do |command|
32
- command.mercenary_init(p)
33
- end
35
+ def self.app
36
+ @app ||= new
37
+ end
34
38
 
35
- p.command(:about) do |c|
36
- c.description 'Shows this screen'
37
- c.action { puts p }
38
- end
39
+ def initialize
40
+ @router = Router.new
41
+ end
39
42
 
40
- p.command(:shell) do |c|
41
- c.description 'Starts an interactive shell'
42
- c.action do
43
- system File.expand_path('../../bin', __FILE__) + "/coltrane-interactive"
44
- end
45
- end
43
+ def ask_questions(questions)
44
+ questions.map { |name, question| [name, ask_question(question)] }.to_h
45
+ end
46
+
47
+ def ask_question(question)
48
+ CLI::UI::Prompt.ask(question[:statement], options: question[:options])
49
+ end
46
50
 
47
- p.command(:help) do |c|
48
- c.description 'May give you some help.'
49
- c.syntax 'help <command> [subcommand, sub-subcommand, ...]'
50
- c.action do |(*command_path), _options|
51
- if command_path.empty?
52
- puts p
53
- else
54
- puts begin
55
- command_path.reduce(p) do |memo, key|
56
- memo.commands.delete(key.to_sym)
57
- end || "\n Sorry, command found."
51
+ def navigation(params)
52
+ return {} if params.empty?
53
+ CLI::UI::Prompt.ask('What to do now?') do |h|
54
+ params.each do |key, _value|
55
+ h.option("Different #{key}") { params[key] = nil }
56
+ end
57
+ h.option("Go back") { params[:path] = '' }
58
58
  end
59
+ params
60
+ end
61
+
62
+ def output(response)
63
+ return unless response[:content]
64
+ puts [
65
+ nil,
66
+ "-> coltrane #{router.url}",
67
+ nil,
68
+ response[:content],
69
+ nil
70
+ ]
71
+ end
72
+
73
+ def flow(response)
74
+ raise 'Response is empty' unless response
75
+ output(response)
76
+ response.delete(:content)
77
+ questions = response&.delete(:questions) || {}
78
+ response.merge!(navigation(response)) unless response.has_key?(:path) || questions.any?
79
+ response.merge!(ask_questions(questions)) if questions.any?
80
+ exit if response[:path] == 'exit'
81
+ router.get(**response.compact)
82
+ rescue => e
83
+ response.delete(:path)
84
+ puts e
85
+ retry
86
+ end
87
+
88
+ def exit
89
+ Kernel.exit(0)
59
90
  end
60
91
  end
61
92
  end
62
-
63
- p.default_command(:shell)
64
93
  end
65
94
 
95
+ Coltrane::UI::App.start(ARGV.join(' '))
Binary file
Binary file
@@ -3,13 +3,8 @@
3
3
  require 'coltrane'
4
4
  require 'coltrane/representation'
5
5
  require 'coltrane/renderers'
6
-
7
6
  require 'coltrane/commands/command'
8
- require 'coltrane/commands/notes'
9
- require 'coltrane/commands/chords'
10
- require 'coltrane/commands/scale'
11
- require 'coltrane/commands/progression'
12
- require 'coltrane/commands/common_chords'
13
- require 'coltrane/commands/find_scale'
14
- require 'coltrane/commands/find_progression'
15
- require 'coltrane/commands/find_guitar_chord'
7
+
8
+ Dir[File.expand_path('../commands/*', __FILE__)].map do |f|
9
+ require(f)
10
+ end
@@ -0,0 +1,9 @@
1
+ module Coltrane
2
+ module Commands
3
+ class AvailableChordRepresentations < Command
4
+ def run
5
+ return ['GuitarChordChart'] + AvailableRepresentations.run
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Coltrane
2
+ module Commands
3
+ class AvailableClassicScales < Command
4
+ def run
5
+ Theory::Scale.known_scales
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Coltrane
2
+ module Commands
3
+ class AvailableNotableProgressions < Command
4
+ def run
5
+ Theory::NotableProgressions::PROGRESSIONS.keys
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Coltrane
2
+ module Commands
3
+ class AvailableRepresentations < Command
4
+ def run
5
+ ['Text'] + Representation.constants.map(&:to_s)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,61 +1,10 @@
1
1
  module Coltrane
2
2
  module Commands
3
3
  class Command
4
- COMMON_OPTIONS = {
5
- on: [
6
- '--on <INSTRUMENT>',
7
- 'Shows the notes on the given instrument/representation type. ' \
8
- 'Can be text, piano, guitar, ukulele, bass.' \
9
- 'You can also provide a custom guitar using the following format:' \
10
- '--on custom_guitar=D2-A3-D3-B3-C3'
11
- ],
4
+ attr_reader :error
12
5
 
13
- flavor: [
14
- '--flavor <FLAVOR>',
15
- 'Chooses which additional information to display: ' \
16
- 'marks, notes, intervals or degrees'
17
- ],
18
-
19
- voicings: [
20
- '--voicings <NUMBER>',
21
- 'Number of voicings for guitar like instruments. Default is 6' \
22
- 'provided they are separated by dashes'
23
- ]
24
- }
25
-
26
- def custom_guitar
27
- on
28
- .to_s
29
- .split('=')
30
- .fetch(1)
31
- .split('-')
32
- .yield_self { |tuning| Representation::Guitar.new(tuning: tuning) }
33
- end
34
-
35
- def render
36
- puts "\n" + Renderers::TextRenderer.render(
37
- representation, **renderer_options
38
- )
39
- end
40
-
41
- def renderer_options
42
- {}
43
- end
44
-
45
- class << self
46
-
47
- def subclasses
48
- @subclasses ||= []
49
- end
50
-
51
- def inherited(base)
52
- subclasses << base
53
- super(base)
54
- end
55
-
56
- def add_shared_option(option_name, mercenary_command)
57
- mercenary_command.option(option_name, *COMMON_OPTIONS[option_name])
58
- end
6
+ def self.run(*args)
7
+ new.run(*args)
59
8
  end
60
9
  end
61
10
  end
@@ -0,0 +1,9 @@
1
+ module Coltrane
2
+ module Commands
3
+ class FindChordByNotes < Command
4
+ def run(notes)
5
+ Theory::Chord.new(notes: notes)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Coltrane
2
+ module Commands
3
+ class FindCommonChords < Command
4
+ def run(*scales)
5
+ scales.map(&:chords).reduce(&:&)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Coltrane
2
+ module Commands
3
+ class FindProgressionsFromChords < Command
4
+ def run(*chords)
5
+ Theory::Progression.find(*chords)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Coltrane
2
+ module Commands
3
+ class FindScaleByChords < Command
4
+ def run(chords)
5
+ Theory::Scale.having_chords(*chords)
6
+ end
7
+ end
8
+ end
9
+ end