<commit_before>require 'gosu_android/requires'

module Gosu
  MAX_SAMPLES = 10
  class SampleInstance
    def initialize

    end
  end

  class AudioFocusListener
      def onAudioFocusChange focusChange
        puts "In focus change #{focusChange}"
      end

      def toString
        self.class.to_s
      end
  end

  #TODO ManageAudioFocus, when app loses, stop song
  #TODO Raise a warning is the file could not be loaded
  class Sample

    #Constructs a sample that can be played on the specified audio
    #system and loads the sample from a file.
    def initialize(window, filename)
      @window = window
      #Set finalize
      ObjectSpace.define_finalizer(self, self.class.method(:finalize).to_proc)
      if not defined? @@pool
        @@pool = JavaImports::SoundPool.new(MAX_SAMPLES, JavaImports::AudioManager::STREAM_MUSIC, 0)
      end

      if(filename.class == Fixnum )
        @id = @@pool.load( @window.activity.getApplicationContext, filename, 1 )
      else
        @id = @@pool.load(filename, 1)
      end
    end

    #Plays the sample without panning.
    #\param volume Can be anything from 0.0 (silence) to 1.0 (full
    #volume).
    #\param speed Playback speed is only limited by the underlying audio library,
    #and can accept very high or low values. Use 1.0 for
    #normal playback speed.
    def play(volume = 1, speed = 1, looping = false)
      if looping == false
        @stream_id = @@pool.play(@id, volume, volume, 1, 0, 1.0)
      else
        @stream_id = @@pool.play(@id, volume, volume, 1, 1, 1.0)
      end
    end

    #TODO Pan is not supported so it is ignored
    def play_pan(pan = 0, volume = 1, speed = 1, looping = false)
      if looping == false
        @stream_id = @@pool.play(@id, volume, volume, 1, 0, 1.0)
      else
        @stream_id = @@pool.play(@id, volume, volume, 1, 1, 1.0)
      end
    end

    def Sample.finalize(id)
      @@pool.unload(@id)
    end

  end

  #TODO Error on playing several songs, bear in mind mediaplayer states
  #TODO Set listener for when the data finished loading asynchronously<commit_msg>Added finalizer to sample class.<commit_after>require 'gosu_android/requires'

module Gosu
  MAX_SAMPLES = 10
  class SampleInstance
    def initialize

    end
  end

  class AudioFocusListener
      def onAudioFocusChange focusChange
        puts "In focus change #{focusChange}"
      end

      def toString
        self.class.to_s
      end
  end

  #TODO ManageAudioFocus, when app loses, stop song
  #TODO Raise a warning is the file could not be loaded
  class Sample

    #Constructs a sample that can be played on the specified audio
    #system and loads the sample from a file.
    def initialize(window, filename)
      @window = window
      if not defined? @@pool
        @@pool = JavaImports::SoundPool.new(MAX_SAMPLES, JavaImports::AudioManager::STREAM_MUSIC, 0)
      end

      if(filename.class == Fixnum )
        @id = @@pool.load( @window.activity.getApplicationContext, filename, 1 )
      else
        @id = @@pool.load(filename, 1)
      end
      #Set finalize
      ObjectSpace.define_finalizer(self, self.class.finalize(@id))      
    end

    #Plays the sample without panning.
    #\param volume Can be anything from 0.0 (silence) to 1.0 (full
    #volume).
    #\param speed Playback speed is only limited by the underlying audio library,
    #and can accept very high or low values. Use 1.0 for
    #normal playback speed.
    def play(volume = 1, speed = 1, looping = false)
      if looping == false
        @stream_id = @@pool.play(@id, volume, volume, 1, 0, 1.0)
      else
        @stream_id = @@pool.play(@id, volume, volume, 1, 1, 1.0)
      end
    end

    #TODO Pan is not supported so it is ignored
    def play_pan(pan = 0, volume = 1, speed = 1, looping = false)
      if looping == false
        @stream_id = @@pool.play(@id, volume, volume, 1, 0, 1.0)
      else
        @stream_id = @@pool.play(@id, volume, volume, 1, 1, 1.0)
      end
    end

    def self.finalize(id)
      proc { @@pool.unload(id) }
    end

  end

  #TODO Error on playing several songs, bear in mind mediaplayer states
  #TODO Set listener for when the data finished loading asynchronously
{'fraction_non_alphanumeric': 0.089612550511053, 'fraction_numerical': 0.015212740670311385, 'mean_word_length': 2.578231292517007, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1532558', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1281, 'n_words': 468}