Class: StepSequencer::REPL::Helpers

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

Constant Summary collapse

HelpSections =
{
  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



91
92
93
# File 'lib/step_sequencer/repl.rb', line 91

def builder
  StepSequencer::SoundBuilder
end

#combine(paths) ⇒ Object



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

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

#docs(section = nil) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/step_sequencer/repl.rb', line 70

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

#gain(path, val) ⇒ Object



105
106
107
108
109
# File 'lib/step_sequencer/repl.rb', line 105

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

#loop(path, times) ⇒ Object



111
112
113
114
115
# File 'lib/step_sequencer/repl.rb', line 111

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

#overlay(paths) ⇒ Object



117
118
119
120
121
# File 'lib/step_sequencer/repl.rb', line 117

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

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



123
124
125
126
127
128
# File 'lib/step_sequencer/repl.rb', line 123

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

#play(path) ⇒ Object



151
152
153
# File 'lib/step_sequencer/repl.rb', line 151

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

#playerObject



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

def player
  StepSequencer::Player
end

#scale(path, inverse) ⇒ Object



130
131
132
133
134
135
# File 'lib/step_sequencer/repl.rb', line 130

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



137
138
139
140
141
142
# File 'lib/step_sequencer/repl.rb', line 137

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



144
145
146
147
148
149
# File 'lib/step_sequencer/repl.rb', line 144

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