Top Level Namespace

Defined Under Namespace

Classes: Api, App, Array, AudioOutput, Composer, Dist, Fader, FileList, Float, HitSq, Integer, Logger, Mapper, MathUtils, Mixer, Note, Object, Snd, SndDist, TestDists, TestHitSq, TestNotes, TestTones, Tone, TonePart, ToneSeq, Wave, WaveData

Instance Method Summary collapse

Instance Method Details

#bar(i = 1) ⇒ Object

return the frames in i bars. used for setting lengths when they are needed in frames.



89
90
91
92
# File 'lib/api/api.rb', line 89

def bar i=1
  z=Composer.beat i*4
  z.to_i
end

#beat(i = 1) ⇒ Object

return the frames in i beats. used for setting lengths when they are needed in frames.



84
85
86
87
# File 'lib/api/api.rb', line 84

def beat i=1
  z=Composer.beat i
  z.to_i
end

#bpmObject

return the current beats per minute.



111
112
113
# File 'lib/api/api.rb', line 111

def bpm
  Composer.bpm
end

#chord_notes(note, name = "dim7") ⇒ Object

outputs the midi notes of the chord in an array

note

midi value of root note in chord. range: 0 to 11

name

anything from Composer.chords



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/api/api.rb', line 134

def chord_notes(note, name = "dim7")
  set=[]
  out=[]
  all=Composer.chords
  # handle all selected
  if name=="all"
    all.keys.each { |val| out.push chord_notes(note, val) }
  else #normal
    set = all[name]
    raise "Unknown scale name" if set.nil?
    out = [note] # always root
    set.each do |val|
      out.push note+val
    end
  end

  out
end

#clearObject

clear already rendered files. usually you will want to do this at the start of the program or temp files created from the last use will overlap the current ones when you run #make.



102
103
104
# File 'lib/api/api.rb', line 102

def clear
  App.clear_ready
end

#computeObject

shortcut for #render #save_state #make



115
116
117
118
119
# File 'lib/api/api.rb', line 115

def compute
  render
  save_state
  make
end

#get_chordsObject

return an Array of chords (each chord is an Array of Integer notes) that fit each note consecutively in Composer#scale. The chord is randomly sampled from those availiable.



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/api/api.rb', line 191

def get_chords
  out = []
  notes = scale_notes
  notes.count.times do |i|
    begin
        chord = scale_chord(i).sample #rand
      if chord == []
        out << [notes[i]]
      else
        out << chord_notes(notes[i], chord)
      end

    rescue Exception
      out << [notes[i]]
    end
  end
  out
end

#load_state(file = nil) ⇒ Object

load program state from a saved file.



59
60
61
62
63
64
65
66
# File 'lib/api/api.rb', line 59

def load_state file=nil
  file=App.outpath + "save.rb" if file.nil?
  f=File.open(file,'r')
  content=f.read
  # puts content
  App.out= YAML.load(content)
  f.close
end

#log(str, level = 3) ⇒ Object

level

it won’t be logged unless Logger.level is at or above this level.



122
123
124
# File 'lib/api/api.rb', line 122

def log str, level=3
  App.logger.log str, level
end

#log_level(set) ⇒ Object

set Logger.level. Higher means more logging. 0 is silent.



126
127
128
# File 'lib/api/api.rb', line 126

def log_level set
  App.logger.level = set
end

#makeObject

make an audio file based off generated data.



79
80
81
# File 'lib/api/api.rb', line 79

def make
  App.out.make_audio_file
end

#music(times = 1) ⇒ Object

the main function. output the code block to numbered files.

times

number of times to run the block into a new file



239
240
241
242
243
244
245
246
247
# File 'lib/api/api.rb', line 239

def music times=1
  times.times do |i|
    clear
    yield 
    render
    App.out.outfile= "#{App.outpath}#{App::OUT_SND_DIR}#{i+1}#{App::EXT}"
    make
  end
end

#note_index(note) ⇒ Object

returns how far the given note (Integer) is into the scale.



211
212
213
# File 'lib/api/api.rb', line 211

def note_index(note)
   scale_notes.index(note)
end

#queue(dist) ⇒ Object

add a Dist to the queue of things to be rendered when you call render. see #render.



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

def queue dist
  App.out.snddists<<dist.instance_variable_get(:@dist)
end

#rand_range(max, min = 0, weight = 1) ⇒ Object

return random Integer in range with min and max



230
231
232
233
234
# File 'lib/api/api.rb', line 230

def rand_range max, min=0, weight =1
  rand_p = max - min
  weight.times {rand_p *= rand}
  min + rand_p
end

#rand_scaleObject

random scale



184
185
186
# File 'lib/api/api.rb', line 184

def rand_scale
  Composer.scales.keys.sample # allow for random.
end

#renderObject

generate the audio data for everything in the queue. see #queue method.



74
75
76
# File 'lib/api/api.rb', line 74

def render
  App.out.render
end

#save_state(file = nil) ⇒ Object

save program state to a file.



69
70
71
# File 'lib/api/api.rb', line 69

def save_state file=nil
  App.out.write_text_files file
end

#scale_chord(i = 0) ⇒ Object

return an Array of String of chords that could be the i number chord for notes in the Composer#scale.

scale

anything from Composer.scales.



177
178
179
180
181
# File 'lib/api/api.rb', line 177

def scale_chord(i=0)
  notes = scale_notes
  raise "#{i} is out of range for that scale, it only has #{notes.count} notes." if notes[i].nil?
  Composer.matching_chords(notes[i])
end

#scale_notes(note = 0, is_all = false) ⇒ Object

return array of notes in the Composer#scale

note

midi value of root note. range: 0 to 11

name

anything from Composer.scales.



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/api/api.rb', line 156

def scale_notes(note=0,is_all=false)
  set=[]
  out=[]
  all=Composer.scales
  # handle all selected
  if is_all
    all.keys.each { |val| out.push scale_notes(val,note) }
  else #normal
    set = all[Composer.scale]
    raise "Unknown scale name" if set.nil?
    out = [note] # always root
    # add set to out
    set.each do |val|
      out.push note+ val
    end
  end
  out
end

#set_bpm(val) ⇒ Object

set the beats per minute of all following commands. now helper methods like #beat will be usefull.



107
108
109
# File 'lib/api/api.rb', line 107

def set_bpm val
  Composer.bpm = val
end

#set_scale(sc) ⇒ Object

sets Composer#scale



215
216
217
# File 'lib/api/api.rb', line 215

def set_scale sc
   Composer.scale = sc
end

#startObject

the typical series of commands at the start of a simple new music coder file.



219
220
221
222
223
# File 'lib/api/api.rb', line 219

def start
  log_level 1
  clear
  set_bpm 128
end