Skip to content

Commit

Permalink
add run lengths in envelope strings; fix #25
Browse files Browse the repository at this point in the history
  • Loading branch information
pinobatch committed Dec 25, 2017
1 parent 504401a commit a46cba4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
8 changes: 5 additions & 3 deletions docs/pentlyas.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,11 @@ cannot, as it controls the length of the sound effect. Place a
vertical line (`|`, Shift+backslash) before the part of the pitch or
timbre that you want to loop. Otherwise, the last step is looped.

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

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

sfx tri_kick on triangle
volume 15 15 15 2 2
volume 15:3 2 2
pitch e' c' a f# e

Drums
Expand Down
12 changes: 6 additions & 6 deletions src/musicseq.pently
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ sfx quiethat on noise
timbre | 0 1

sfx openhat on noise
volume 6 5 4 4 3 3 3 2 2 2 1 1 1 1 1
volume 6 5 4 4 3:3 2:3 1:5
pitch 12
timbre | 0 1

sfx snarehat on noise
volume 6 5 4 4 3 3 3 2 2 2 1 1 1 1 1
volume 12 10 8 6 3:3 2:3 1:5
pitch 4 10 10 12
timbre 0 0 | 0 1

Expand Down Expand Up @@ -81,11 +81,11 @@ sfx stickshatlo on noise
timbre 1

sfx longkick on noise
volume 12 11 10 9 8 7 6 4 3 3 2 2 2 1 1 1 1
volume 12 11 10 9 8 7 6 4 3 3 2:3 1:4
pitch 10 0

sfx longsnare on noise
volume 12 11 10 9 8 7 6 4 3 3 2 2 2 1 1 1 1
volume 12 11 10 9 8 7 6 4 3 3 2:3 1:4
pitch 4 10

drum kick kick
Expand Down Expand Up @@ -139,7 +139,7 @@ instrument dut
instrument feat_wah
volume 8 8 7 7 6 6 5 5 5 4 4 4 3
decay 1
timbre 2 2 2 2 2 2 1 1 1 1 1 1 0
timbre 2:6 1:6 0

instrument feat_power
timbre 0
Expand All @@ -160,7 +160,7 @@ instrument bf98_osti
detached

instrument orchhit
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
volume 8:3 7:3 6:3 5:3 4:3 3:3 2:3 1:3 0
timbre 1
pitch | 12 0 -12

Expand Down
24 changes: 20 additions & 4 deletions tools/pentlyas.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,28 @@ def set_volume(self, volumes, linenum=None):
raise ValueError("volume steps must be 0 to 15")
self.volume, self.volume_linenum = volumes, linenum

@staticmethod
def expand_runs(words):
if isinstance(words, str):
words = words.split()
words = [word.rsplit(":", 1) for word in words]
# words is [[word], [word, "runlength"], [word], ...]
words = [(word[0], int(word[1]) if len(word) > 1 else 1)
for word in words]
# words is [(word, runlength), ...]
words = [word
for word, runlength in words
for i in range(runlength)]
return words

@staticmethod
def pipesplit(words):
pipesplit = ' '.join(words).split('|', 1)
out = pipesplit[0].split()
pipesplit = [PentlyEnvelopeContainer.expand_runs(part)
for part in pipesplit]
out = pipesplit[0]
if len(pipesplit) > 1:
afterloop = pipesplit[1].split()
afterloop = pipesplit[1]
looplen = len(afterloop)
out.extend(afterloop)
else:
Expand Down Expand Up @@ -1430,8 +1446,8 @@ def add_volume(self, words):
if len(words) < 2:
raise ValueError("volume requires at least one step")
obj = self.cur_obj[1]
obj.set_volume([int(x) for x in words[1:] if x != '|'],
linenum=self.linenum)
vols = [int(x) for x in obj.expand_runs(words[1:]) if x != '|']
obj.set_volume(vols, linenum=self.linenum)

def add_decay(self, words):
self.ensure_in_object('decay', 'instrument')
Expand Down

0 comments on commit a46cba4

Please sign in to comment.