Skip to content

Commit

Permalink
fix csd
Browse files Browse the repository at this point in the history
  • Loading branch information
gesellkammer committed Aug 5, 2024
1 parent 360b07b commit 3988fd9
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions csoundengine/csd.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,27 @@ def addInstr(self, instr: int | str, body: str, instrComment='',
self.instrs[instr] = instrdef

def addOpcode(self, name: str, outargs: str, inargs: str, body: str) -> None:
"""
Add an opcode to this csd
Args:
name: the opcode name
outargs: the output arguments
inargs: the input arguments
body: the body of the opcode
Example
~~~~~~~
.. code::
csd.addOpcode("gain", "a", "ak", r'''
asig, kgain xin
asig *=kgain
xout asig
''')
"""
self.opcodes[opcode] = _OpcodeDef(name, outargs=outargs, inargs=inargs, body=body)

def addGlobalCode(self, code: str, acceptDuplicates=True) -> None:
Expand Down Expand Up @@ -974,6 +995,10 @@ def _writeCsd(self, stream, datadir='') -> None:
write("; ----- end global code\n\n")

for name, opcodedef in self.opcodes.items():
write(f"opcode {name}, {opcodedef.outargs}, {opcodedef.inargs}")
body = _textwrap.dedent(opcodedef.body)
write(_textwrap.indent(body, tab))
write("endop\n")

for instr, instrdef in self.instrs.items():
if instrdef.preComment:
Expand Down

0 comments on commit 3988fd9

Please sign in to comment.