Skip to content

Commit f540d08

Browse files
committed
Spider - move all path methods to the Paths module
1 parent 8481462 commit f540d08

File tree

11 files changed

+78
-238
lines changed

11 files changed

+78
-238
lines changed

app/server/ruby/bin/qt-doc.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@
8787
"zh_TW" => "臺灣華語" # Chinese (Traditional, Taiwan)
8888
]
8989

90-
FileUtils::rm_rf "#{qt_gui_path}/help/"
91-
FileUtils::mkdir "#{qt_gui_path}/help/"
90+
FileUtils::rm_rf "#{Paths.qt_gui_path}/help/"
91+
FileUtils::mkdir "#{Paths.qt_gui_path}/help/"
9292

93-
FileUtils::rm_rf "#{qt_gui_path}/info/"
94-
FileUtils::mkdir "#{qt_gui_path}/info/"
93+
FileUtils::rm_rf "#{Paths.qt_gui_path}/info/"
94+
FileUtils::mkdir "#{Paths.qt_gui_path}/info/"
9595

96-
FileUtils::rm_rf "#{qt_gui_path}/book/"
97-
FileUtils::mkdir "#{qt_gui_path}/book/"
96+
FileUtils::rm_rf "#{Paths.qt_gui_path}/book/"
97+
FileUtils::mkdir "#{Paths.qt_gui_path}/book/"
9898

9999
docs = []
100100
filenames = []
@@ -172,7 +172,7 @@
172172

173173
filenames << filename
174174

175-
File.open("#{qt_gui_path}/#{filename}", 'w') do |f|
175+
File.open("#{Paths.qt_gui_path}/#{filename}", 'w') do |f|
176176
f << "#{doc}"
177177
end
178178

@@ -197,7 +197,7 @@
197197
book_body = book[/<body.*?>/]
198198
book.gsub!(/<\/?body.*?>/, '')
199199
book.gsub!(/<meta http-equiv.*?>/, '')
200-
File.open("#{qt_gui_path}/book/Sonic Pi - #{name.capitalize}" + (lang != "en" ? " (#{lang})" : "") + ".html", 'w') do |f|
200+
File.open("#{Paths.qt_gui_path}/book/Sonic Pi - #{name.capitalize}" + (lang != "en" ? " (#{lang})" : "") + ".html", 'w') do |f|
201201
f << "<link rel=\"stylesheet\" href=\"../theme/light/doc-styles.css\" type=\"text/css\"/>\n"
202202
f << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n\n"
203203
f << book_body << "\n"
@@ -218,9 +218,9 @@
218218
docs << "\n // language #{lang}\n"
219219
tutorial_html_map = {}
220220
if lang == "en" then
221-
markdown_path = tutorial_path
221+
markdown_path = Paths.tutorial_path
222222
else
223-
markdown_path = File.expand_path("../generated/#{lang}/tutorial", tutorial_path)
223+
markdown_path = File.expand_path("../generated/#{lang}/tutorial", Paths.tutorial_path)
224224
end
225225
Dir["#{markdown_path}/*.md"].sort.each do |path|
226226
f = File.open(path, 'r:UTF-8')
@@ -241,7 +241,7 @@
241241
example_html_map = {}
242242
example_dirs = ["Apprentice", "Illusionist", "Magician", "Sorcerer", "Wizard", "Algomancer"]
243243
example_dirs.each do |ex_dir|
244-
Dir["#{examples_path}/#{ex_dir.downcase}/*.rb"].sort.each do |path|
244+
Dir["#{Paths.examples_path}/#{ex_dir.downcase}/*.rb"].sort.each do |path|
245245
bname = File.basename(path, ".rb")
246246
bname = ActiveSupport::Inflector.titleize(bname)
247247
name = "[#{ex_dir}] #{bname}"
@@ -269,7 +269,7 @@
269269
# before the generic language code,
270270
# e.g., "de_CH" should be handled before "de"
271271
languages =
272-
Dir[File.expand_path("../lang/sonic-pi-tutorial-*.po", tutorial_path)].
272+
Dir[File.expand_path("../lang/sonic-pi-tutorial-*.po", Paths.tutorial_path)].
273273
map { |p| File.basename(p).gsub(/sonic-pi-tutorial-(.*?).po/, '\1') }.
274274
sort_by {|n| [-n.length, n]}
275275

@@ -338,7 +338,7 @@ def generate_ui_lang_names
338338
locale_arrays << "\n};\n"
339339

340340
# Write the map to lang_list.h
341-
content = File.readlines("#{qt_gui_path}/utils/lang_list.tmpl")
341+
content = File.readlines("#{Paths.qt_gui_path}/utils/lang_list.tmpl")
342342
lang_names_generated = content.take_while { |line| !line.start_with?("// AUTO-GENERATED")}
343343
lang_names_generated << "// AUTO-GENERATED HEADER FILE\n"
344344
lang_names_generated << "// Do not add any code to this file\n"
@@ -350,7 +350,7 @@ def generate_ui_lang_names
350350
lang_names_generated << locale_arrays.join()
351351
lang_names_generated << "#endif\n"
352352

