Class: Musiki::Makam

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(m, up = true, down = true) ⇒ Makam

Returns a new instance of Makam.



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/musiki.rb', line 209

def initialize m, up = true, down = true
  GC.start
  m = m.name if m.is_a?(Note)
  m = NOTES[m][:name] if m.is_a?(Integer)
  if MAKAM.has_key?(m.tr_to_ascii.downcase.gsub(/\W/,""))
    g = MAKAM[m.tr_to_ascii.downcase.gsub(/\W/,"")]
  elsif MAKAM_ALIAS.has_key?(m.tr_to_ascii.downcase.gsub(/\W/,""))
    g = MAKAM[MAKAM_ALIAS[m.tr_to_ascii.downcase.gsub(/\W/,"")]]
  elsif g = (MAKAM.map{|i,j| j[:code] == m ? j : nil}-[nil])[0]
  elsif m.scan(/\w\d/).length > 1
    g = {:name=>"Sallama",:code=>m}
  end
  return unless g
  if up and down
    self.setup(g)
    @up = self
    @down = Makam.new(m, false, true)
  elsif up
    self.setup(g)
    @up = self
    @down = nil
  elsif down
    self.setdown(g)
    @up = nil
    @down = self
  end
end

Instance Attribute Details

#dominantObject (readonly)

Returns the value of attribute dominant.



207
208
209
# File 'lib/musiki.rb', line 207

def dominant
  @dominant
end

#interval_symbolsObject (readonly)

Returns the value of attribute interval_symbols.



207
208
209
# File 'lib/musiki.rb', line 207

def interval_symbols
  @interval_symbols
end

#intervalsObject (readonly)

Returns the value of attribute intervals.



207
208
209
# File 'lib/musiki.rb', line 207

def intervals
  @intervals
end

#nameObject (readonly)

Returns the value of attribute name.



207
208
209
# File 'lib/musiki.rb', line 207

def name
  @name
end

#note_namesObject (readonly)

Returns the value of attribute note_names.



207
208
209
# File 'lib/musiki.rb', line 207

def note_names
  @note_names
end

#notesObject (readonly)

Returns the value of attribute notes.



207
208
209
# File 'lib/musiki.rb', line 207

def notes
  @notes
end

#subdominantObject (readonly)

Returns the value of attribute subdominant.



207
208
209
# File 'lib/musiki.rb', line 207

def subdominant
  @subdominant
end

#tonicObject (readonly)

Returns the value of attribute tonic.



207
208
209
# File 'lib/musiki.rb', line 207

def tonic
  @tonic
end

Instance Method Details

#[](key) ⇒ Object



240
241
242
# File 'lib/musiki.rb', line 240

def []key
  @notes[key]
end

#downObject



247
248
249
# File 'lib/musiki.rb', line 247

def down
  @down
end

#inspectObject



237
238
239
# File 'lib/musiki.rb', line 237

def inspect
  @name ? "#{@name} makamı".tr_capitalize : nil
end

#sample(dur = 500) ⇒ Object



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/musiki.rb', line 251

def sample dur=500
  # TODO seems there's an error with the frequencies, doesn't sound right.
  puts "#{self.inspect}:" if self.up or self.down
  if self.up
    print "> "
    self.up.notes.each_with_index do |note,index|
      print "#{index == 0 ? note.name.tr_capitalize : note.name}#{index < self.notes.length - 1 ? ", " : "."}"
      `chuck --bufsize64 ../misc/makam.ck:#{Musiki::base}:#{dur}:#{note.order} 2>&1 >/dev/null`
    end
    puts
  end
  if self.down
    print "< "
    self.down.notes.each_with_index do |note,index|
      print "#{index == 0 ? note.name.tr_capitalize : note.name}#{index < self.down.notes.length - 1 ? ", " : "."}"
      `chuck --bufsize64 ../misc/makam.ck:#{Musiki::base}:#{dur}:#{note.order} 2>&1 >/dev/null`
    end
    puts
  end
end

#setdown(g) ⇒ Object



310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/musiki.rb', line 310

def setdown g
  @name = "inici #{g[:name]}"
  m = g[:code].scan(/\w\d/)
  n = m.index{|i| i=~/[A-Z]\w/} || 0
  n = 0
  m.map!(&:downcase)
  q = m.map {|i| MODE[i[1].to_i][i[0].to_sym] }
  @interval_symbols = q.map {|i| i[:interval].split("") }.flatten.reverse
  @intervals = @interval_symbols.map{|i| INTERVAL[i.to_sym][:value] * -1}
  @tonic = q[n][:tonic]+24
  a = NOTES.map{|i|i[:interval]}
  u = a[0..@tonic].reverse.map{|i| i * -1}
  dd = @tonic
  @notes = [dd]
  #p [0, u[0], NOTES[dd][:name]]
  #puts
  @intervals.each do |int|
    while true
      int -= u.shift
      dd -= 1
      #p [int, u[0], NOTES[dd][:name]]
      if int == 0
        break
      elsif int > 0
        dd += 1
        break
      end
    end
    #puts
    @notes << dd
  end
  @notes.map!{|i| Note.new(i)}
  @note_names = @notes.map {|i| i.name.tr_capitalize}
end

#setup(g) ⇒ Object



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/musiki.rb', line 272

def setup g
  @name = g[:name]
  m = g[:code].scan(/\w\d/)
  n = m.index{|i| i=~/[A-Z]\w/} || 0
  n = 0
  m.map!(&:downcase)
  q = m.map {|i| MODE[i[1].to_i][i[0].to_sym] }
  @interval_symbols = q.map {|i| i[:interval].split("") }.flatten
  @intervals = @interval_symbols.map{|i| INTERVAL[i.to_sym][:value]}
  @tonic = q[n][:tonic]
  a = NOTES.map{|i|i[:interval]}
  u = a[@tonic..-1]
  dd = @tonic
  @notes = [dd]
  p [0, u[0], NOTES[dd][:name], NOTES[dd][:comma], dd] if Musiki.verbose?
  puts if Musiki.verbose?
  @intervals.each do |int|
    while true
      puts "\e[39m#{[int, u[0], NOTES[dd][:name], NOTES[dd][:comma], dd]}" if Musiki.verbose?
      int -= u.shift
      dd += 1
      if int == 0
        puts "\e[32m#{[int, u[0], NOTES[dd][:name], NOTES[dd][:comma], dd]}" if Musiki.verbose?
        puts if Musiki.verbose?
        break
      elsif int < 0
        dd -= 1
        puts "\e[31m#{[int, u[0], "< #{NOTES[dd][:name]}", NOTES[dd][:comma], dd]}" if Musiki.verbose?
        puts if Musiki.verbose?
        break
      end
    end
    @notes << dd
  end
  @notes.map!{|i| Note.new(i, @notes[0])}
  @note_names = @notes.map {|i| i.name.tr_capitalize}
end

#upObject



243
244
245
# File 'lib/musiki.rb', line 243

def up
  @up
end