rubytrackselector 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +165 -0
- data/README +54 -0
- data/Rakefile +38 -0
- data/doc/index.rdoc +52 -0
- data/lib/rubytrackselector.rb +29 -0
- data/lib/rubytrackselector/home.rb +37 -0
- data/lib/rubytrackselector/utp.rb +90 -0
- data/samples/sample.rb +8 -0
- data/test/dummy.wav +0 -0
- data/test/test_general.rb +43 -0
- data/test/test_homedir.rb +27 -0
- data/test/test_tags.rb +35 -0
- data/test/testhelper.rb +28 -0
- metadata +89 -0
data/COPYING
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
Version 3, 29 June 2007
|
3
|
+
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
6
|
+
of this license document, but changing it is not allowed.
|
7
|
+
|
8
|
+
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
11
|
+
License, supplemented by the additional permissions listed below.
|
12
|
+
|
13
|
+
0. Additional Definitions.
|
14
|
+
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
17
|
+
General Public License.
|
18
|
+
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
20
|
+
other than an Application or a Combined Work as defined below.
|
21
|
+
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
25
|
+
of using an interface provided by the Library.
|
26
|
+
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
28
|
+
Application with the Library. The particular version of the Library
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
30
|
+
Version".
|
31
|
+
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
35
|
+
based on the Application, and not on the Linked Version.
|
36
|
+
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
38
|
+
object code and/or source code for the Application, including any data
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
41
|
+
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
43
|
+
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
46
|
+
|
47
|
+
2. Conveying Modified Versions.
|
48
|
+
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
51
|
+
that uses the facility (other than as an argument passed when the
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
53
|
+
version:
|
54
|
+
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
56
|
+
ensure that, in the event an Application does not supply the
|
57
|
+
function or data, the facility still operates, and performs
|
58
|
+
whatever part of its purpose remains meaningful, or
|
59
|
+
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
61
|
+
this License applicable to that copy.
|
62
|
+
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
64
|
+
|
65
|
+
The object code form of an Application may incorporate material from
|
66
|
+
a header file that is part of the Library. You may convey such object
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
68
|
+
material is not limited to numerical parameters, data structure
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
71
|
+
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
73
|
+
Library is used in it and that the Library and its use are
|
74
|
+
covered by this License.
|
75
|
+
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
77
|
+
document.
|
78
|
+
|
79
|
+
4. Combined Works.
|
80
|
+
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
82
|
+
taken together, effectively do not restrict modification of the
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
85
|
+
the following:
|
86
|
+
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
88
|
+
the Library is used in it and that the Library and its use are
|
89
|
+
covered by this License.
|
90
|
+
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92
|
+
document.
|
93
|
+
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
95
|
+
execution, include the copyright notice for the Library among
|
96
|
+
these notices, as well as a reference directing the user to the
|
97
|
+
copies of the GNU GPL and this license document.
|
98
|
+
|
99
|
+
d) Do one of the following:
|
100
|
+
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
102
|
+
License, and the Corresponding Application Code in a form
|
103
|
+
suitable for, and under terms that permit, the user to
|
104
|
+
recombine or relink the Application with a modified version of
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
107
|
+
Corresponding Source.
|
108
|
+
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
111
|
+
a copy of the Library already present on the user's computer
|
112
|
+
system, and (b) will operate properly with a modified version
|
113
|
+
of the Library that is interface-compatible with the Linked
|
114
|
+
Version.
|
115
|
+
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
117
|
+
be required to provide such information under section 6 of the
|
118
|
+
GNU GPL, and only to the extent that such information is
|
119
|
+
necessary to install and execute a modified version of the
|
120
|
+
Combined Work produced by recombining or relinking the
|
121
|
+
Application with a modified version of the Linked Version. (If
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
126
|
+
for conveying Corresponding Source.)
|
127
|
+
|
128
|
+
5. Combined Libraries.
|
129
|
+
|
130
|
+
You may place library facilities that are a work based on the
|
131
|
+
Library side by side in a single library together with other library
|
132
|
+
facilities that are not Applications and are not covered by this
|
133
|
+
License, and convey such a combined library under terms of your
|
134
|
+
choice, if you do both of the following:
|
135
|
+
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
137
|
+
on the Library, uncombined with any other library facilities,
|
138
|
+
conveyed under the terms of this License.
|
139
|
+
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
141
|
+
is a work based on the Library, and explaining where to find the
|
142
|
+
accompanying uncombined form of the same work.
|
143
|
+
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
145
|
+
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
148
|
+
versions will be similar in spirit to the present version, but may
|
149
|
+
differ in detail to address new problems or concerns.
|
150
|
+
|
151
|
+
Each version is given a distinguishing version number. If the
|
152
|
+
Library as you received it specifies that a certain numbered version
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
154
|
+
applies to it, you have the option of following the terms and
|
155
|
+
conditions either of that published version or of any later version
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
160
|
+
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
164
|
+
permanent authorization for you to choose that version for the
|
165
|
+
Library.
|
data/README
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
Tired of hearing always the same background music in your game?
|
2
|
+
Too lazy to fire up your media player?
|
3
|
+
|
4
|
+
Ruby Track Selector to the rescue!
|
5
|
+
=> gem install rubytrackselector
|
6
|
+
|
7
|
+
_______________________________________________________________________________
|
8
|
+
|
9
|
+
Ruby Track Selector organizes your game music into tags (for example "menu" or
|
10
|
+
"loading") and generates a list of all music files for a given tag in
|
11
|
+
"~/.rubytracks" and one or more application specific directories. The
|
12
|
+
application specific directories can be disabled and re-enabled at will.
|
13
|
+
|
14
|
+
_______________________________________________________________________________
|
15
|
+
|
16
|
+
Example:
|
17
|
+
|
18
|
+
require "rubytrackselector"
|
19
|
+
|
20
|
+
rts = RTS::Rts.new
|
21
|
+
rts.tag = RTS::MENU
|
22
|
+
|
23
|
+
rts.files.sample # => ~/.rubytracks/menu/ultra_awesome_menu_song.ogg
|
24
|
+
rts.files.sample # => ~/.rubytracks/menu/awesome_menu_song.ogg
|
25
|
+
|
26
|
+
With application specific directories:
|
27
|
+
|
28
|
+
require "rubytrackselector"
|
29
|
+
|
30
|
+
rts = RTS::Rts.new
|
31
|
+
rts.tag = RTS::MENU
|
32
|
+
rts.local << File.join(File.dirname(__FILE__), "music")
|
33
|
+
rts.enable_local = true
|
34
|
+
|
35
|
+
rts.files.sample # => ~/.rubytracks/menu/awesome_menu_song.ogg
|
36
|
+
rts.files.sample # => /game/path/music/menu/other_menu_song.ogg
|
37
|
+
|
38
|
+
Rubygame integration:
|
39
|
+
|
40
|
+
require "rubytrackselector"
|
41
|
+
require "rubygame"
|
42
|
+
|
43
|
+
rts = RTS::Rts.new
|
44
|
+
rts.tag = RTS::MENU
|
45
|
+
|
46
|
+
rts.play(:repeats => -1)
|
47
|
+
|
48
|
+
_______________________________________________________________________________
|
49
|
+
|
50
|
+
Ruby Track Selector is licensed under the GNU Lesser General Public License.
|
51
|
+
See COPYING for details.
|
52
|
+
|
53
|
+
_______________________________________________________________________________
|
54
|
+
(c) 2010 by Raphael Robatsch
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require "rake/testtask"
|
2
|
+
require "rake/rdoctask"
|
3
|
+
require "rake/gempackagetask"
|
4
|
+
require "lib/rubytrackselector.rb"
|
5
|
+
|
6
|
+
spec = Gem::Specification.new do |s|
|
7
|
+
s.name = "rubytrackselector"
|
8
|
+
s.summary = "A music selection library for Rubygame."
|
9
|
+
s.version = RTS::VERSION.join(".")
|
10
|
+
|
11
|
+
s.required_ruby_version = ">= 1.8"
|
12
|
+
s.add_dependency("rubygame", "~> 2.6")
|
13
|
+
|
14
|
+
s.author = "Raphael Robatsch"
|
15
|
+
s.email = "mf.m-f@rleahpar".reverse
|
16
|
+
s.has_rdoc = true
|
17
|
+
s.homepage = "http://raphaelr.github.com/rubytrackselector"
|
18
|
+
|
19
|
+
s.files = Dir["lib/**/*"] + Dir["test/**/*"] + Dir["doc/**/*"]
|
20
|
+
s.files += Dir["samples/*"] + Dir["*"]
|
21
|
+
s.extra_rdoc_files = Dir["doc/*.rdoc"]
|
22
|
+
s.test_files = Dir["test/test_*.rb"]
|
23
|
+
end
|
24
|
+
|
25
|
+
Rake::TestTask.new do |t|
|
26
|
+
t.libs << "test"
|
27
|
+
t.pattern = "test/test_*.rb"
|
28
|
+
end
|
29
|
+
|
30
|
+
Rake::RDocTask.new do |t|
|
31
|
+
t.main = "doc/index.rdoc"
|
32
|
+
t.title = "Ruby Track Selector #{RTS::VERSION.join(".")}"
|
33
|
+
t.rdoc_files = Dir["doc/*.rdoc"] + Dir["lib/**/*"]
|
34
|
+
end
|
35
|
+
|
36
|
+
Rake::GemPackageTask.new(spec) do |t|
|
37
|
+
t.need_tar_gz
|
38
|
+
end
|
data/doc/index.rdoc
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
For a complete example, see the RTS module documentation.
|
2
|
+
|
3
|
+
== User Music Directory Structure
|
4
|
+
|
5
|
+
~ (home)
|
6
|
+
|
|
7
|
+
+- .rubytracks (created automatically)
|
8
|
+
| |
|
9
|
+
| +- tag1 (created automatically if needed)
|
10
|
+
| +- tag2 (created automatically if needed)
|
11
|
+
| |
|
12
|
+
| +- noname_tag_independent_music.ogg
|
13
|
+
| +- noname_tag_independent_music2.ogg
|
14
|
+
|
15
|
+
|
16
|
+
The standard tag names are:
|
17
|
+
|
18
|
+
- menu
|
19
|
+
- calm_menu
|
20
|
+
- loading
|
21
|
+
- calm_loading
|
22
|
+
- action_scene
|
23
|
+
- puzzle_scene
|
24
|
+
- world_scene
|
25
|
+
|
26
|
+
== Local Music Directory
|
27
|
+
|
28
|
+
Each application may define it's own music directory, which has the same
|
29
|
+
structure as the user's music directory.
|
30
|
+
|
31
|
+
@rts = RTS::Rts.new
|
32
|
+
@rts.local << "data/music"
|
33
|
+
@rts.enable_local = true
|
34
|
+
|
35
|
+
== Setting the tag
|
36
|
+
|
37
|
+
@rts.tag = RTS::MENU
|
38
|
+
|
39
|
+
== Selecting a random file
|
40
|
+
|
41
|
+
@rts.files.sample
|
42
|
+
|
43
|
+
== Playing a random file
|
44
|
+
|
45
|
+
@rts.play
|
46
|
+
# Any options passed to RTS::Rts#play get redirected to Rubygame::Music#play.
|
47
|
+
|
48
|
+
== Noname-Tag
|
49
|
+
|
50
|
+
If you don't set a tag, or set the tag to RTS::NONAME, User Track Player will
|
51
|
+
select the files outside a tag (directly in ~/.usertrackplayer). You shouldn't
|
52
|
+
do that.
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#--
|
2
|
+
# Ruby Track Selector - A music selecting library for Rubygame.
|
3
|
+
# Copyright (C) 2010 Raphael Robatsch.
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 3 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18
|
+
#++
|
19
|
+
|
20
|
+
module RTS
|
21
|
+
# Ruby Track Selector Version.
|
22
|
+
#
|
23
|
+
# <tt>[major, minor, revision]</tt>
|
24
|
+
VERSION = [0, 0, 2]
|
25
|
+
end
|
26
|
+
|
27
|
+
lib = File.join(File.expand_path(File.dirname(__FILE__)), "rubytrackselector")
|
28
|
+
require File.join(lib, "home")
|
29
|
+
require File.join(lib, "utp")
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#--
|
2
|
+
# Ruby Track Selector - A music selecting library for Rubygame.
|
3
|
+
# Copyright (C) 2010 Raphael Robatsch.
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 3 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18
|
+
#++
|
19
|
+
|
20
|
+
module RTS
|
21
|
+
RTS_DIR = ".rubytracks" # :nodoc:
|
22
|
+
|
23
|
+
# Returns the user's home directory.
|
24
|
+
def self.home
|
25
|
+
return File.expand_path("~")
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns the path to the user's custom music directory.
|
29
|
+
#
|
30
|
+
# +create+:: If this parameter is true, the directory will be created if
|
31
|
+
# it doesn't exists.
|
32
|
+
def self.user_music(create = true)
|
33
|
+
dn = File.join(home, RTS_DIR)
|
34
|
+
Dir.mkdir(dn) if create && !Dir.exists?(dn)
|
35
|
+
return dn
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
#--
|
2
|
+
# Ruby Track Selector - A music selecting library for Rubygame.
|
3
|
+
# Copyright (C) 2010 Raphael Robatsch.
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 3 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18
|
+
#++
|
19
|
+
|
20
|
+
# == Usage Example
|
21
|
+
#
|
22
|
+
# # Initialize
|
23
|
+
# @rts = RTS::Rts.new
|
24
|
+
# @rts.local << "data/music" # Add application specific music directory. (optional)
|
25
|
+
# @rts.enable_local = true # Enable application specific music directory.
|
26
|
+
#
|
27
|
+
# # And play
|
28
|
+
# @rts.tag = RTS::MENU # See below for a full list of tags.
|
29
|
+
# # You can set it to any string you like.
|
30
|
+
# @rts.play(:repeats => -1) # Select a random music and play it.
|
31
|
+
# # Returns the selected Rubygame::Music.
|
32
|
+
#
|
33
|
+
#
|
34
|
+
# # Or manually:
|
35
|
+
# music = Rubygame::Music.load(@rts.files.sample)
|
36
|
+
# music.play(:repeats => -1)
|
37
|
+
#
|
38
|
+
|
39
|
+
|
40
|
+
module RTS
|
41
|
+
# Tag for menu tracks.
|
42
|
+
MENU = "menu"
|
43
|
+
# Tag for calm menu tracks.
|
44
|
+
CALM_MENU = "calm_menu"
|
45
|
+
# Tag for loading tracks.
|
46
|
+
LOADING = "loading"
|
47
|
+
# Tag for calm loading tracks.
|
48
|
+
CALM_LOADING = "calm_loading"
|
49
|
+
# Tag for action tracks.
|
50
|
+
ACTION_SCENE = "action_scene"
|
51
|
+
# Tag for puzzle tracks.
|
52
|
+
PUZZLE_SCENE = "puzzle_scene"
|
53
|
+
# Tag for world map tracks.
|
54
|
+
WORLD_SCENE = "world_scene"
|
55
|
+
NONAME = nil # :nodoc:
|
56
|
+
|
57
|
+
# Main RTS Class.
|
58
|
+
class Rts < Struct.new(:local, :enable_local, :tag)
|
59
|
+
# The current track being played by <tt>Rts#play</tt>.
|
60
|
+
attr_reader :current
|
61
|
+
|
62
|
+
# Initializes a new RTS.
|
63
|
+
def initialize
|
64
|
+
self.local = []
|
65
|
+
self.enable_local = false
|
66
|
+
end
|
67
|
+
|
68
|
+
# Returns a list of all music files in the selected tag.
|
69
|
+
def files
|
70
|
+
a = [RTS.user_music]
|
71
|
+
a += self.local if self.enable_local
|
72
|
+
join_string = (self.tag ? "#{self.tag}/" : "") + "*.{ogg,wav,mid,midi,mod}"
|
73
|
+
return a.collect { |x| Dir[File.join(x, join_string)] }.inject(:+)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Selects a random music file and plays it. The option hash passed to
|
77
|
+
# this method gets forwarded to <tt>Rubygame::Music#play</tt>. See
|
78
|
+
# http://docs.rubygame.org/rdoc/current/classes/Rubygame/Music.html#M000407
|
79
|
+
# for more information.
|
80
|
+
def play(opts = {})
|
81
|
+
if fn = files.sample
|
82
|
+
@current = Rubygame::Music.load(files.sample)
|
83
|
+
@current.play(opts)
|
84
|
+
return @current
|
85
|
+
else
|
86
|
+
return nil
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/samples/sample.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# This will print out 10 random song files. You can pass a tag
|
2
|
+
# as command line parameter. Default is "menu".
|
3
|
+
require File.join(File.dirname(__FILE__), "..", "lib", "rubytrackselector")
|
4
|
+
|
5
|
+
rts = RTS::Rts.new
|
6
|
+
rts.tag = ARGV[0] || RTS::MENU
|
7
|
+
|
8
|
+
10.times { puts rts.files.sample }
|
data/test/dummy.wav
ADDED
Binary file
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "fileutils"
|
3
|
+
require "rubytrackselector"
|
4
|
+
require "testhelper"
|
5
|
+
|
6
|
+
class UsermusicTest < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
usermusic_wrapper do
|
9
|
+
FileUtils.rm_rf(RTS.user_music(false)) rescue nil
|
10
|
+
@musics = generate_musics.sort
|
11
|
+
@rts = RTS::Rts.new
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_user_musics
|
16
|
+
usermusic_wrapper do
|
17
|
+
assert_equal @musics, @rts.files.sort
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_local_musics
|
22
|
+
usermusic_wrapper do
|
23
|
+
@rts.local << ["test"]
|
24
|
+
@rts.enable_local = true
|
25
|
+
assert_equal [*@musics, "test/dummy.wav"].sort, @rts.files
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_disable_local_musics
|
30
|
+
usermusic_wrapper do
|
31
|
+
@rts.local << ["test"]
|
32
|
+
@rts.enable_local = false
|
33
|
+
assert_equal @musics, @rts.files.sort
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_default_disable_local_musics
|
38
|
+
usermusic_wrapper do
|
39
|
+
@rts.local << ["test"]
|
40
|
+
assert_equal @musics, @rts.files.sort
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "fileutils"
|
3
|
+
require "rubytrackselector"
|
4
|
+
require "testhelper"
|
5
|
+
|
6
|
+
class HomedirTest < Test::Unit::TestCase
|
7
|
+
def test_home
|
8
|
+
assert_equal File.expand_path("~"), RTS.home
|
9
|
+
assert_equal File.join(RTS.home, RTS::RTS_DIR), RTS.user_music
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_no_music_dir
|
13
|
+
usermusic_wrapper do
|
14
|
+
FileUtils.rm_rf(RTS.user_music) rescue nil
|
15
|
+
RTS.user_music(false)
|
16
|
+
assert_equal false, Dir.exists?(RTS.user_music(false))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_has_music_dir
|
21
|
+
usermusic_wrapper do
|
22
|
+
FileUtils.rm_rf(RTS.user_music) rescue nil
|
23
|
+
RTS.user_music(true)
|
24
|
+
assert_equal true, Dir.exists?(RTS.user_music(false))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/test/test_tags.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "fileutils"
|
3
|
+
require "rubytrackselector"
|
4
|
+
require "testhelper"
|
5
|
+
|
6
|
+
class TagTest < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
usermusic_wrapper do
|
9
|
+
FileUtils.rm_rf(RTS.user_music(false)) rescue nil
|
10
|
+
Dir.mkdir(File.join(RTS.user_music, "tag1"))
|
11
|
+
Dir.mkdir(File.join(RTS.user_music, "tag2"))
|
12
|
+
|
13
|
+
@musics = []
|
14
|
+
@musics[0] = generate_musics(RTS.user_music + "/tag1").sort
|
15
|
+
@musics[1] = generate_musics(RTS.user_music + "/tag2").sort
|
16
|
+
@musics[2] = generate_musics.sort
|
17
|
+
@rts = RTS::Rts.new
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_tags
|
22
|
+
usermusic_wrapper do
|
23
|
+
assert_equal @musics[2], @rts.files
|
24
|
+
|
25
|
+
@rts.tag = "tag1"
|
26
|
+
assert_equal @musics[0], @rts.files
|
27
|
+
|
28
|
+
@rts.tag = "tag2"
|
29
|
+
assert_equal @musics[1], @rts.files
|
30
|
+
|
31
|
+
@rts.tag = nil
|
32
|
+
assert_equal @musics[2], @rts.files
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/test/testhelper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
def usermusic_wrapper(new_md = ".rubytrackselector-test-tmp")
|
2
|
+
dummy_stderr = Object.new
|
3
|
+
def dummy_stderr.write(*); end
|
4
|
+
original_stderr = $stderr
|
5
|
+
|
6
|
+
$stderr = dummy_stderr
|
7
|
+
original_md = RTS::RTS_DIR
|
8
|
+
RTS::const_set(:RTS_DIR, new_md)
|
9
|
+
$stderr = original_stderr
|
10
|
+
|
11
|
+
yield
|
12
|
+
|
13
|
+
$stderr = dummy_stderr
|
14
|
+
RTS::const_set(:RTS_DIR, original_md)
|
15
|
+
$stderr = original_stderr
|
16
|
+
end
|
17
|
+
|
18
|
+
def generate_musics(to = nil, n = 5)
|
19
|
+
to ||= RTS.user_music
|
20
|
+
n.times do
|
21
|
+
s = ""
|
22
|
+
20.times { s += (rand('z'.ord - 'a'.ord) + 'a'.ord).chr }
|
23
|
+
s += ".wav"
|
24
|
+
|
25
|
+
FileUtils.cp("test/dummy.wav", File.join(to , s))
|
26
|
+
end
|
27
|
+
return Dir[File.join(to, "*.wav")]
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubytrackselector
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Raphael Robatsch
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-18 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rubygame
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 6
|
30
|
+
version: "2.6"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
description:
|
34
|
+
email: raphaelr@f-m.fm
|
35
|
+
executables: []
|
36
|
+
|
37
|
+
extensions: []
|
38
|
+
|
39
|
+
extra_rdoc_files:
|
40
|
+
- doc/index.rdoc
|
41
|
+
files:
|
42
|
+
- lib/rubytrackselector/home.rb
|
43
|
+
- lib/rubytrackselector/utp.rb
|
44
|
+
- lib/rubytrackselector.rb
|
45
|
+
- test/dummy.wav
|
46
|
+
- test/testhelper.rb
|
47
|
+
- test/test_general.rb
|
48
|
+
- test/test_homedir.rb
|
49
|
+
- test/test_tags.rb
|
50
|
+
- doc/index.rdoc
|
51
|
+
- samples/sample.rb
|
52
|
+
- COPYING
|
53
|
+
- Rakefile
|
54
|
+
- README
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://raphaelr.github.com/rubytrackselector
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
segments:
|
69
|
+
- 1
|
70
|
+
- 8
|
71
|
+
version: "1.8"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.3.6
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: A music selection library for Rubygame.
|
86
|
+
test_files:
|
87
|
+
- test/test_general.rb
|
88
|
+
- test/test_homedir.rb
|
89
|
+
- test/test_tags.rb
|