353-
File.open("#{qt_gui_path}/utils/lang_list.h", 'w') do |f|
353+
File.open("#{Paths.qt_gui_path}/utils/lang_list.h", 'w') do |f|
354354
f << lang_names_generated.join()
355355
end
356356
end
@@ -360,7 +360,7 @@ def generate_ui_lang_names
360360
if options[:output_name] then
361361
cpp = options[:output_name]
362362
else
363-
cpp = "#{qt_gui_path}/ruby_help.h"
363+
cpp = "#{Paths.qt_gui_path}/ruby_help.h"
364364
end
365365

366366
content = File.readlines(cpp)
@@ -377,7 +377,7 @@ def generate_ui_lang_names
377377
f << new_content.join
378378
end
379379

380-
File.open("#{qt_gui_path}/help_files.qrc", 'w') do |f|
380+
File.open("#{Paths.qt_gui_path}/help_files.qrc", 'w') do |f|
381381
f << "<RCC>\n <qresource prefix=\"/\">\n"
382382
f << filenames.map{|n| " <file>#{n}</file>\n"}.join
383383
f << " </qresource>\n</RCC>\n"
@@ -389,7 +389,7 @@ def generate_ui_lang_names
389389
###
390390

391391
info_sources = ["CHANGELOG.md", "CONTRIBUTORS.md", "COMMUNITY.md", "CORETEAM.html", "LICENSE.md"]
392-
outputdir = "#{qt_gui_path}/info"
392+
outputdir = "#{Paths.qt_gui_path}/info"
393393

394394
info_sources.each do |src|
395395

app/server/ruby/bin/sonic-pi-server.rb

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818

1919
require_relative "../core.rb"
20+
require_relative "../paths"
2021
require_relative "../lib/sonicpi/studio"
2122

2223
require_relative "../lib/sonicpi/server"
@@ -41,13 +42,19 @@
4142
STDOUT.puts "The time is #{Time.now}"
4243

4344
## Ensure ~/.sonic-pi/* user config, history and setting directories exist
44-
[home_dir_path, project_path, log_path, cached_samples_path, config_path, system_store_path].each do |d|
45+
[ SonicPi::Paths.home_dir_path,
46+
SonicPi::Paths.project_path,
47+
SonicPi::Paths.log_path,
48+
SonicPi::Paths.cached_samples_path,
49+
SonicPi::Paths.config_path,
50+
SonicPi::Paths.system_store_path
51+
].each do |d|
4552
ensure_dir(d)
4653
end
4754

4855
## Just check to see if the user still has an old settings.json and if
4956
## so, remove it. This is now stored in system_cache_store_path
50-
old_settings_file_path = File.absolute_path("#{home_dir_path}/settings.json")
57+
old_settings_file_path = File.absolute_path("#{SonicPi::Paths.home_dir_path}/settings.json")
5158
File.delete(old_settings_file_path) if File.exist?(old_settings_file_path)
5259

5360
## Move across any config example files if they don't
@@ -56,12 +63,12 @@
5663

5764

5865
begin
59-
if File.exists?(original_init_path)
60-
if (File.exists?(init_path))
61-
STDOUT.puts "Warning, you have an older init.rb file in #{original_init_path} which is now being ignored as your newer config/init.rb file is being used instead. Consider deleting your old init.rb (perhaps copying anything useful across first)."
66+
if File.exists?(SonicPi::Paths.original_init_path)
67+
if (File.exists?(SonicPi::Paths.init_path))
68+
STDOUT.puts "Warning, you have an older init.rb file in #{SonicPi::Paths.original_init_path} which is now being ignored as your newer config/init.rb file is being used instead. Consider deleting your old init.rb (perhaps copying anything useful across first)."
6269
else
63-
STDOUT.puts "Found init.rb in old location #{original_init_path}. Moving it to the new config directory #{init_path}."
64-
FileUtils.mv(original_init_path, init_path)
70+
STDOUT.puts "Found init.rb in old location #{SonicPi::Paths.original_init_path}. Moving it to the new config directory #{SonicPi::Paths.init_path}."
71+
FileUtils.mv(SonicPi::Paths.original_init_path, init_path)
6572
end
6673
end
6774
rescue Exception => e
@@ -75,9 +82,9 @@
7582

7683

7784

