Sha256: 74e6f08ff544d886ed89ee4f61875098f49908596b42e5b42e260cc588f24574

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

# lib/gemwarrior/misc/music.rb
# Music cues using win32-sound

module Gemwarrior
  module Music
    def self.cue(sequence)
      # if Windows, use superior win32-sound library
      if OS.windows?
        require 'win32/sound'
        threads = []

        Thread.start {
          sequence.each do |seq|
            seq[:frequencies].split(',').each do |note|
              threads << Thread.new {
                Win32::Sound::play_freq(Notes::NOTE_FREQ[note], seq[:duration], 0.5)
              }
            end
            threads.each { |th| th.join }
          end
        }
      # otherwise, use inferior feep library
      else
        require 'feep'
        require_relative 'musical_notes'

        feep_defaults = {
          :frequencies  => '440',
          :waveform     => 'sine',
          :volume       => 0.3,
          :duration     => 500,
          :notext       => true
        }
      
        Thread.start {
          sequence.each do |seq|
            seq = feep_defaults.merge(seq)

            Feep::Base.new({
              :freq_or_note => seq[:frequencies],
              :waveform     => seq[:waveform],
              :volume       => seq[:volume],
              :duration     => seq[:duration],
              :notext       => seq[:notext]
            })
          end
        }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gemwarrior-0.9.27 lib/gemwarrior/misc/music.rb