Class: Musiki::Note
- Inherits:
-
Object
- Object
- Musiki::Note
- Defined in:
- lib/musiki.rb
Instance Attribute Summary collapse
-
#absolute_frequency ⇒ Object
readonly
Returns the value of attribute absolute_frequency.
-
#comma ⇒ Object
readonly
Returns the value of attribute comma.
-
#fraction ⇒ Object
readonly
Returns the value of attribute fraction.
-
#frequency ⇒ Object
readonly
Returns the value of attribute frequency.
-
#interval_after ⇒ Object
readonly
Returns the value of attribute interval_after.
-
#interval_after_symbol ⇒ Object
readonly
Returns the value of attribute interval_after_symbol.
-
#interval_before ⇒ Object
readonly
Returns the value of attribute interval_before.
-
#interval_before_symbol ⇒ Object
readonly
Returns the value of attribute interval_before_symbol.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#power2 ⇒ Object
readonly
Returns the value of attribute power2.
-
#power3 ⇒ Object
readonly
Returns the value of attribute power3.
-
#relative_fraction ⇒ Object
readonly
Returns the value of attribute relative_fraction.
-
#relative_frequency ⇒ Object
readonly
Returns the value of attribute relative_frequency.
-
#relative_order ⇒ Object
readonly
Returns the value of attribute relative_order.
-
#relative_power2 ⇒ Object
readonly
Returns the value of attribute relative_power2.
-
#relative_power3 ⇒ Object
readonly
Returns the value of attribute relative_power3.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
Instance Method Summary collapse
- #find_note(n) ⇒ Object
- #fraction_from(n) ⇒ Object
- #fraction_to(n) ⇒ Object
- #freq ⇒ Object
-
#initialize(a = 0, b = 0) ⇒ Note
constructor
A new instance of Note.
- #inspect ⇒ Object
- #int ⇒ Object
- #int_sym ⇒ Object
- #interval ⇒ Object
- #interval_symbol ⇒ Object
- #ratio ⇒ Object
- #rel_freq ⇒ Object
- #setup(m, n) ⇒ Object
- #transpose(o) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(a = 0, b = 0) ⇒ Note
Returns a new instance of Note.
352 353 354 355 356 |
# File 'lib/musiki.rb', line 352 def initialize a=0, b=0 m = find_note a n = find_note b self.setup m, n end |
Instance Attribute Details
#absolute_frequency ⇒ Object (readonly)
Returns the value of attribute absolute_frequency.
349 350 351 |
# File 'lib/musiki.rb', line 349 def absolute_frequency @absolute_frequency end |
#comma ⇒ Object (readonly)
Returns the value of attribute comma.
349 350 351 |
# File 'lib/musiki.rb', line 349 def comma @comma end |
#fraction ⇒ Object (readonly)
Returns the value of attribute fraction.
349 350 351 |
# File 'lib/musiki.rb', line 349 def fraction @fraction end |
#frequency ⇒ Object (readonly)
Returns the value of attribute frequency.
349 350 351 |
# File 'lib/musiki.rb', line 349 def frequency @frequency end |
#interval_after ⇒ Object (readonly)
Returns the value of attribute interval_after.
349 350 351 |
# File 'lib/musiki.rb', line 349 def interval_after @interval_after end |
#interval_after_symbol ⇒ Object (readonly)
Returns the value of attribute interval_after_symbol.
349 350 351 |
# File 'lib/musiki.rb', line 349 def interval_after_symbol @interval_after_symbol end |
#interval_before ⇒ Object (readonly)
Returns the value of attribute interval_before.
349 350 351 |
# File 'lib/musiki.rb', line 349 def interval_before @interval_before end |
#interval_before_symbol ⇒ Object (readonly)
Returns the value of attribute interval_before_symbol.
349 350 351 |
# File 'lib/musiki.rb', line 349 def interval_before_symbol @interval_before_symbol end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
349 350 351 |
# File 'lib/musiki.rb', line 349 def name @name end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
349 350 351 |
# File 'lib/musiki.rb', line 349 def order @order end |
#power2 ⇒ Object (readonly)
Returns the value of attribute power2.
349 350 351 |
# File 'lib/musiki.rb', line 349 def power2 @power2 end |
#power3 ⇒ Object (readonly)
Returns the value of attribute power3.
349 350 351 |
# File 'lib/musiki.rb', line 349 def power3 @power3 end |
#relative_fraction ⇒ Object (readonly)
Returns the value of attribute relative_fraction.
349 350 351 |
# File 'lib/musiki.rb', line 349 def relative_fraction @relative_fraction end |
#relative_frequency ⇒ Object (readonly)
Returns the value of attribute relative_frequency.
349 350 351 |
# File 'lib/musiki.rb', line 349 def relative_frequency @relative_frequency end |
#relative_order ⇒ Object (readonly)
Returns the value of attribute relative_order.
349 350 351 |
# File 'lib/musiki.rb', line 349 def relative_order @relative_order end |
#relative_power2 ⇒ Object (readonly)
Returns the value of attribute relative_power2.
349 350 351 |
# File 'lib/musiki.rb', line 349 def relative_power2 @relative_power2 end |
#relative_power3 ⇒ Object (readonly)
Returns the value of attribute relative_power3.
349 350 351 |
# File 'lib/musiki.rb', line 349 def relative_power3 @relative_power3 end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
349 350 351 |
# File 'lib/musiki.rb', line 349 def role @role end |
Instance Method Details
#find_note(n) ⇒ Object
420 421 422 423 424 425 426 427 428 |
# File 'lib/musiki.rb', line 420 def find_note n if n.to_s.to_i == n NOTES[n % 48] elsif n.class == Musiki::Note NOTES[n.order] elsif n = NOTES.map{|t| t[:name].tr_to_ascii}.index(n.tr_to_ascii) NOTES[i] end end |
#fraction_from(n) ⇒ Object
377 378 379 |
# File 'lib/musiki.rb', line 377 def fraction_from n self.fraction_to(n) ** -1 end |
#fraction_to(n) ⇒ Object
362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/musiki.rb', line 362 def fraction_to n if n.class == Musiki::Note 2 ** (self.power2 - n.power2) * 3 ** (self.power3 - n.power3) elsif n.class == Hash 2 ** (self.power2 - n[:power2]) * 3 ** (self.power3 - n[:power3]) else begin n = find_note n 2 ** (self.power2 - n[:power2]) * 3 ** (self.power3 - n[:power3]) rescue nil end end end |
#freq ⇒ Object
434 435 436 |
# File 'lib/musiki.rb', line 434 def freq @absolute_frequency end |
#inspect ⇒ Object
358 359 360 |
# File 'lib/musiki.rb', line 358 def inspect "#{@name}".tr_capitalize end |
#int ⇒ Object
446 447 448 |
# File 'lib/musiki.rb', line 446 def int @interval_before end |
#int_sym ⇒ Object
452 453 454 |
# File 'lib/musiki.rb', line 452 def int_sym @interval_before_symbol end |
#interval ⇒ Object
449 450 451 |
# File 'lib/musiki.rb', line 449 def interval @interval_before end |
#interval_symbol ⇒ Object
455 456 457 |
# File 'lib/musiki.rb', line 455 def interval_symbol @interval_before_symbol end |
#ratio ⇒ Object
440 441 442 |
# File 'lib/musiki.rb', line 440 def ratio @relative_frequency end |
#rel_freq ⇒ Object
443 444 445 |
# File 'lib/musiki.rb', line 443 def rel_freq @relative_frequency end |
#setup(m, n) ⇒ Object
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
# File 'lib/musiki.rb', line 391 def setup m, n @name = m[:name] @frequency = m[:frequency] @absolute_frequency = Musiki.base * m[:frequency] @fraction = m[:fraction].gsub(/\s/,"").to_r @order = m[:order] @power2 = m[:power2] @power3 = m[:power3] @interval_before = m[:interval] @interval_before_symbol = m[:interval_symbol] @interval_after = NOTES[(m[:order]+1)%48][:interval] @interval_after_symbol = NOTES[(m[:order]+1)%48][:interval_symbol] # values relative to the makam @relative_fraction = self.fraction_to n @relative_frequency = eval("#{self.relative_fraction}.0") @relative_order = self.order - n[:order] rf = self.relative_fraction.to_r.to_s.split("/").map(&:to_i) if rf[0] % 2 == 0 @relative_power2 = Math.log(rf[0],2).to_i @relative_power3 = Math.log(rf[1],3).to_i * -1 else @relative_power2 = Math.log(rf[1],2).to_i * -1 @relative_power3 = Math.log(rf[0],3).to_i end @comma = m[:comma] - n[:comma] self end |
#transpose(o) ⇒ Object
381 382 383 384 385 386 387 388 389 |
# File 'lib/musiki.rb', line 381 def transpose o if o.is_a? Integer self.setup(find_note(self.order + o), find_note((self.relative_order - self.order)*-1 + o)) elsif o.match(/^[+-]?\d+c$/) o = o.match(/\d+/)[0].to_i * (o.match(/^-/) ? -1 : 1) elsif o.match(/^[+-]?[FEBSKTAZ]$/i) o = INTERVAL[o.match(/\w/)[0].upcase.to_sym][:value] * (o.match(/^-/) ? -1 : 1) end end |