Class: StepSequencer::REPL::Helpers

Inherits:
Object
  • Object
show all
Defined in:
lib/step_sequencer/repl.rb

Constant Summary collapse

HelpSections =
{
  download: "
    Usage: download #{"\"<youtube url>\"".blue}, #{"\"<out dir>\"".blue} #{"\"<filename>\"".blue}
    - requires youtube-dl program to be installed on computer
    - e.g. download 'http://youtube.com/asd', '~/Desktop', 'foo.mp3'
  ",
  play: "
    Usage: play #{"\"<path>\"".blue}
    - plays the file in its own thread using mpg123
    - hides the output
  ",
  combine: "
    Usage: combine #{"\"[<paths>]\"".blue}
    - note that this combines them sequentially.
      for concurrent playback, use overlay
    - returns a single path.
  ",
  gain: "
    Usage: gain #{"\"<path>\"".blue}, #{"<value>".blue}
    - <value> is a float, e.g. 0.5 for half and 2.0 for double
    - returns a single path
  ",
  loop: "
    Usage: loop #{"\"<path>\"".blue}, #{"<num_times>".blue}
    - <num_times> can be a int or a float. if it's a float, then the last
      loop will include only part of the original sample.
    - returns a single path

  ",
  overlay: "
    Usage: overlay #{"\"[<paths>]\"".blue}
    - combines files so they play on top of one another
    - returns a single path
  ",
  pitch: "
    Usage: pitch #{"\"<path>\"".blue}, #{"<value>".blue}, #{"<speed_correct>".blue}
    - <value> here is a integer/float, e.g. 0.5 for half and 2.0 for double.
    - <speed_correct> defaults to true. It will prevent the pitch shift from
      changing the speed.
    - returns a single path
  ",
  scale: "
    Usage: scale #{"\"<path>\"".blue}, #{"<inverse>".blue}
    - This will generate 12 notes of the equal temperament tuning
    - <inverse> defaults to false. If true then the generated notes will
      be downtuned from the original (descending).
  ",
  slice: "
    Usage: slice #{"\"<path>\"".blue} #{"<start>".blue} #{"<end>".blue}
    - <start> and <end> are floats referring to a number of seconds.
      Providing values of 2.0 and 3.5 would create a 1.5 second slice
    - returns a single path
  ",
  speed: "
    Usage: speed #{"\"<path>\"".blue} #{"<value>".blue}
    - <value> is a integer/float, e.g. 0.5 for half and 2.0 for double
    - returns a single path
  "
}

Instance Method Summary collapse

Instance Method Details

#builderObject



96
97
98
# File 'lib/step_sequencer/repl.rb', line 96

def builder
  StepSequencer::SoundBuilder
end

#combine(paths) ⇒ Object



108
109
110
111
112
# File 'lib/step_sequencer/repl.rb', line 108

def combine(paths)
  builder.build(
    sources: paths, effect: :Combine
  )
end

#docs(section = nil) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/step_sequencer/repl.rb', line 75

def docs(section=nil)
  section = section.to_sym if section
  if section && (doc = self.class::HelpSections[section])
    puts HelpSections[section]
  elsif section
    puts "
      docs section #{section} not found.
      Enter #{"docs".blue} to see a list of sections
    ".red
  else
    puts "
      StepSequencer
      #{"================"}

      Usage: docs #{"\"command\"".blue}
      where #{"command".blue} is one of:
      #{self.class::HelpSections.keys.join(", ")}
    "
  end
end

#download(url, outpath, filename) ⇒ Object



104
105
106
# File 'lib/step_sequencer/repl.rb', line 104

def download(url, outpath, filename)
  YoutubeAudioDownloader.download_audio url, outpath, filename
end

#gain(path, val) ⇒ Object



114
115
116
117
118
# File 'lib/step_sequencer/repl.rb', line 114

def gain(path, val)
  builder.build(
    sources: [path], effect: :Gain, args: [value: val]
  )[0]
end

#loop(path, times) ⇒ Object



120
121
122
123
124
# File 'lib/step_sequencer/repl.rb', line 120

def loop(path, times)
  builder.build(
    sources: [path], effect: :Loop, args: [times: val]
  )[0]
end

#overlay(paths) ⇒ Object



126
127
128
129
130
# File 'lib/step_sequencer/repl.rb', line 126

def overlay(paths)
  builder.build(
    sources: paths, effect: :Overlay
  )
end

#pitch(path, val, speed_correct = true) ⇒ Object



132
133
134
135
136
137
# File 'lib/step_sequencer/repl.rb', line 132

def pitch(path, val, speed_correct=true)
  builder.build(
    sources: [path], effect: :Pitch,
    args: [{value: val, speed_correction: speed_correct}]
  )[0]
end

#play(path) ⇒ Object



160
161
162
# File 'lib/step_sequencer/repl.rb', line 160

def play(path)
  Thread.new { `mpg123 #{path} 2> /dev/null` }
end

#playerObject



100
101
102
# File 'lib/step_sequencer/repl.rb', line 100

def player
  StepSequencer::SoundPlayer
end

#scale(path, inverse) ⇒ Object



139
140
141
142
143
144
# File 'lib/step_sequencer/repl.rb', line 139

def scale(path, inverse)
  builder.build(
    sources: [path], effect: :Scale,
    args: [{scale: :equal_temperament, inverse: inverse}]
  )[0]
end

#slice(path, start_time, end_time) ⇒ Object



146
147
148
149
150
151
# File 'lib/step_sequencer/repl.rb', line 146

def slice(path, start_time, end_time)
  builder.build(
    sources: [path], effect: :Slice,
    args: [{start_time: start_time, end_time: end_time}]
  )[0]
end

#speed(path, val) ⇒ Object



153
154
155
156
157
158
# File 'lib/step_sequencer/repl.rb', line 153

def speed(path, val)
  builder.build(
    sources: [path], effect: :Speed,
    args: [{value: val}]
  )[0]
end