include/pulseaudio_sink.rb in pulseaudio-0.0.9 vs include/pulseaudio_sink.rb in pulseaudio-0.0.10

- old
+ new

@@ -6,11 +6,11 @@ # end class PulseAudio::Sink #The arguments-hash. Contains various data for the sink. attr_reader :args - @@sinks = Wref_map.new + @@sinks = Wref::Map.new #Used to look up IDs from names (like when getting default sink). @@sink_name_to_id_ref = {} #Autoloader for subclasses. @@ -29,18 +29,27 @@ list = %x[pactl list sinks] sinks = [] unless block_given? list.scan(/(\n|^)Sink #(\d+)\s+([\s\S]+?)Formats:\s+(.+?)\n/) do |match| props = {} + match[2].scan(/(\t|^)([A-z]+?): (.+?)\n/) do |match_prop| props[match_prop[1].downcase] = match_prop[2] end + + internal_props = {} + sink_internal_properties = match[2].scan(/Properties:\n(?:.+=.+\n)+/).first + sink_internal_properties.scan(/\t([A-z]+(?:\.[A-z]+)+) = "(.+?)"\n/) do |match_prop| + internal_props[match_prop[0].downcase] = match_prop[1] + end + props["internal_props"] = internal_props + sink_id = match[1].to_i args = {:sink_id => sink_id, :props => props} - sink = @@sinks.get!(sink_id) + sink = @@sinks[sink_id] if !sink sink = PulseAudio::Sink.new @@sinks[sink_id] = sink @@sink_name_to_id_ref[props["name"]] = sink_id end @@ -70,11 +79,11 @@ return PulseAudio::Sink.by_id(sink_id.to_i) end #This automatically reloads a sink when a 'change'-event appears. PulseAudio::Events.instance.connect(:event => :change, :element => "sink") do |args| - if @@sinks.key?(args[:args][:element_id]) and sink = @@sinks.get!(args[:args][:element_id]) + if @@sinks.key?(args[:args][:element_id]) and sink = @@sinks[args[:args][:element_id]] sink.reload end end #Reloads the information on the sink. @@ -85,11 +94,11 @@ #Returns a sink by its sink-ID. #===Examples # sink = PulseAudio::Sink.by_id(3) def self.by_id(id) #Return it from the weak-reference-map, if it already exists there. - if sink = @@sinks.get!(id) + if sink = @@sinks[id] return sink end #Read the sinks one-by-one and return it when found. PulseAudio::Sink.list do |sink| @@ -196,6 +205,6 @@ end %x[pacmd set-default-sink #{self.sink_id}] return nil end -end \ No newline at end of file +end