78-
Dir["#{user_config_examples_path}/*"].each do |f|
85+
Dir["#{SonicPi::Paths.user_config_examples_path}/*"].each do |f|
7986
basename = File.basename(f)
80-
full_config_path = File.absolute_path("#{config_path}/#{basename}")
87+
full_config_path = File.absolute_path("#{SonicPi::Paths.config_path}/#{basename}")
8188
unless File.exist?(full_config_path)
8289
FileUtils.cp(f, full_config_path)
8390
end
@@ -277,10 +284,10 @@
277284
STDOUT.puts "Spider - Runtime Server Initialised"
278285
STDOUT.flush
279286
# read in init.rb if exists
280-
if File.exists?(init_path)
281-
sp.__spider_eval(File.read(init_path), silent: true)
287+
if File.exists?(SonicPi::Paths.init_path)
288+
sp.__spider_eval(File.read(SonicPi::Paths.init_path), silent: true)
282289
else
283-
STDOUT.puts "Spider - Could not find init.rb file: #{init_path} "
290+
STDOUT.puts "Spider - Could not find init.rb file: #{SonicPi::Paths.init_path} "
284291
end
285292

286293
sp.__print_boot_messages

app/server/ruby/lib/sonicpi/lang/core.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4782,7 +4782,7 @@ def load_buffer(path)
47824782

47834783

47844784
def load_example(example_name)
4785-
path = Dir[examples_path + '/**/' + example_name.to_s + '.rb'].first
4785+
path = Dir[Paths.examples_path + '/**/' + example_name.to_s + '.rb'].first
47864786
raise IOError, "Error - no example found with name: #{example_name.inspect}" unless path
47874787
buf = __current_job_info[:workspace]
47884788
__info "loading #{buf} with #{path}"

app/server/ruby/lib/sonicpi/lang/sound.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def self.included(base)
7878

7979
@sample_paths_cache = {}
8080

81-
@sample_loader = SampleLoader.new("#{samples_path}/**")
81+
@sample_loader = SampleLoader.new("#{Paths.samples_path}/**")
8282

8383
@job_groups = {}
8484
@job_group_mutex = Mutex.new
@@ -3279,7 +3279,7 @@ def fx_names
32793279
examples: []
32803280

32813281

3282-
def load_synthdefs(path=synthdef_path)
3282+
def load_synthdefs(path=Paths.synthdef_path)
32833283
path = File.expand_path(path)
32843284
raise "No directory exists called #{path.inspect}" unless File.exist? path
32853285
@mod_sound_studio.load_synthdefs(path)

app/server/ruby/lib/sonicpi/runtime.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module RuntimeMethods
5252
## Probably should be moved somewhere else
5353
@@stop_job_mutex = Mutex.new
5454

55-
def load_snippets(path=snippets_path, quiet=false)
55+
def load_snippets(path=Paths.snippets_path, quiet=false)
5656
path = File.expand_path(path)
5757
Dir["#{path}/**/*.sps"].each do |p|
5858

@@ -265,10 +265,10 @@ def __gui_heartbeat(id)
265265
end
266266

267267
def __extract_git_hash
268-
head_path = root_path + "/.git/HEAD"
268+
head_path = Paths.root_path + "/.git/HEAD"
269269
if File.exist? head_path
270270
ref = File.readlines(head_path).first
271-
ref_path = root_path + "/.git/" + ref[5..-1]
271+
ref_path = Paths.root_path + "/.git/" + ref[5..-1]
272272
ref_path = ref_path.strip
273273
if File.exist? ref_path
274274
return File.readlines(ref_path).first
@@ -568,7 +568,7 @@ def __stop_other_jobs
568568
def __load_buffer(id)
569569
id = id.to_s
570570
raise "Aborting load: file name is blank" if id.empty?
571-
path = project_path + id + '.spi'
571+
path = File.expand_path("#{Paths.project_path}/#{id}.spi")
572572
s = "# Welcome to Sonic Pi\n\n"
573573
if File.exist? path
574574
s = IO.read(path)
@@ -1408,7 +1408,7 @@ def initialize(ports, msg_queue, user_methods)
14081408
@ports = ports
14091409
@git_hash = __extract_git_hash
14101410
gh_short = @git_hash ? "-#{@git_hash[0, 5]}" : ""
1411-
@settings = Config::Settings.new(system_cache_store_path)
1411+
@settings = Config::Settings.new(Paths.system_cache_store_path)
14121412
# @scsynth_clobber_args = @audio_settings.scsynth_opts_override
14131413
# @scsynth_opts = @audio_settings.scsynth_opts
14141414
@version = Version.new(4, 0, 0, "beta1")
@@ -1495,7 +1495,7 @@ def initialize(ports, msg_queue, user_methods)
14951495
@gui_heartbeats = {}
14961496
@gui_last_heartbeat = nil
14971497
begin
1498-
@gitsave = GitSave.new(project_path)
1498+
@gitsave = GitSave.new(Paths.project_path)
14991499
rescue
15001500
@gitsave = nil
15011501
end
@@ -1507,7 +1507,7 @@ def initialize(ports, msg_queue, user_methods)
15071507
event = @save_queue.pop
15081508
id, content = *event
15091509
filename = id + '.spi'
1510-
path = project_path + "/" + filename
1510+
path = File.expand_path("#{Paths.project_path}/#{filename}")
15111511
content = filter_for_save(content)
15121512
begin
15131513
File.open(path, 'w') {|f| f.write(content) }
@@ -1527,11 +1527,11 @@ def initialize(ports, msg_queue, user_methods)
15271527
__info "Initialised Erlang OSC Scheduler"
15281528

