gtk2mp3 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/gtk2mp3 +6 -9
- data/lib/gtk2mp3/appconfig.rb +23 -22
- data/lib/gtk2mp3/couple.rb +18 -17
- data/lib/gtk2mp3/playlist.rb +10 -8
- data/lib/gtk2mp3.rb +60 -60
- metadata +13 -12
data/bin/gtk2mp3
CHANGED
@@ -1,28 +1,25 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'rubygems'
|
3
|
-
gem 'gtk2applib', '~>
|
3
|
+
gem 'gtk2applib', '~> 14.0'
|
4
4
|
$help = <<EOT
|
5
5
|
|
6
6
|
You can also give it the default mp3 directory via command line...
|
7
7
|
\t#{$0} /path-to/mp3s
|
8
8
|
|
9
9
|
EOT
|
10
|
-
require 'gtk2applib'
|
11
|
-
include Gtk2AppLib
|
12
|
-
include Configuration
|
10
|
+
require 'gtk2applib' # Gtk2AppLib defined
|
13
11
|
|
14
|
-
|
15
|
-
program = Program.new( {
|
12
|
+
program = Gtk2AppLib::Program.new( {
|
16
13
|
'name' => 'Ruby-Gnome MP3',
|
17
14
|
'authors' => ['carlosjhr64@gmail.com'],
|
18
|
-
'website' => '
|
15
|
+
'website' => 'https://sites.google.com/site/gtk2applib/home/gtk2applib-applications/gtk2mp3',
|
19
16
|
'website-label' => 'Ruby-Gnome MP3',
|
20
17
|
'license' => 'GPL',
|
21
|
-
'copyright' => '
|
18
|
+
'copyright' => '2011-03-10 11:19:13',
|
22
19
|
} )
|
23
20
|
|
24
21
|
begin
|
25
|
-
require 'gtk2mp3'
|
22
|
+
require 'gtk2mp3' # Gtk2MP3 defined
|
26
23
|
Gtk2MP3::Couple.load
|
27
24
|
program.window do |window|
|
28
25
|
Gtk2MP3::GUI.new(window,program)
|
data/lib/gtk2mp3/appconfig.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
|
-
module Gtk2AppLib
|
1
|
+
module Gtk2AppLib # Gtk2AppLib defined
|
2
2
|
module Configuration
|
3
|
+
WINDOW_DEFAULT_SIZE[0],WINDOW_DEFAULT_SIZE[1] = 0,0 # WINDOW_DEFAULT_SIZE defined in gtk2applib/configuration
|
4
|
+
MENU[:dock] = '_Dock' # MENU defined in gtk2applib/configuration
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
module Gtk2MP3
|
9
|
+
module Configuration
|
10
|
+
# File defined
|
11
|
+
# ARGV defined as command line arguments
|
12
|
+
# Gtk defined in gtk2
|
3
13
|
# Where is your MP3 directory?
|
4
14
|
dialog = Gtk::FileChooserDialog.new("Choose Mp3 Directory", nil, Gtk::FileChooser::ACTION_SELECT_FOLDER, nil,
|
5
15
|
[Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL], [Gtk::Stock::OPEN, Gtk::Dialog::RESPONSE_ACCEPT])
|
@@ -15,25 +25,22 @@ module Configuration
|
|
15
25
|
dialog.destroy
|
16
26
|
DIRECTORY = directory
|
17
27
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
SPACER4 = [' ', OPTIONS].freeze
|
25
|
-
INFO = {:modify_font => FONT[:Small]}.freeze
|
26
|
-
|
28
|
+
options = {:modify_font => Gtk2AppLib::Configuration::FONT[:Large]}.freeze
|
29
|
+
SPACER1 = [' ', options].freeze
|
30
|
+
SPACER2 = [' ', options].freeze
|
31
|
+
SPACER3 = [' ', options].freeze
|
32
|
+
SPACER4 = [' ', options].freeze
|
33
|
+
INFO = ['Gtk2 MP3 Next!!!!',{:modify_font => Gtk2AppLib::Configuration::FONT[:Small]}].freeze
|
27
34
|
|
28
35
|
RELOAD = '_Reload'
|
29
36
|
|
30
|
-
|
31
|
-
NEXT = ['Next!',
|
32
|
-
PAUSE = ['Pause',
|
33
|
-
STOP = ['Stop',
|
34
|
-
DELETE = ['Delete',
|
37
|
+
clicked = 'clicked'
|
38
|
+
NEXT = ['Next!', options, clicked].freeze
|
39
|
+
PAUSE = ['Pause', options, clicked].freeze # this one can be set to nil
|
40
|
+
STOP = ['Stop', options, clicked].freeze # this one can be set to nil
|
41
|
+
DELETE = ['Delete', options, clicked].freeze # this one can be set to nil
|
35
42
|
|
36
|
-
SELECT_A_FILE = [['Select a file', Gtk::FileChooser::ACTION_OPEN],HNIL].freeze
|
43
|
+
SELECT_A_FILE = [['Select a file', Gtk::FileChooser::ACTION_OPEN],Gtk2AppLib::HNIL].freeze
|
37
44
|
|
38
45
|
PLAYER = 'mpg123 -q -a hw:0,0 -R' # 'mpg123 -q -R'
|
39
46
|
# mpg123 commands
|
@@ -43,11 +50,5 @@ module Configuration
|
|
43
50
|
C_LOAD = 'L'
|
44
51
|
C_QUIT = 'Q'
|
45
52
|
|
46
|
-
### Unused ####
|
47
|
-
# C_LOADPAUSED = 'LP'
|
48
|
-
# C_VOLUME = 'V'
|
49
|
-
# C_TAG = 'T'
|
50
|
-
|
51
|
-
MENU[:dock] = '_Dock'
|
52
53
|
end
|
53
54
|
end
|
data/lib/gtk2mp3/couple.rb
CHANGED
@@ -1,17 +1,25 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# Gtk2AppLib defined
|
2
|
+
module Gtk2MP3 # Gtk2MP3 defined
|
3
|
+
class Couple # Couple defined
|
3
4
|
BASE = Hash.new(1.0)
|
4
|
-
BASE_DUMP = USERDIR + '/base.dump'
|
5
|
+
BASE_DUMP = Gtk2AppLib::USERDIR + '/base.dump'
|
5
6
|
|
6
7
|
COUPLE = Hash.new(1.0)
|
7
|
-
COUPLE_DUMP = USERDIR + '/couple.dump'
|
8
|
+
COUPLE_DUMP = Gtk2AppLib::USERDIR + '/couple.dump'
|
8
9
|
|
9
|
-
LEARNING = Math.sqrt(2.0)
|
10
|
+
LEARNING = Math.sqrt(2.0) # Math defined, built in
|
10
11
|
SEP = '/'
|
11
|
-
SEPX = Regexp.new(SEP)
|
12
|
+
SEPX = Regexp.new(SEP) # Regexp defined, built in
|
13
|
+
|
14
|
+
def initialize(candidate,previous)
|
15
|
+
@candidate = candidate
|
16
|
+
@previous = previous
|
17
|
+
self.keys!
|
18
|
+
self.threshold!
|
19
|
+
end
|
12
20
|
|
13
21
|
def self._load(dump,hash)
|
14
|
-
File.open(dump,'r'){|fh|
|
22
|
+
File.open(dump,'r'){|fh| # File defined, built in
|
15
23
|
fh.each{|line|
|
16
24
|
if line=~/^(.*)\s([\d\.]+)\s*$/ then
|
17
25
|
hash[$1.strip] = $2.to_f
|
@@ -25,7 +33,7 @@ class Couple
|
|
25
33
|
end
|
26
34
|
|
27
35
|
def self.delete(current)
|
28
|
-
key = File.basename(current,MP3)
|
36
|
+
key = File.basename(current,Gtk2MP3::MP3)
|
29
37
|
BASE.delete(key)
|
30
38
|
COUPLE.delete_if{|k| k.split(SEPX).include?(key)}
|
31
39
|
end
|
@@ -40,8 +48,8 @@ class Couple
|
|
40
48
|
end
|
41
49
|
|
42
50
|
def keys!
|
43
|
-
@base = File.basename(@candidate,MP3)
|
44
|
-
@couple = @base + SEP + File.basename(@previous,MP3)
|
51
|
+
@base = File.basename(@candidate,Gtk2MP3::MP3)
|
52
|
+
@couple = @base + SEP + File.basename(@previous,Gtk2MP3::MP3)
|
45
53
|
end
|
46
54
|
|
47
55
|
def keys
|
@@ -56,13 +64,6 @@ class Couple
|
|
56
64
|
@threshold
|
57
65
|
end
|
58
66
|
|
59
|
-
def initialize(candidate,previous)
|
60
|
-
@candidate = candidate
|
61
|
-
@previous = previous
|
62
|
-
self.keys!
|
63
|
-
self.threshold!
|
64
|
-
end
|
65
|
-
|
66
67
|
def promote
|
67
68
|
BASE[@base] *= LEARNING
|
68
69
|
COUPLE[@couple] *= LEARNING
|
data/lib/gtk2mp3/playlist.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
|
-
|
2
|
-
class Playlist < Array
|
3
|
-
IS_MP3 = Regexp.new(/\.mp3$/)
|
1
|
+
require 'find' # Find defined
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
raise 'no mp3s found' if self.length < 1
|
9
|
-
end
|
3
|
+
module Gtk2MP3
|
4
|
+
class Playlist < Array # [] defined in Array
|
5
|
+
IS_MP3 = Regexp.new(/\.mp3$/) # Regexp defined, built in
|
10
6
|
|
11
7
|
def initialize(directory)
|
12
8
|
super()
|
@@ -15,6 +11,12 @@ class Playlist < Array
|
|
15
11
|
$stderr.puts "Playlist length #{self.length}" if $trace
|
16
12
|
end
|
17
13
|
|
14
|
+
def reload
|
15
|
+
self.clear
|
16
|
+
Find.find(@directory){|fn| self.push(fn) if fn=~IS_MP3 }
|
17
|
+
raise 'no mp3s found' if self.length < 1
|
18
|
+
end
|
19
|
+
|
18
20
|
def random
|
19
21
|
self[ rand(self.length) ]
|
20
22
|
end
|
data/lib/gtk2mp3.rb
CHANGED
@@ -1,12 +1,19 @@
|
|
1
1
|
require 'gtk2mp3/playlist'
|
2
|
-
require 'gtk2mp3/couple'
|
2
|
+
require 'gtk2mp3/couple' # Couple defined
|
3
|
+
# Configuration defined in gtk2mp3/appconfig
|
4
|
+
# Gtk2AppLib defined
|
3
5
|
|
4
|
-
module Gtk2MP3
|
6
|
+
module Gtk2MP3 # Gtk2MP3 defined
|
5
7
|
MP3 = '.mp3'
|
6
8
|
|
7
|
-
class Pipe
|
9
|
+
class Pipe # Pipe defined
|
10
|
+
def initialize(gui)
|
11
|
+
@gui = gui
|
12
|
+
@pipe = nil
|
13
|
+
self.open
|
14
|
+
end
|
8
15
|
def _read
|
9
|
-
@thread = Thread.new do
|
16
|
+
@thread = Thread.new do # Thread defined
|
10
17
|
@pipe.each do |line|
|
11
18
|
line.strip!
|
12
19
|
$stderr.puts line if $trace
|
@@ -24,8 +31,8 @@ module Gtk2MP3
|
|
24
31
|
end
|
25
32
|
def open
|
26
33
|
if !@pipe then
|
27
|
-
@pipe = IO.popen(Configuration::PLAYER,'w+')
|
28
|
-
self.puts C_SILENCE
|
34
|
+
@pipe = IO.popen(Configuration::PLAYER,'w+') # IO defined
|
35
|
+
self.puts Configuration::C_SILENCE
|
29
36
|
self._read
|
30
37
|
end
|
31
38
|
end
|
@@ -42,16 +49,54 @@ module Gtk2MP3
|
|
42
49
|
@pipe = nil
|
43
50
|
end
|
44
51
|
end
|
45
|
-
def initialize(gui)
|
46
|
-
@gui = gui
|
47
|
-
self.open
|
48
|
-
end
|
49
52
|
end
|
50
53
|
|
51
54
|
class GUI
|
52
|
-
include Configuration
|
53
55
|
attr_reader :continue, :couple, :current
|
54
56
|
attr_writer :previous
|
57
|
+
def initialize(window,program)
|
58
|
+
@playlist = Gtk2MP3::Playlist.new(Configuration::DIRECTORY)
|
59
|
+
@current = ''
|
60
|
+
@previous = ''
|
61
|
+
@continue = true
|
62
|
+
@pipe = Pipe.new(self)
|
63
|
+
window.signal_connect('destroy'){ @pipe.close }
|
64
|
+
|
65
|
+
vbox = Gtk2AppLib::Widgets::VBox.new(window)
|
66
|
+
|
67
|
+
hbox = Gtk2AppLib::Widgets::HBox.new(vbox)
|
68
|
+
@info = Gtk2AppLib::Widgets::Label.new(*Configuration::INFO+[hbox])
|
69
|
+
|
70
|
+
hbox = Gtk2AppLib::Widgets::HBox.new(vbox)
|
71
|
+
Gtk2AppLib::Widgets::Label.new(*Configuration::SPACER1+[hbox]) # Spacer
|
72
|
+
Gtk2AppLib::Widgets::Button.new(*Configuration::NEXT+[hbox]){ self.skip_song }
|
73
|
+
if Configuration::PAUSE then
|
74
|
+
Gtk2AppLib::Widgets::Label.new(*Configuration::SPACER2+[hbox]) # Spacer
|
75
|
+
Gtk2AppLib::Widgets::Button.new(*Configuration::PAUSE+[hbox]){ self.pause_song }
|
76
|
+
end
|
77
|
+
if Configuration::STOP then
|
78
|
+
Gtk2AppLib::Widgets::Label.new(*Configuration::SPACER2+[hbox]) # Spacer
|
79
|
+
Gtk2AppLib::Widgets::Button.new(*Configuration::STOP+[hbox]){ self.stop_song }
|
80
|
+
end
|
81
|
+
if Configuration::DELETE then
|
82
|
+
Gtk2AppLib::Widgets::Label.new(*Configuration::SPACER3+[hbox]) # Spacer
|
83
|
+
Gtk2AppLib::Widgets.define_composite(:CheckButton,:Button)
|
84
|
+
Gtk2AppLib::Widgets::CheckButtonButton.new(*Configuration::DELETE+[hbox]){|is,*dummies|
|
85
|
+
if is.checkbutton.active? then
|
86
|
+
self.delete_song
|
87
|
+
is.checkbutton.active = false
|
88
|
+
end
|
89
|
+
}
|
90
|
+
end
|
91
|
+
Gtk2AppLib::Widgets::Label.new(*Configuration::SPACER4+[hbox]) # Spacer
|
92
|
+
|
93
|
+
self.load_song
|
94
|
+
|
95
|
+
program.append_app_menu(Configuration::RELOAD){ @playlist.reload }
|
96
|
+
program.append_dock_menu(Configuration::PAUSE.first){ self.pause_song } if Configuration::PAUSE
|
97
|
+
program.append_dock_menu(Configuration::STOP.first){ self.stop_song } if Configuration::STOP
|
98
|
+
program.append_dock_menu(Configuration::NEXT.first){ self.skip_song }
|
99
|
+
end
|
55
100
|
|
56
101
|
def random_song
|
57
102
|
plays = false
|
@@ -66,8 +111,8 @@ module Gtk2MP3
|
|
66
111
|
|
67
112
|
def load_song
|
68
113
|
self.random_song
|
69
|
-
@info.text = File.basename(@current,MP3)
|
70
|
-
@pipe.puts "#{C_LOAD} #{@current}"
|
114
|
+
@info.text = File.basename(@current,MP3) # File defined
|
115
|
+
@pipe.puts "#{Configuration::C_LOAD} #{@current}"
|
71
116
|
end
|
72
117
|
|
73
118
|
def skip_song
|
@@ -77,7 +122,7 @@ module Gtk2MP3
|
|
77
122
|
|
78
123
|
def stop_song
|
79
124
|
if @continue then
|
80
|
-
@pipe.puts C_STOP
|
125
|
+
@pipe.puts Configuration::C_STOP
|
81
126
|
@previous = ''
|
82
127
|
@continue = false
|
83
128
|
@pipe.close
|
@@ -88,7 +133,7 @@ module Gtk2MP3
|
|
88
133
|
end
|
89
134
|
|
90
135
|
def pause_song
|
91
|
-
@pipe.puts C_PAUSE
|
136
|
+
@pipe.puts Configuration::C_PAUSE
|
92
137
|
end
|
93
138
|
|
94
139
|
def delete_song
|
@@ -97,50 +142,5 @@ module Gtk2MP3
|
|
97
142
|
Couple.delete(@current)
|
98
143
|
self.load_song
|
99
144
|
end
|
100
|
-
|
101
|
-
|
102
|
-
def initialize(window,program)
|
103
|
-
@playlist = Gtk2MP3::Playlist.new(DIRECTORY)
|
104
|
-
@current = ''
|
105
|
-
@previous = ''
|
106
|
-
@continue = true
|
107
|
-
@pipe = Pipe.new(self)
|
108
|
-
window.signal_connect('destroy'){ @pipe.close }
|
109
|
-
|
110
|
-
vbox = Widgets::VBox.new(window)
|
111
|
-
|
112
|
-
hbox = Widgets::HBox.new(vbox)
|
113
|
-
@info = Widgets::Label.new('Gtk2 MP3 Next!!!!', INFO, hbox)
|
114
|
-
|
115
|
-
hbox = Widgets::HBox.new(vbox)
|
116
|
-
Widgets::Label.new(*SPACER1, hbox) # Spacer
|
117
|
-
Widgets::Button.new(*NEXT, hbox){ self.skip_song }
|
118
|
-
if PAUSE then
|
119
|
-
Widgets::Label.new(*SPACER2, hbox) # Spacer
|
120
|
-
Widgets::Button.new(*PAUSE, hbox){ self.pause_song }
|
121
|
-
end
|
122
|
-
if STOP then
|
123
|
-
Widgets::Label.new(*SPACER2, hbox) # Spacer
|
124
|
-
Widgets::Button.new(*STOP, hbox){ self.stop_song }
|
125
|
-
end
|
126
|
-
if DELETE then
|
127
|
-
Widgets::Label.new(*SPACER3, hbox) # Spacer
|
128
|
-
Widgets.define_composite(:CheckButton,:Button)
|
129
|
-
Widgets::CheckButtonButton.new(*DELETE, hbox){|is,*dummies|
|
130
|
-
if is.checkbutton.active? then
|
131
|
-
self.delete_song
|
132
|
-
is.checkbutton.active = false
|
133
|
-
end
|
134
|
-
}
|
135
|
-
end
|
136
|
-
Widgets::Label.new(*SPACER4, hbox) # Spacer
|
137
|
-
|
138
|
-
self.load_song
|
139
|
-
|
140
|
-
program.append_app_menu(RELOAD){ @playlist.reload }
|
141
|
-
program.append_dock_menu(PAUSE.first){ self.pause_song } if PAUSE
|
142
|
-
program.append_dock_menu(STOP.first){ self.stop_song } if STOP
|
143
|
-
program.append_dock_menu(NEXT.first){ self.skip_song }
|
144
|
-
end
|
145
145
|
end
|
146
146
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gtk2mp3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- carlosjhr64@gmail.com
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-03-10 00:00:00 -08:00
|
19
19
|
default_executable: gtk2mp3
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -26,10 +26,11 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 51
|
30
30
|
segments:
|
31
|
-
-
|
32
|
-
|
31
|
+
- 14
|
32
|
+
- 0
|
33
|
+
version: "14.0"
|
33
34
|
type: :runtime
|
34
35
|
version_requirements: *id001
|
35
36
|
description: a "Next!" button gui for mpg123
|
@@ -51,7 +52,7 @@ files:
|
|
51
52
|
- README.txt
|
52
53
|
- bin/gtk2mp3
|
53
54
|
has_rdoc: true
|
54
|
-
homepage:
|
55
|
+
homepage: https://sites.google.com/site/gtk2applib/home/gtk2applib-applications/gtk2mp3
|
55
56
|
licenses: []
|
56
57
|
|
57
58
|
post_install_message:
|
@@ -80,8 +81,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
81
|
version: "0"
|
81
82
|
requirements:
|
82
83
|
- mpg123
|
83
|
-
rubyforge_project:
|
84
|
-
rubygems_version: 1.
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.5.2
|
85
86
|
signing_key:
|
86
87
|
specification_version: 3
|
87
88
|
summary: Gtk2MP3
|