Skip to content

Commit cc20b37

Browse files
committed
Server - begin DSL and synth/fx documentation templating
1 parent 81fc206 commit cc20b37

File tree

6 files changed

+688
-0
lines changed

6 files changed

+688
-0
lines changed

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env ruby
2+
#--
3+
# This file is part of Sonic Pi: http://sonic-pi.net
4+
# Full project source: https://github.com/samaaron/sonic-pi
5+
# License: https://github.com/samaaron/sonic-pi/blob/main/LICENSE.md
6+
#
7+
# Copyright 2013, 2014, 2015, 2016 by Sam Aaron (http://sam.aaron.name).
8+
# All rights reserved.
9+
#
10+
# Permission is granted for use, copying, modification, and
11+
# distribution of modified versions of this work as long as this
12+
# notice is included.
13+
#++
14+
15+
require 'cgi'
16+
require 'optparse'
17+
require 'fileutils'
18+
19+
require_relative "../core.rb"
20+
require_relative "../lib/sonicpi/lang/support/docsystem"
21+
require_relative "../lib/sonicpi/synths/synthinfo"
22+
require_relative "../lib/sonicpi/util"
23+
require_relative "../lib/sonicpi/runtime"
24+
require_relative "../lib/sonicpi/lang/core"
25+
require_relative "../lib/sonicpi/lang/sound"
26+
require_relative "../lib/sonicpi/lang/minecraftpi"
27+
require_relative "../lib/sonicpi/lang/midi"
28+
require 'active_support/inflector'
29+
require 'erb'
30+
require 'gettext'
31+
require "gettext/tools/xgettext"
32+
33+
34+
class QtDocs
35+
include SonicPi::Lang::Support::DocSystem
36+
include SonicPi::Util
37+
include GetText
38+
39+
def run
40+
# _generate_lang_docs
41+
_generate_synth_docs
42+
end
43+
44+
def t_(arg)
45+
"<%= _(\"#{arg}\") %>"
46+
end
47+
48+
private
49+
def _generate_lang_docs
50+
_generate_docs(@@docs, lang_template_path, lang_toml_path)
51+
end
52+
53+
def _generate_synth_docs
54+
collection = SonicPi::Synths::SynthInfo.get_all.select do |k, v|
55+
v.is_a?(SonicPi::Synths::SynthInfo) && v.user_facing?
56+
end
57+
_generate_docs(
58+
collection,
59+
synth_and_fx_template_path,
60+
synth_toml_path,
61+
SonicPi::Synths::SynthInfo
62+
)
63+
end
64+
65+
def _generate_docs(collection, template_path, output_path, klass = nil)
66+
original_template = File.read(template_path)
67+
collection.to_a.take(2).map do |key, item|
68+
template = ERB.new(original_template).result(binding)
69+
interpolated_path = "#{interpolated_template_path}/#{key}.toml.erb"
70+
File.open(interpolated_path, 'w') do |f|
71+
f.write template
72+
end
73+
74+
GetText::Tools::XGetText.run(
75+
interpolated_path,
76+
"-o ../../../../../../etc/doc/generated/toml/synths/test.pot"
77+
)
78+
end
79+
end
80+
end
81+
82+
QtDocs.new.run
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
<%= _("# This is a data file that contains information describing the text that is
2+
# displayed on pages in the Synths section of Sonic Pi's help panel.
3+
4+
# A unique identifier for this synth or fx, the word that is typed in the code
5+
# to use it.
6+
# (For example: :pretty_bell).
7+
") %>
8+
[:dull_bell]
9+
10+
<%= _("# A word or short phrase that is used as a label for the synth or fx.
11+
# (For example: Pretty Bell).
12+
") %>
13+
name = "<%= _("Dull Bell") %>"
14+
15+
<%= _("# A basic code example of how to use the synth or fx.") %>
16+
usage = '''
17+
use_synth :dull_bell
18+
'''
19+
20+
<%= _("# The detailed description of the synth or fx.") %>
21+
doc = '''
22+
<%= _("A simple dull discordant bell sound.") %>
23+
'''
24+
25+
<%= _("# The label describing the version of Sonic Pi in which this synth or fx first
26+
# appeared.
27+
") %>
28+
[:dull_bell.introduced]
29+
label = "<%= _("Introduced in v2.0") %>"
30+
31+
<%= _("# The options are the opts of this synth or fx.
32+
# In the documentation, we currently display two table of opts:
33+
# - one listing the name of each opt and its default value for easy reference
34+
# - a second, more detailed table labelled 'Options', containing:
35+
# - the name of each opt
36+
# - a detailed description of it
37+
# - its default value
38+
# - (if the opt has constraints (limits or range of permitted values, etc):
39+
# the constraints of the opt
40+
# - a label describing whether this opt can be modulated (altered) while the
41+
# synth or fx is running
42+
# - (if the opt is slidable): a label indicating that the opt is slidable
43+
") %>
44+
[:dull_bell.options]
45+
label = "<%= _("Options") %>"
46+
47+
[[:dull_bell.options.list]]
48+
name = "note:"
49+
doc = "<%= _("Note to play. Either a MIDI number or a symbol representing a note. For example: `30`, `52`, `:C`, `:C2`, `:Eb4`, or `:Ds3`") %>"
50+
default_value = "52"
51+
52+
constraints = '''
53+
<%= _("Must be zero or greater") %>
54+
'''
55+
56+
modulatable = '''
57+
<%= _("May be changed whilst playing") %>
58+
'''
59+
60+
[[:dull_bell.options.list]]
61+
name = "amp:"
62+
doc = "<%= _("The amplitude of the sound. Typically a value between 0 and 1. Higher amplitudes may be used, but won't make the sound louder, they will just reduce the quality of all the sounds currently being played (due to compression.)") %>"
63+
default_value = "1"
64+
65+
constraints = '''
66+
<%= _("Must be zero or greater") %>
67+
'''
68+
69+
modulatable = '''
70+
<%= _("May be changed whilst playing") %>
71+
'''
72+
73+
[[:dull_bell.options.list]]
74+
name = "pan:"
75+
doc = "<%= _("Position of sound in stereo. With headphones on, this means how much of the sound is in the left ear, and how much is in the right ear. With a value of -1, the sound is completely in the left ear, a value of 0 puts the sound equally in both ears and a value of 1 puts the sound in the right ear. Values in between -1 and 1 move the sound accordingly.") %>"
76+
default_value = "0"
77+
78+
constraints = '''
79+
<%= _("Must be a value between -1 and 1 inclusively") %>
80+
'''
81+
82+
modulatable = '''
83+
<%= _("May be changed whilst playing") %>
84+
'''
85+
86+
[[:dull_bell.options.list]]
87+
name = "attack:"
88+
doc = "<%= _("Amount of time (in beats) for sound to reach full amplitude (attack_level). A short attack (i.e. 0.01) makes the initial part of the sound very percussive like a sharp tap. A longer attack (i.e 1) fades the sound in gently. Full length of sound is attack + decay + sustain + release.") %>"
89+
default_value = "0"
90+
91+
constraints = '''
92+
<%= _("Must be zero or greater") %>
93+
'''
94+
95+
modulatable = '''
96+
<%= _("Can not be changed once set") %>
97+
'''
98+
99+
[[:dull_bell.options.list]]
100+
name = "decay:"
101+
doc = "<%= _("Amount of time (in beats) for the sound to move from full amplitude (attack_level) to the sustain amplitude (sustain_level).") %>"
102+
default_value = "0"
103+
104+
constraints = '''
105+
<%= _("Must be zero or greater") %>
106+
'''
107+
108+
modulatable = '''
109+
<%= _("Can not be changed once set") %>
110+
'''
111+
112+
[[:dull_bell.options.list]]
113+
name = "sustain:"
114+
doc = "<%= _("Amount of time (in beats) for sound to remain at sustain level amplitude. Longer sustain values result in longer sounds. Full length of sound is attack + decay + sustain + release.") %>"
115+
default_value = "0"
116+
117+
constraints = '''
118+
<%= _("Must be zero or greater") %>
119+
'''
120+
121+
modulatable = '''
122+
<%= _("Can not be changed once set") %>
123+
'''
124+
125+
[[:dull_bell.options.list]]
126+
name = "release:"
127+
doc = "<%= _("Amount of time (in beats) for sound to move from sustain level amplitude to silent. A short release (i.e. 0.01) makes the final part of the sound very percussive (potentially resulting in a click). A longer release (i.e 1) fades the sound out gently. Full length of sound is attack + decay + sustain + release.") %>"
128+
default_value = "1"
129+
130+
constraints = '''
131+
<%= _("Must be zero or greater") %>
132+
'''
133+
134+
modulatable = '''
135+
<%= _("Can not be changed once set") %>
136+
'''
137+
138+
[[:dull_bell.options.list]]
139+
name = "attack_level:"
140+
doc = "<%= _("Amplitude level reached after attack phase and immediately before decay phase") %>"
141+
default_value = "1"
142+
143+
constraints = '''
144+
<%= _("Must be zero or greater") %>
145+
'''
146+
147+
modulatable = '''
148+
<%= _("Can not be changed once set") %>
149+
'''
150+
151+
[[:dull_bell.options.list]]
152+
name = "decay_level:"
153+
doc = "<%= _("Amplitude level reached after decay phase and immediately before sustain phase. Defaults to sustain_level unless explicitly set") %>"
154+
default_value = "sustain_level"
155+
156+
constraints = '''
157+
<%= _("Must be zero or greater") %>
158+
'''
159+
160+
modulatable = '''
161+
<%= _("Can not be changed once set") %>
162+
'''
163+
164+
[[:dull_bell.options.list]]
165+
name = "sustain_level:"
166+
doc = "<%= _("Amplitude level reached after decay phase and immediately before release phase.") %>"
167+
default_value = "1"
168+
169+
constraints = '''
170+
<%= _("Must be zero or greater") %>
171+
'''
172+
173+
modulatable = '''
174+
<%= _("Can not be changed once set") %>
175+
'''
176+
177+
[[:dull_bell.options.list]]
178+
name = "env_curve:"
179+
doc = "<%= _("Select the shape of the curve between levels in the envelope. 1=linear, 2=exponential, 3=sine, 4=welch, 6=squared, 7=cubed") %>"
180+
default_value = "2"
181+
182+
constraints = '''
183+
<%= _("Must be one of the following values: [1, 2, 3, 4, 6, 7]") %>
184+
'''
185+
186+
modulatable = '''
187+
<%= _("Can not be changed once set") %>
188+
'''
189+
190+
191+
[sliding]
192+
slide_label = "Slide Options"
193+
slide_description = '''
194+
Any parameter that is slidable has three additional options named _slide,
195+
slide_curve, and _slide_shape. For example, 'amp' is slidable, so you can also
196+
set amp_slide, amp_slide_curve, and amp_slide_shape with the following effects:
197+
'''
198+
199+
200+
[[sliding.slide_opts]]
201+
name = "_slide"
202+
default = "0"
203+
doc = '''
204+
Amount of time (in beats) for the parameter value to change. A long parameter_slide value means that the parameter takes a long time to slide from the previous value to the new value. A parameter_slide of 0 means that the parameter instantly changes to the new value.
205+
'''
206+
207+
[[sliding.slide_opts]]
208+
name = "_slide_shape"
209+
default = "5"
210+
doc = '''
211+
Shape of curve. 0: step, 1: linear, 3: sine, 4: welch, 5: custom (use *_slide_curve: opt e.g. amp_slide_curve:), 6: squared, 7: cubed.
212+
'''
213+
214+
[[sliding.slide_opts]]
215+
name = "_slide_curve"
216+
default = "0"
217+
doc = '''
218+
Shape of the slide curve (only honoured if slide shape is 5). 0 means linear and positive and negative numbers curve the segment up and down respectively.
219+
'''
220+
221+

0 commit comments

Comments
 (0)