Sha256: 90c8d92baea32c7fe27e9a3654779ba183941c11d54fe17a7fa36c7d5ad0f330

Contents?: true

Size: 1.69 KB

Versions: 5

Compression:

Stored size: 1.69 KB

Contents

# lib/gemwarrior/misc/music.rb
# Music cues using win32-sound or feep, depending on platform

require_relative '../game_options'

module Gemwarrior
  module Music
    def self.cue(sequence)
      if GameOptions.data['sound_enabled']
        # if Windows, use superior win32-sound library
        if GameOptions.data['sound_system'].eql?('win32-sound')
          require 'win32/sound'
          require_relative 'musical_notes'
        
          Thread.start do
            sequence.each do |seq|
              threads = []
              seq[:frequencies].split(',').each do |note|
                threads << Thread.new do
                  Win32::Sound::play_freq(Notes::NOTE_FREQ[note], seq[:duration], GameOptions.data['sound_volume'])
                end
              end
              threads.each { |th| th.join }
            end
          end
        # otherwise, use inferior feep library
        elsif GameOptions.data['sound_system'].eql?('feep')
          require 'feep'

          feep_defaults = {
            frequencies:  '440',
            waveform:     'sine',
            volume:       GameOptions.data['sound_volume'],
            duration:     500,
            notext:       true
          }
      
          Thread.start do
            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
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gemwarrior-0.10.8 lib/gemwarrior/misc/music.rb
gemwarrior-0.10.7 lib/gemwarrior/misc/music.rb
gemwarrior-0.10.6 lib/gemwarrior/misc/music.rb
gemwarrior-0.10.5 lib/gemwarrior/misc/music.rb
gemwarrior-0.10.4 lib/gemwarrior/misc/music.rb