15291529
if safe_mode?
1530-
__info "!!WARNING!! - file permissions issue:\n Unable to write to folder #{home_dir_path} \n Booting in SAFE MODE.\n Buffer auto-saving is disabled, please save your work manually.", 1
1530+
__info "!!WARNING!! - file permissions issue:\n Unable to write to folder #{Paths.home_dir_path} \n Booting in SAFE MODE.\n Buffer auto-saving is disabled, please save your work manually.", 1
15311531
end
15321532

1533-
log "Unable to initialise git repo at #{project_path}" unless @gitsave
1534-
load_snippets(snippets_path, true)
1533+
log "Unable to initialise git repo at #{Paths.project_path}" unless @gitsave
1534+
load_snippets(Paths.snippets_path, true)
15351535
end
15361536

15371537
def __print_boot_messages

app/server/ruby/lib/sonicpi/samplebuffer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def onset_data
102102
# [:minioi_ms] 12.0 (ms)
103103

104104
begin
105-
aubio_onsets_command = "\"#{aubio_onset_path}\" \"#{@path}\""
105+
aubio_onsets_command = "\"#{Paths.aubio_onset_path}\" \"#{@path}\""
106106
onsets_str = `#{aubio_onsets_command}`
107107
onsets = onsets_str.split.map(&:to_f)
108108
rescue Exception => e

app/server/ruby/lib/sonicpi/server.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def initialize(port, msg_queue, state, register_cue_event_lambda, current_spider
109109
add_event_oneshot_handler("/sonic-pi/server-info") do |payload|
110110
info_prom.deliver! payload
111111
end
112-
load_synthdefs(synthdef_path)
112+
load_synthdefs(Paths.synthdef_path)
113113
osc @osc_path_s_new, "sonic-pi-server-info", 1, 0, 0
114114
server_info = info_prom.get
115115
@scsynth_info = SonicPi::Core::SPMap.new({

app/server/ruby/lib/sonicpi/sox.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ module Sox
2020

2121
def self.info(path)
2222
# Some sox commands print out to std err?!
23-
info_out, info_err = Open3.capture3("'#{sox_path}' --info '#{path}'")
24-
stat_out, stat_err = Open3.capture3("'#{sox_path}' '#{path}' -n stat")
23+
info_out, info_err = Open3.capture3("'#{Paths.sox_path}' --info '#{path}'")
24+
stat_out, stat_err = Open3.capture3("'#{Paths.sox_path}' '#{path}' -n stat")
2525
res = {}
2626
(info_out.lines + info_err.lines + stat_out.lines + stat_err.lines).each do |l|
2727
m = l.match(/\A(.+?)\s*:\s+(.*)\Z/)

app/server/ruby/lib/sonicpi/studio.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def init_scsynth
6969
end
7070

7171
def init_studio
72-
@server.load_synthdefs(synthdef_path)
72+
@server.load_synthdefs(Paths.synthdef_path)
7373
@amp = [0.0, 1.0]
7474
@server.add_event_handler("/sonic-pi/amp", "/sonic-pi/amp") do |payload|
7575
@amp = [payload[2], payload[3]]
@@ -84,7 +84,7 @@ def init_studio
8484
end
8585

8686
# load rand stream directly - ensuring it doesn't get considered as a 'sample'
87-
rand_buf = @server.buffer_alloc_read(buffers_path + "/rand-stream.wav")
87+
rand_buf = @server.buffer_alloc_read(Paths.buffers_path + "/rand-stream.wav")
8888

8989
@sample_sem.synchronize do
9090
@buffers = {}
@@ -141,7 +141,7 @@ def allocate_buffer(name, duration_in_seconds)
141141

142142
# our buffer has the same name but is of a different duration
143143
# therefore nuke it
144-
path = cached_samples_path + "/#{name}.wav"
144+
path = Paths.cached_samples_path + "/#{name}.wav"
145145
# now actually allocate a new buffer and cache it
146146
sample_rate = @server.scsynth_info[:sample_rate]
147147
buffer_info = @server.buffer_alloc(duration_in_seconds * sample_rate, 2)

0 commit comments

Comments
 (0)