Skip to content

Commit a46cba4

Browse files
committed
add run lengths in envelope strings; fix #25
1 parent 504401a commit a46cba4

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

docs/pentlyas.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,11 @@ cannot, as it controls the length of the sound effect. Place a
155155
vertical line (`|`, Shift+backslash) before the part of the pitch or
156156
timbre that you want to loop. Otherwise, the last step is looped.
157157

158+
Steps of an envelope are separated by spaces is one word. A step
159+
can be repeated with a colon and an integer: `8:3` means `8 8 8`.
158160
By default, a sound effect plays one step every frame, which is 60
159-
steps per second. But this can be slowed down with `rate 2` through
160-
`rate 16`.
161+
steps per second on NTSC or 50 on PAL. To slow this down, use
162+
`rate 2` through `rate 16`
161163

162164
Sound effect names are exported with the `PE_` prefix, such as
163165
`PE_closed_hihat`. Use these values with `pently_start_sound`.
@@ -174,7 +176,7 @@ Examples:
174176
pitch 10 0
175177

176178
sfx tri_kick on triangle
177-
volume 15 15 15 2 2
179+
volume 15:3 2 2
178180
pitch e' c' a f# e
179181

180182
Drums

src/musicseq.pently

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ sfx quiethat on noise
4343
timbre | 0 1
4444

4545
sfx openhat on noise
46-
volume 6 5 4 4 3 3 3 2 2 2 1 1 1 1 1
46+
volume 6 5 4 4 3:3 2:3 1:5
4747
pitch 12
4848
timbre | 0 1
4949

5050
sfx snarehat on noise
51-
volume 6 5 4 4 3 3 3 2 2 2 1 1 1 1 1
51+
volume 12 10 8 6 3:3 2:3 1:5
5252
pitch 4 10 10 12
5353
timbre 0 0 | 0 1
5454

@@ -81,11 +81,11 @@ sfx stickshatlo on noise
8181
timbre 1
8282

8383
sfx longkick on noise
84-
volume 12 11 10 9 8 7 6 4 3 3 2 2 2 1 1 1 1
84+
volume 12 11 10 9 8 7 6 4 3 3 2:3 1:4
8585
pitch 10 0
8686

8787
sfx longsnare on noise
88-
volume 12 11 10 9 8 7 6 4 3 3 2 2 2 1 1 1 1
88+
volume 12 11 10 9 8 7 6 4 3 3 2:3 1:4
8989
pitch 4 10
9090

9191
drum kick kick
@@ -139,7 +139,7 @@ instrument dut
139139
instrument feat_wah
140140
volume 8 8 7 7 6 6 5 5 5 4 4 4 3
141141
decay 1
142-
timbre 2 2 2 2 2 2 1 1 1 1 1 1 0
142+
timbre 2:6 1:6 0
143143

144144
instrument feat_power
145145
timbre 0
@@ -160,7 +160,7 @@ instrument bf98_osti
160160
detached
161161

162162
instrument orchhit
163-
volume 8 8 8 7 7 7 6 6 6 5 5 5 4 4 4 3 3 3 2 2 2 1 1 1 0
163+
volume 8:3 7:3 6:3 5:3 4:3 3:3 2:3 1:3 0
164164
timbre 1
165165
pitch | 12 0 -12
166166

tools/pentlyas.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,12 +523,28 @@ def set_volume(self, volumes, linenum=None):
523523
raise ValueError("volume steps must be 0 to 15")
524524
self.volume, self.volume_linenum = volumes, linenum
525525

526+
@staticmethod
527+
def expand_runs(words):
528+
if isinstance(words, str):
529+
words = words.split()
530+
words = [word.rsplit(":", 1) for word in words]
531+
# words is [[word], [word, "runlength"], [word], ...]
532+
words = [(word[0], int(word[1]) if len(word) > 1 else 1)
533+
for word in words]
534+
# words is [(word, runlength), ...]
535+
words = [word
536+
for word, runlength in words
537+
for i in range(runlength)]
538+
return words
539+
526540
@staticmethod
527541
def pipesplit(words):
528542
pipesplit = ' '.join(words).split('|', 1)
529-
out = pipesplit[0].split()
543+
pipesplit = [PentlyEnvelopeContainer.expand_runs(part)
544+
for part in pipesplit]
545+
out = pipesplit[0]
530546
if len(pipesplit) > 1:
531-
afterloop = pipesplit[1].split()
547+
afterloop = pipesplit[1]
532548
looplen = len(afterloop)
533549
out.extend(afterloop)
534550
else:
@@ -1430,8 +1446,8 @@ def add_volume(self, words):
14301446
if len(words) < 2:
14311447
raise ValueError("volume requires at least one step")
14321448
obj = self.cur_obj[1]
1433-
obj.set_volume([int(x) for x in words[1:] if x != '|'],
1434-
linenum=self.linenum)
1449+
vols = [int(x) for x in obj.expand_runs(words[1:]) if x != '|']
1450+
obj.set_volume(vols, linenum=self.linenum)
14351451

14361452
def add_decay(self, words):
14371453
self.ensure_in_object('decay', 'instrument')

0 commit comments

Comments
 (0)