From d0ae3caca5828675335d3b19ab5dd987e7369b23 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 14 Jul 2004 16:21:44 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r1857, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/tb/; revision=1858 --- sc4pd/build-max-msvc.bat | 4 + sc4pd/build-pd-bcc.bat | 3 + sc4pd/build-pd-cygwin.sh | 15 + sc4pd/build-pd-darwin.sh | 17 + sc4pd/build-pd-linux.sh | 17 + sc4pd/build-pd-mingw.bat | 3 + sc4pd/build-pd-msvc.bat | 4 + sc4pd/config-max-msvc.txt | 27 + sc4pd/config-pd-bcc.txt | 23 + sc4pd/config-pd-cygwin.txt | 35 + sc4pd/config-pd-darwin.txt | 35 + sc4pd/config-pd-linux.txt | 37 + sc4pd/config-pd-mingw.txt | 35 + sc4pd/config-pd-msvc.txt | 19 + sc4pd/headers/app/AIAttributedStringAdditions.h | 39 + sc4pd/headers/app/AIColorAdditions.h | 39 + sc4pd/headers/app/AIHTMLDecoder.h | 28 + sc4pd/headers/app/AIStringAdditions.h | 25 + sc4pd/headers/app/AITextAttributes.h | 44 ++ sc4pd/headers/app/ChangeCounter.h | 30 + sc4pd/headers/app/ControlSpec.h | 36 + sc4pd/headers/app/DrawBackground.h | 83 +++ sc4pd/headers/app/GetStringFromUser.h | 46 ++ sc4pd/headers/app/GoToPanel.h | 52 ++ sc4pd/headers/app/MyDocument.h | 107 +++ sc4pd/headers/app/RendezvousClient.h | 39 + sc4pd/headers/app/SCDialog.h | 41 ++ sc4pd/headers/app/SCGeom.h | 90 +++ sc4pd/headers/app/SCGraphView.h | 55 ++ sc4pd/headers/app/SCService.h | 16 + sc4pd/headers/app/SCTextView.h | 33 + sc4pd/headers/app/SCView.h | 784 +++++++++++++++++++++ sc4pd/headers/app/SCVirtualMachine.h | 65 ++ sc4pd/headers/app/TabletEvents.h | 75 ++ sc4pd/headers/app/TextFinder.h | 64 ++ sc4pd/headers/app/UserPanel.h | 40 ++ sc4pd/headers/common/SC_AllocPool.h | 278 ++++++++ sc4pd/headers/common/SC_Altivec.h | 118 ++++ sc4pd/headers/common/SC_Endian.h | 64 ++ sc4pd/headers/common/SC_Sem.h | 43 ++ sc4pd/headers/common/SC_StringBuffer.h | 67 ++ sc4pd/headers/common/SC_StringParser.h | 40 ++ sc4pd/headers/common/dfftlib.h | 62 ++ sc4pd/headers/common/dlfcn.h | 44 ++ sc4pd/headers/common/fftlib.h | 62 ++ sc4pd/headers/common/scsynthsend.h | 191 +++++ sc4pd/headers/lang/AdvancingAllocPool.h | 82 +++ sc4pd/headers/lang/AllocPools.h | 34 + sc4pd/headers/lang/ByteCodeArray.h | 50 ++ sc4pd/headers/lang/FIFOT.h | 75 ++ sc4pd/headers/lang/GC.h | 263 +++++++ sc4pd/headers/lang/HashTable.h | 274 +++++++ sc4pd/headers/lang/InitAlloc.h | 32 + sc4pd/headers/lang/MiscInlineMath.h | 54 ++ sc4pd/headers/lang/OSCData.h | 1 + sc4pd/headers/lang/Opcodes.h | 426 +++++++++++ sc4pd/headers/lang/PowerOfTwoAllocPool.h | 154 ++++ sc4pd/headers/lang/PredefinedSymbols.h | 29 + sc4pd/headers/lang/PriorityQueue.h | 90 +++ sc4pd/headers/lang/PyrArchiverT.h | 619 ++++++++++++++++ sc4pd/headers/lang/PyrDeepCopier.h | 221 ++++++ sc4pd/headers/lang/PyrDeepFreezer.h | 178 +++++ sc4pd/headers/lang/PyrErrors.h | 49 ++ sc4pd/headers/lang/PyrFilePrim.h | 62 ++ sc4pd/headers/lang/PyrFileUtils.h | 50 ++ sc4pd/headers/lang/PyrInterpreter.h | 47 ++ sc4pd/headers/lang/PyrKernel.h | 256 +++++++ sc4pd/headers/lang/PyrKernelProto.h | 62 ++ sc4pd/headers/lang/PyrLexer.h | 136 ++++ sc4pd/headers/lang/PyrListPrim.h | 34 + sc4pd/headers/lang/PyrMathPrim.h | 51 ++ sc4pd/headers/lang/PyrMessage.h | 55 ++ sc4pd/headers/lang/PyrObject.h | 288 ++++++++ sc4pd/headers/lang/PyrObjectProto.h | 44 ++ sc4pd/headers/lang/PyrParseNode.h | 456 ++++++++++++ sc4pd/headers/lang/PyrPrimitive.h | 42 ++ sc4pd/headers/lang/PyrPrimitiveProto.h | 81 +++ sc4pd/headers/lang/PyrSched.h | 58 ++ sc4pd/headers/lang/PyrSignal.h | 417 +++++++++++ sc4pd/headers/lang/PyrSignalPrim.h | 56 ++ sc4pd/headers/lang/PyrSlot.h | 286 ++++++++ sc4pd/headers/lang/PyrSymbol.h | 59 ++ sc4pd/headers/lang/PyrSymbolTable.h | 78 ++ sc4pd/headers/lang/ReadWriteMacros.h | 336 +++++++++ sc4pd/headers/lang/SCBase.h | 68 ++ sc4pd/headers/lang/SC_ComPort.h | 118 ++++ sc4pd/headers/lang/SC_LanguageClient.h | 164 +++++ sc4pd/headers/lang/SC_LibraryConfig.h | 108 +++ sc4pd/headers/lang/SC_List.h | 229 ++++++ sc4pd/headers/lang/SC_LogFile.h | 29 + sc4pd/headers/lang/SC_Msg.h | 70 ++ sc4pd/headers/lang/SC_SynthImpl.h | 42 ++ sc4pd/headers/lang/SC_TerminalClient.h | 92 +++ sc4pd/headers/lang/SC_UnorderedList.h | 60 ++ sc4pd/headers/lang/SFHeaders.h | 1 + sc4pd/headers/lang/Samp.h | 46 ++ sc4pd/headers/lang/SimpleStack.h | 32 + sc4pd/headers/lang/VMGlobals.h | 94 +++ sc4pd/headers/lang/bullet.h | 7 + sc4pd/headers/lang/libraryConfig.h | 31 + sc4pd/headers/lang/readSamples.h | 1 + sc4pd/headers/plugin_interface/Hash.h | 152 ++++ sc4pd/headers/plugin_interface/SC_BoundsMacros.h | 29 + sc4pd/headers/plugin_interface/SC_BufGen.h | 40 ++ sc4pd/headers/plugin_interface/SC_Constants.h | 46 ++ sc4pd/headers/plugin_interface/SC_DemandUnit.h | 54 ++ sc4pd/headers/plugin_interface/SC_Dimension.h | 31 + sc4pd/headers/plugin_interface/SC_FifoMsg.h | 59 ++ sc4pd/headers/plugin_interface/SC_Graph.h | 53 ++ sc4pd/headers/plugin_interface/SC_InlineBinaryOp.h | 574 +++++++++++++++ sc4pd/headers/plugin_interface/SC_InlineUnaryOp.h | 448 ++++++++++++ sc4pd/headers/plugin_interface/SC_InterfaceTable.h | 175 +++++ sc4pd/headers/plugin_interface/SC_Node.h | 48 ++ sc4pd/headers/plugin_interface/SC_PlugIn.h | 53 ++ sc4pd/headers/plugin_interface/SC_RGen.h | 288 ++++++++ sc4pd/headers/plugin_interface/SC_Rate.h | 42 ++ sc4pd/headers/plugin_interface/SC_SndBuf.h | 109 +++ sc4pd/headers/plugin_interface/SC_Types.h | 67 ++ sc4pd/headers/plugin_interface/SC_Unit.h | 101 +++ sc4pd/headers/plugin_interface/SC_Wire.h | 36 + sc4pd/headers/plugin_interface/SC_World.h | 105 +++ sc4pd/headers/plugin_interface/SC_WorldOptions.h | 91 +++ sc4pd/headers/plugin_interface/Unroll.h | 249 +++++++ sc4pd/headers/plugin_interface/clz.h | 195 +++++ sc4pd/headers/plugin_interface/sc_msg_iter.h | 264 +++++++ sc4pd/headers/server/HashTable.h | 356 ++++++++++ sc4pd/headers/server/IntFifo.h | 87 +++ sc4pd/headers/server/MsgFifo.h | 169 +++++ sc4pd/headers/server/OSC_Packet.h | 43 ++ sc4pd/headers/server/PriorityQueue.h | 123 ++++ sc4pd/headers/server/ReadWriteMacros.h | 430 +++++++++++ sc4pd/headers/server/Rendezvous.h | 41 ++ sc4pd/headers/server/SC_ComPort.h | 144 ++++ sc4pd/headers/server/SC_Complex.h | 142 ++++ sc4pd/headers/server/SC_CoreAudio.h | 263 +++++++ sc4pd/headers/server/SC_Errors.h | 58 ++ sc4pd/headers/server/SC_GraphDef.h | 75 ++ sc4pd/headers/server/SC_Group.h | 34 + sc4pd/headers/server/SC_HiddenWorld.h | 113 +++ sc4pd/headers/server/SC_Lib.h | 62 ++ sc4pd/headers/server/SC_Lib_Cintf.h | 124 ++++ sc4pd/headers/server/SC_List.h | 229 ++++++ sc4pd/headers/server/SC_Lock.h | 38 + sc4pd/headers/server/SC_Prototypes.h | 213 ++++++ sc4pd/headers/server/SC_Reply.h | 55 ++ sc4pd/headers/server/SC_Samp.h | 38 + sc4pd/headers/server/SC_SequencedCommand.h | 481 +++++++++++++ sc4pd/headers/server/SC_Str4.h | 103 +++ sc4pd/headers/server/SC_SyncCondition.h | 45 ++ sc4pd/headers/server/SC_SynthDef.h | 43 ++ sc4pd/headers/server/SC_UnitDef.h | 69 ++ sc4pd/headers/server/SC_UnitSpec.h | 41 ++ sc4pd/headers/server/SC_WireSpec.h | 47 ++ sc4pd/make-files.txt | 6 + sc4pd/makefile.max-msvc | 77 ++ sc4pd/makefile.pd-bcc | 73 ++ sc4pd/makefile.pd-cygwin | 86 +++ sc4pd/makefile.pd-darwin | 77 ++ sc4pd/makefile.pd-linux | 94 +++ sc4pd/makefile.pd-mingw | 85 +++ sc4pd/makefile.pd-msvc | 53 ++ sc4pd/pd/crackle.pd | 10 + sc4pd/pd/dust.pd | 11 + sc4pd/pd/hasher.pd | 17 + sc4pd/pd/mantissamask.pd | 21 + sc4pd/readme.txt | 23 + sc4pd/source/BrownNoise.cpp | 150 ++++ sc4pd/source/ClipNoise.cpp | 130 ++++ sc4pd/source/Crackle.cpp | 161 +++++ sc4pd/source/Dust.cpp | 179 +++++ sc4pd/source/Dust2.cpp | 180 +++++ sc4pd/source/GrayNoise.cpp | 137 ++++ sc4pd/source/Hasher.cpp | 122 ++++ sc4pd/source/MantissaMask.cpp | 160 +++++ sc4pd/source/Median.cpp | 220 ++++++ sc4pd/source/PinkNoise.cpp | 168 +++++ sc4pd/source/WhiteNoise.cpp | 130 ++++ sc4pd/source/main.cpp | 91 +++ sc4pd/source/support.hpp | 80 +++ sc4pd/source/template.cpp | 43 ++ 180 files changed, 19410 insertions(+) create mode 100644 sc4pd/build-max-msvc.bat create mode 100644 sc4pd/build-pd-bcc.bat create mode 100644 sc4pd/build-pd-cygwin.sh create mode 100755 sc4pd/build-pd-darwin.sh create mode 100755 sc4pd/build-pd-linux.sh create mode 100644 sc4pd/build-pd-mingw.bat create mode 100644 sc4pd/build-pd-msvc.bat create mode 100644 sc4pd/config-max-msvc.txt create mode 100644 sc4pd/config-pd-bcc.txt create mode 100644 sc4pd/config-pd-cygwin.txt create mode 100755 sc4pd/config-pd-darwin.txt create mode 100755 sc4pd/config-pd-linux.txt create mode 100644 sc4pd/config-pd-mingw.txt create mode 100644 sc4pd/config-pd-msvc.txt create mode 100644 sc4pd/headers/app/AIAttributedStringAdditions.h create mode 100644 sc4pd/headers/app/AIColorAdditions.h create mode 100644 sc4pd/headers/app/AIHTMLDecoder.h create mode 100644 sc4pd/headers/app/AIStringAdditions.h create mode 100644 sc4pd/headers/app/AITextAttributes.h create mode 100644 sc4pd/headers/app/ChangeCounter.h create mode 100644 sc4pd/headers/app/ControlSpec.h create mode 100644 sc4pd/headers/app/DrawBackground.h create mode 100644 sc4pd/headers/app/GetStringFromUser.h create mode 100644 sc4pd/headers/app/GoToPanel.h create mode 100644 sc4pd/headers/app/MyDocument.h create mode 100644 sc4pd/headers/app/RendezvousClient.h create mode 100644 sc4pd/headers/app/SCDialog.h create mode 100644 sc4pd/headers/app/SCGeom.h create mode 100644 sc4pd/headers/app/SCGraphView.h create mode 100644 sc4pd/headers/app/SCService.h create mode 100644 sc4pd/headers/app/SCTextView.h create mode 100644 sc4pd/headers/app/SCView.h create mode 100644 sc4pd/headers/app/SCVirtualMachine.h create mode 100755 sc4pd/headers/app/TabletEvents.h create mode 100644 sc4pd/headers/app/TextFinder.h create mode 100644 sc4pd/headers/app/UserPanel.h create mode 100755 sc4pd/headers/common/SC_AllocPool.h create mode 100644 sc4pd/headers/common/SC_Altivec.h create mode 100644 sc4pd/headers/common/SC_Endian.h create mode 100755 sc4pd/headers/common/SC_Sem.h create mode 100644 sc4pd/headers/common/SC_StringBuffer.h create mode 100644 sc4pd/headers/common/SC_StringParser.h create mode 100755 sc4pd/headers/common/dfftlib.h create mode 100755 sc4pd/headers/common/dlfcn.h create mode 100755 sc4pd/headers/common/fftlib.h create mode 100644 sc4pd/headers/common/scsynthsend.h create mode 100755 sc4pd/headers/lang/AdvancingAllocPool.h create mode 100755 sc4pd/headers/lang/AllocPools.h create mode 100755 sc4pd/headers/lang/ByteCodeArray.h create mode 100755 sc4pd/headers/lang/FIFOT.h create mode 100755 sc4pd/headers/lang/GC.h create mode 100755 sc4pd/headers/lang/HashTable.h create mode 100755 sc4pd/headers/lang/InitAlloc.h create mode 100755 sc4pd/headers/lang/MiscInlineMath.h create mode 100755 sc4pd/headers/lang/OSCData.h create mode 100755 sc4pd/headers/lang/Opcodes.h create mode 100755 sc4pd/headers/lang/PowerOfTwoAllocPool.h create mode 100755 sc4pd/headers/lang/PredefinedSymbols.h create mode 100755 sc4pd/headers/lang/PriorityQueue.h create mode 100755 sc4pd/headers/lang/PyrArchiverT.h create mode 100755 sc4pd/headers/lang/PyrDeepCopier.h create mode 100755 sc4pd/headers/lang/PyrDeepFreezer.h create mode 100755 sc4pd/headers/lang/PyrErrors.h create mode 100755 sc4pd/headers/lang/PyrFilePrim.h create mode 100755 sc4pd/headers/lang/PyrFileUtils.h create mode 100755 sc4pd/headers/lang/PyrInterpreter.h create mode 100755 sc4pd/headers/lang/PyrKernel.h create mode 100755 sc4pd/headers/lang/PyrKernelProto.h create mode 100755 sc4pd/headers/lang/PyrLexer.h create mode 100755 sc4pd/headers/lang/PyrListPrim.h create mode 100755 sc4pd/headers/lang/PyrMathPrim.h create mode 100755 sc4pd/headers/lang/PyrMessage.h create mode 100755 sc4pd/headers/lang/PyrObject.h create mode 100755 sc4pd/headers/lang/PyrObjectProto.h create mode 100755 sc4pd/headers/lang/PyrParseNode.h create mode 100755 sc4pd/headers/lang/PyrPrimitive.h create mode 100755 sc4pd/headers/lang/PyrPrimitiveProto.h create mode 100755 sc4pd/headers/lang/PyrSched.h create mode 100755 sc4pd/headers/lang/PyrSignal.h create mode 100755 sc4pd/headers/lang/PyrSignalPrim.h create mode 100755 sc4pd/headers/lang/PyrSlot.h create mode 100755 sc4pd/headers/lang/PyrSymbol.h create mode 100755 sc4pd/headers/lang/PyrSymbolTable.h create mode 100755 sc4pd/headers/lang/ReadWriteMacros.h create mode 100755 sc4pd/headers/lang/SCBase.h create mode 100755 sc4pd/headers/lang/SC_ComPort.h create mode 100644 sc4pd/headers/lang/SC_LanguageClient.h create mode 100644 sc4pd/headers/lang/SC_LibraryConfig.h create mode 100755 sc4pd/headers/lang/SC_List.h create mode 100755 sc4pd/headers/lang/SC_LogFile.h create mode 100755 sc4pd/headers/lang/SC_Msg.h create mode 100755 sc4pd/headers/lang/SC_SynthImpl.h create mode 100644 sc4pd/headers/lang/SC_TerminalClient.h create mode 100755 sc4pd/headers/lang/SC_UnorderedList.h create mode 100755 sc4pd/headers/lang/SFHeaders.h create mode 100755 sc4pd/headers/lang/Samp.h create mode 100755 sc4pd/headers/lang/SimpleStack.h create mode 100755 sc4pd/headers/lang/VMGlobals.h create mode 100755 sc4pd/headers/lang/bullet.h create mode 100644 sc4pd/headers/lang/libraryConfig.h create mode 100755 sc4pd/headers/lang/readSamples.h create mode 100755 sc4pd/headers/plugin_interface/Hash.h create mode 100755 sc4pd/headers/plugin_interface/SC_BoundsMacros.h create mode 100644 sc4pd/headers/plugin_interface/SC_BufGen.h create mode 100755 sc4pd/headers/plugin_interface/SC_Constants.h create mode 100644 sc4pd/headers/plugin_interface/SC_DemandUnit.h create mode 100644 sc4pd/headers/plugin_interface/SC_Dimension.h create mode 100644 sc4pd/headers/plugin_interface/SC_FifoMsg.h create mode 100644 sc4pd/headers/plugin_interface/SC_Graph.h create mode 100755 sc4pd/headers/plugin_interface/SC_InlineBinaryOp.h create mode 100755 sc4pd/headers/plugin_interface/SC_InlineUnaryOp.h create mode 100644 sc4pd/headers/plugin_interface/SC_InterfaceTable.h create mode 100644 sc4pd/headers/plugin_interface/SC_Node.h create mode 100644 sc4pd/headers/plugin_interface/SC_PlugIn.h create mode 100755 sc4pd/headers/plugin_interface/SC_RGen.h create mode 100644 sc4pd/headers/plugin_interface/SC_Rate.h create mode 100644 sc4pd/headers/plugin_interface/SC_SndBuf.h create mode 100755 sc4pd/headers/plugin_interface/SC_Types.h create mode 100644 sc4pd/headers/plugin_interface/SC_Unit.h create mode 100644 sc4pd/headers/plugin_interface/SC_Wire.h create mode 100644 sc4pd/headers/plugin_interface/SC_World.h create mode 100644 sc4pd/headers/plugin_interface/SC_WorldOptions.h create mode 100644 sc4pd/headers/plugin_interface/Unroll.h create mode 100755 sc4pd/headers/plugin_interface/clz.h create mode 100644 sc4pd/headers/plugin_interface/sc_msg_iter.h create mode 100755 sc4pd/headers/server/HashTable.h create mode 100644 sc4pd/headers/server/IntFifo.h create mode 100755 sc4pd/headers/server/MsgFifo.h create mode 100644 sc4pd/headers/server/OSC_Packet.h create mode 100755 sc4pd/headers/server/PriorityQueue.h create mode 100644 sc4pd/headers/server/ReadWriteMacros.h create mode 100644 sc4pd/headers/server/Rendezvous.h create mode 100755 sc4pd/headers/server/SC_ComPort.h create mode 100644 sc4pd/headers/server/SC_Complex.h create mode 100755 sc4pd/headers/server/SC_CoreAudio.h create mode 100755 sc4pd/headers/server/SC_Errors.h create mode 100644 sc4pd/headers/server/SC_GraphDef.h create mode 100644 sc4pd/headers/server/SC_Group.h create mode 100644 sc4pd/headers/server/SC_HiddenWorld.h create mode 100755 sc4pd/headers/server/SC_Lib.h create mode 100755 sc4pd/headers/server/SC_Lib_Cintf.h create mode 100755 sc4pd/headers/server/SC_List.h create mode 100755 sc4pd/headers/server/SC_Lock.h create mode 100644 sc4pd/headers/server/SC_Prototypes.h create mode 100755 sc4pd/headers/server/SC_Reply.h create mode 100644 sc4pd/headers/server/SC_Samp.h create mode 100644 sc4pd/headers/server/SC_SequencedCommand.h create mode 100644 sc4pd/headers/server/SC_Str4.h create mode 100755 sc4pd/headers/server/SC_SyncCondition.h create mode 100644 sc4pd/headers/server/SC_SynthDef.h create mode 100644 sc4pd/headers/server/SC_UnitDef.h create mode 100644 sc4pd/headers/server/SC_UnitSpec.h create mode 100644 sc4pd/headers/server/SC_WireSpec.h create mode 100755 sc4pd/make-files.txt create mode 100644 sc4pd/makefile.max-msvc create mode 100644 sc4pd/makefile.pd-bcc create mode 100644 sc4pd/makefile.pd-cygwin create mode 100755 sc4pd/makefile.pd-darwin create mode 100644 sc4pd/makefile.pd-linux create mode 100644 sc4pd/makefile.pd-mingw create mode 100644 sc4pd/makefile.pd-msvc create mode 100644 sc4pd/pd/crackle.pd create mode 100644 sc4pd/pd/dust.pd create mode 100644 sc4pd/pd/hasher.pd create mode 100644 sc4pd/pd/mantissamask.pd create mode 100644 sc4pd/readme.txt create mode 100644 sc4pd/source/BrownNoise.cpp create mode 100644 sc4pd/source/ClipNoise.cpp create mode 100644 sc4pd/source/Crackle.cpp create mode 100644 sc4pd/source/Dust.cpp create mode 100644 sc4pd/source/Dust2.cpp create mode 100644 sc4pd/source/GrayNoise.cpp create mode 100644 sc4pd/source/Hasher.cpp create mode 100644 sc4pd/source/MantissaMask.cpp create mode 100644 sc4pd/source/Median.cpp create mode 100644 sc4pd/source/PinkNoise.cpp create mode 100644 sc4pd/source/WhiteNoise.cpp create mode 100644 sc4pd/source/main.cpp create mode 100644 sc4pd/source/support.hpp create mode 100644 sc4pd/source/template.cpp diff --git a/sc4pd/build-max-msvc.bat b/sc4pd/build-max-msvc.bat new file mode 100644 index 0000000..130a3bc --- /dev/null +++ b/sc4pd/build-max-msvc.bat @@ -0,0 +1,4 @@ +@echo --- Building with MS Visual C++ --- + +nmake -f makefile.max-msvc clean +nmake -f makefile.max-msvc diff --git a/sc4pd/build-pd-bcc.bat b/sc4pd/build-pd-bcc.bat new file mode 100644 index 0000000..3dd2132 --- /dev/null +++ b/sc4pd/build-pd-bcc.bat @@ -0,0 +1,3 @@ +@echo --- Building with BorlandC++ --- + +make -f makefile.pd-bcc diff --git a/sc4pd/build-pd-cygwin.sh b/sc4pd/build-pd-cygwin.sh new file mode 100644 index 0000000..9477844 --- /dev/null +++ b/sc4pd/build-pd-cygwin.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +SYS=pd-cygwin + +. config-${SYS}.txt + +make -f makefile.${SYS} && +{ + if [ $INSTDIR != "" ]; then + make -f makefile.${SYS} install + fi + if [ $HELPDIR != "" ]; then + make -f makefile.${SYS} install-help + fi +} diff --git a/sc4pd/build-pd-darwin.sh b/sc4pd/build-pd-darwin.sh new file mode 100755 index 0000000..38814a9 --- /dev/null +++ b/sc4pd/build-pd-darwin.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +SYS=pd-darwin + +. config-${SYS}.txt + +make -f makefile.${SYS} && +{ + if [ $INSTDIR != "" ]; then + echo Now install as root + sudo make -f makefile.${SYS} install + fi + if [ $HELPDIR != "" ]; then + echo Now install help as root + sudo make -f makefile.${SYS} install-help + fi +} diff --git a/sc4pd/build-pd-linux.sh b/sc4pd/build-pd-linux.sh new file mode 100755 index 0000000..77c6e3f --- /dev/null +++ b/sc4pd/build-pd-linux.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +SYS=pd-linux + +. config-${SYS}.txt + +make -f makefile.${SYS} && +{ + if [ $INSTDIR != "" ]; then + echo Now install as root + su -c "make -f makefile.${SYS} install" + fi + if [ $HELPDIR != "" ]; then + echo Now install help as root + su -c "make -f makefile.${SYS} install-help" + fi +} diff --git a/sc4pd/build-pd-mingw.bat b/sc4pd/build-pd-mingw.bat new file mode 100644 index 0000000..fa8919a --- /dev/null +++ b/sc4pd/build-pd-mingw.bat @@ -0,0 +1,3 @@ +mingw32-make -f makefile.pd-mingw +mingw32-make -f makefile.pd-mingw install +mingw32-make -f makefile.pd-mingw install-help diff --git a/sc4pd/build-pd-msvc.bat b/sc4pd/build-pd-msvc.bat new file mode 100644 index 0000000..d6187f0 --- /dev/null +++ b/sc4pd/build-pd-msvc.bat @@ -0,0 +1,4 @@ +@echo --- Building with MS Visual C++ --- + +nmake -f makefile.pd-msvc clean +nmake -f makefile.pd-msvc diff --git a/sc4pd/config-max-msvc.txt b/sc4pd/config-max-msvc.txt new file mode 100644 index 0000000..95dfe38 --- /dev/null +++ b/sc4pd/config-max-msvc.txt @@ -0,0 +1,27 @@ +# config file for sc4pd, adapted from Thomas Grill's xsample makefile +# + +# where is the Max SDK? +# you should have the latest version! +MAXSDKPATH="F:\prog\audio\MaxWinSDK\c74support" + +# where do the flext libraries reside? +FLEXTPATH="%CommonProgramFiles%\Cycling '74\flext" + +# where is MS VC++? +# (need not be defined if the build is started with the compiler environment set) +# MSVCPATH="c:\programme\prog\microsoft visual studio\VC98" + + +# where should the external be built? +# (path for temporary files) +OUTPATH=max-msvc + +# where should the external be installed? +# (leave blank to omit installation) +INSTPATH="%CommonProgramFiles%\Cycling '74\externals\flext" + + +# some user-definable flags +# (check if they match your system!) +UFLAGS=/G6 /arch:SSE diff --git a/sc4pd/config-pd-bcc.txt b/sc4pd/config-pd-bcc.txt new file mode 100644 index 0000000..8f8ba75 --- /dev/null +++ b/sc4pd/config-pd-bcc.txt @@ -0,0 +1,23 @@ +# config file for sc4pd, adapted from Thomas Grill's xsample makefile +# + +# where is PD? +PDPATH=c:\programme\audio\pd + +# where do the flext libraries reside? +FLEXTPATH=$(PDPATH)\flext + +# where is BorlandC++? +BCCPATH=c:\programme\prog\bcc55 + +# where should the external(s) be built? +OUTPATH=.\pd-bcc + +# should the external be installed? (yes/no) +INSTALL=yes + +# where should the external be installed? +INSTDIR=$(PDPATH)\extra + +# additional compiler flags +UFLAGS=-6 -O2 -OS -ff diff --git a/sc4pd/config-pd-cygwin.txt b/sc4pd/config-pd-cygwin.txt new file mode 100644 index 0000000..feb8d31 --- /dev/null +++ b/sc4pd/config-pd-cygwin.txt @@ -0,0 +1,35 @@ +# config file for sc4pd, adapted from Thomas Grill's xsample makefile +# + +# your c++ compiler (define only if it's different than g++) +# CXX=g++ + +# where does the PD installation reside? +PD=/cygdrive/c/programme/audio/pd + +# where are the PD header files? +# leave it blank if it is a system directory (like /usr/local/include), +# since gcc 3.2 complains about it +PDINC=${PD}/src + +# where do the flext libraries reside? +FLEXTPATH=${PD}/flext + +# where should sc4pd objects be built? +TARGDIR=./pd-cygwin + +# where should sc4pd be installed? +# (leave blank to omit installation) +INSTDIR=${PD}/extra + +# where should the sc4pd help be installed? +# (leave blank to omit installation) +HELPDIR=${PD}/doc/5.reference + +# additional compiler flags +# (check whether they fit to your system!) +UFLAGS=-mcpu=pentium4 -msse -mfpmath=sse # gcc 3.2 +# UFLAGS=-mcpu=pentiumpro # gcc 2.95 + +# define to build with shared flext library +#FLEXT_SHARED=1 diff --git a/sc4pd/config-pd-darwin.txt b/sc4pd/config-pd-darwin.txt new file mode 100755 index 0000000..82c5b70 --- /dev/null +++ b/sc4pd/config-pd-darwin.txt @@ -0,0 +1,35 @@ +# config file for sc4pd, adapted from Thomas Grill's xsample makefile +# + +# your c++ compiler (if not g++) +#CXX=g++-3.3 + +# where does the PD installation reside? +PD=/usr/local/lib/pd + +# where are the PD header files? +# leave it blank if it is a system directory (like /usr/local/include), +# since gcc 3.2 complains about it +PDINC=${PD}/src + +# where is the PD executable? +PDBIN=/usr/local/bin/pd + +# where do the flext libraries reside? +FLEXTPATH=${PD}/flext + +# where should the sc4pd objects be built? +TARGDIR=./pd-darwin + +# where should sc4pd be installed? +# (leave blank to omit installation) +INSTDIR=${PD}/extra + +# where should the sc4pd help be installed? +# (leave blank to omit installation) +HELPDIR=${PD}/doc/5.reference + +# additional compiler flags +# (check whether they fit your system!) +UFLAGS=-malign-power -maltivec -faltivec + diff --git a/sc4pd/config-pd-linux.txt b/sc4pd/config-pd-linux.txt new file mode 100755 index 0000000..e3d8dc1 --- /dev/null +++ b/sc4pd/config-pd-linux.txt @@ -0,0 +1,37 @@ +# config file for sc4pd, adapted from Thomas Grill's xsample makefile + +# your c++ compiler (if not g++) + CXX=icc + + +# where does the PD installation reside? +PD=/usr/lib/pd + +# where are the PD header files? +# leave it blank if it is a system directory (like /usr/local/include), +# since gcc 3.2 complains about it +PDINC=/home/tim/pd/pd/src + +# where do the flext libraries reside? +FLEXTPATH=/usr/lib/flext + +# where should sc4pd objects be built? +TARGDIR=./pd-linux + +# where should sc4pd be installed? +# (leave blank to omit installation) +INSTDIR=${PD}/externs + +# where should the sc4pd help be installed? +# (leave blank to omit installation) +HELPDIR=${PD}/doc/5.reference + +# additional compiler flags +# (check whether they fit to your system!) +#UFLAGS=-xN -tpp7 -ip -ipo_obj # icc +# UFLAGS=-mcpu=pentium4 -mmmx -msse2 -msse -mfpmath=sse # gcc 3.2 + + +# define to link against shared flext library (flext version >= 0.5.0) +FLEXT_SHARED=1 + diff --git a/sc4pd/config-pd-mingw.txt b/sc4pd/config-pd-mingw.txt new file mode 100644 index 0000000..d5352b7 --- /dev/null +++ b/sc4pd/config-pd-mingw.txt @@ -0,0 +1,35 @@ +# config file for sc4pd, adapted from Thomas Grill's xsample makefile +# + +# your c++ compiler (define only if it's different than g++) +# CXX=g++ + +# where does the PD installation reside? +PD=c:/programme/audio/pd + +# where are the PD header files? +# leave it blank if it is a system directory (like /usr/local/include), +# since gcc 3.2 complains about it +PDINC=${PD}/src + +# where do the flext libraries reside? +FLEXTPATH=${PD}/flext + +# where should sc4pd objects be built? +TARGDIR=./pd-mingw + +# where should sc4pd be installed? +# (leave blank to omit installation) +INSTDIR=${PD}/extra + +# where should the sc4pd help be installed? +# (leave blank to omit installation) +HELPDIR=${PD}/doc/5.reference + +# additional compiler flags +# (check whether they fit to your system!) +UFLAGS=-mcpu=pentium4 -msse -mfpmath=sse # gcc 3.2 +# UFLAGS=-mcpu=pentiumpro # gcc 2.95 + +# define to build with shared flext library +# FLEXT_SHARED=1 \ No newline at end of file diff --git a/sc4pd/config-pd-msvc.txt b/sc4pd/config-pd-msvc.txt new file mode 100644 index 0000000..9ba68f2 --- /dev/null +++ b/sc4pd/config-pd-msvc.txt @@ -0,0 +1,19 @@ +# config file for sc4pd, adapted from Thomas Grill's xsample makefile +# + +# where is PD? +PDPATH=c:\programme\audio\pd + +# where do the flext libraries reside? +FLEXTPATH=$(PDPATH)\flext + +# where is MS VC++? +# (not necessary if the build started with the compiler environment) +# MSVCPATH=c:\programme\prog\microsoft visual studio\VC98 + +# where should the external be built? +OUTPATH=pd-msvc + +# where should the external be installed? +# (leave blank to omit installation) +INSTDIR=$(PDPATH)\extra diff --git a/sc4pd/headers/app/AIAttributedStringAdditions.h b/sc4pd/headers/app/AIAttributedStringAdditions.h new file mode 100644 index 0000000..ae81326 --- /dev/null +++ b/sc4pd/headers/app/AIAttributedStringAdditions.h @@ -0,0 +1,39 @@ +/*-------------------------------------------------------------------------------------------------------*\ +| Adium, Copyright (C) 2001-2003, Adam Iser (adamiser@mac.com | http://www.adiumx.com) | +\---------------------------------------------------------------------------------------------------------/ + | This program is free software; you can redistribute it and/or modify it under the terms of the GNU + | General Public License as published by the Free Software Foundation; either version 2 of the License, + | or (at your option) any later version. + | + | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + | Public License for more details. + | + | You should have received a copy of the GNU General Public License along with this program; if not, + | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + \------------------------------------------------------------------------------------------------------ */ + +#import +#import + +@interface NSMutableAttributedString (AIAttributedStringAdditions) + +- (void)appendString:(NSString *)aString withAttributes:(NSDictionary *)attrs; +- (NSData *)dataRepresentation; +- (NSAttributedString *)safeString; +- (unsigned int)replaceOccurrencesOfString:(NSString *)target withString:(NSString*)replacement options:(unsigned)opts range:(NSRange)searchRange; +- (unsigned int)replaceOccurrencesOfString:(NSString *)target withString:(NSString*)replacement attributes:(NSDictionary*)attributes options:(unsigned)opts range:(NSRange)searchRange; +- (void)adjustColorsToShowOnBackground:(NSColor *)backgroundColor; +- (void)adjustColorsToShowOnBackgroundRelativeToOriginalBackground:(NSColor *)backgroundColor; +@end + +@interface NSAttributedString (AIAttributedStringAdditions) + +- (float)heightWithWidth:(float)width; +- (NSData *)dataRepresentation; ++ (NSAttributedString *)stringWithData:(NSData *)inData; +- (NSAttributedString *)safeString; + +@end + + diff --git a/sc4pd/headers/app/AIColorAdditions.h b/sc4pd/headers/app/AIColorAdditions.h new file mode 100644 index 0000000..6af9dc8 --- /dev/null +++ b/sc4pd/headers/app/AIColorAdditions.h @@ -0,0 +1,39 @@ +/*-------------------------------------------------------------------------------------------------------*\ +| Adium, Copyright (C) 2001-2003, Adam Iser (adamiser@mac.com | http://www.adiumx.com) | +\---------------------------------------------------------------------------------------------------------/ + | This program is free software; you can redistribute it and/or modify it under the terms of the GNU + | General Public License as published by the Free Software Foundation; either version 2 of the License, + | or (at your option) any later version. + | + | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + | Public License for more details. + | + | You should have received a copy of the GNU General Public License along with this program; if not, + | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + \------------------------------------------------------------------------------------------------------ */ + +#import +#import + +@interface NSString (AIColorAdditions) + +- (NSColor *)hexColor; +- (NSColor *)representedColor; +- (NSColor *)representedColorWithAlpha:(float)alpha; + +@end + +@interface NSColor (AIColorAdditions) + +- (BOOL)equalToRGBColor:(NSColor *)inColor; +- (BOOL)colorIsDark; +- (NSColor *)darkenBy:(float)amount; +- (NSString *)hexString; +- (NSString *)stringRepresentation; +- (void)getHue:(float *)hue luminance:(float *)luminance saturation:(float *)saturation; ++ (NSColor *)colorWithCalibratedHue:(float)hue luminance:(float)luminance saturation:(float)saturation alpha:(float)alpha; +- (NSColor *)colorWithInvertedLuminance; +- (NSColor *)adjustHue:(float)dHue saturation:(float)dSat brightness:(float)dBrit; + +@end diff --git a/sc4pd/headers/app/AIHTMLDecoder.h b/sc4pd/headers/app/AIHTMLDecoder.h new file mode 100644 index 0000000..492d663 --- /dev/null +++ b/sc4pd/headers/app/AIHTMLDecoder.h @@ -0,0 +1,28 @@ +/*-------------------------------------------------------------------------------------------------------*\ +| Adium, Copyright (C) 2001-2003, Adam Iser (adamiser@mac.com | http://www.adiumx.com) | +\---------------------------------------------------------------------------------------------------------/ + | This program is free software; you can redistribute it and/or modify it under the terms of the GNU + | General Public License as published by the Free Software Foundation; either version 2 of the License, + | or (at your option) any later version. + | + | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + | Public License for more details. + | + | You should have received a copy of the GNU General Public License along with this program; if not, + | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + \------------------------------------------------------------------------------------------------------ */ + +#import +#import +#import "AIStringAdditions.h" + +@interface AIHTMLDecoder : NSObject { + +} + ++ (NSAttributedString *)decodeHTML:(NSString *)inMessage; ++ (NSString *)encodeHTML:(NSAttributedString *)inMessage encodeFullString:(BOOL)encodeFullString; ++ (NSString *)encodeHTML:(NSAttributedString *)inMessage headers:(BOOL)includeHeaders fontTags:(BOOL)includeFontTags closeFontTags:(BOOL)closeFontTags styleTags:(BOOL)includeStyleTags closeStyleTagsOnFontChange:(BOOL)closeStyleTagsOnFontChange encodeNonASCII:(BOOL)encodeNonASCII; + +@end diff --git a/sc4pd/headers/app/AIStringAdditions.h b/sc4pd/headers/app/AIStringAdditions.h new file mode 100644 index 0000000..b0a5a64 --- /dev/null +++ b/sc4pd/headers/app/AIStringAdditions.h @@ -0,0 +1,25 @@ +/*-------------------------------------------------------------------------------------------------------*\ +| Adium, Copyright (C) 2001-2003, Adam Iser (adamiser@mac.com | http://www.adiumx.com) | +\---------------------------------------------------------------------------------------------------------/ + | This program is free software; you can redistribute it and/or modify it under the terms of the GNU + | General Public License as published by the Free Software Foundation; either version 2 of the License, + | or (at your option) any later version. + | + | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + | Public License for more details. + | + | You should have received a copy of the GNU General Public License along with this program; if not, + | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + \------------------------------------------------------------------------------------------------------ */ + +#import +#import + +@interface NSString (AIStringAdditions) +- (NSString *)compactedString; +- (int)intValueFromHex; +- (NSString *)stringByExpandingBundlePath; +- (NSString *)stringByCollapsingBundlePath; +- (NSString *)stringByTruncatingTailToWidth:(float)inWidth; +@end diff --git a/sc4pd/headers/app/AITextAttributes.h b/sc4pd/headers/app/AITextAttributes.h new file mode 100644 index 0000000..02b0754 --- /dev/null +++ b/sc4pd/headers/app/AITextAttributes.h @@ -0,0 +1,44 @@ +/*-------------------------------------------------------------------------------------------------------*\ +| Adium, Copyright (C) 2001-2003, Adam Iser (adamiser@mac.com | http://www.adiumx.com) | +\---------------------------------------------------------------------------------------------------------/ + | This program is free software; you can redistribute it and/or modify it under the terms of the GNU + | General Public License as published by the Free Software Foundation; either version 2 of the License, + | or (at your option) any later version. + | + | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + | Public License for more details. + | + | You should have received a copy of the GNU General Public License along with this program; if not, + | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + \------------------------------------------------------------------------------------------------------ */ + +#import +#import + +#define AIBodyColorAttributeName @"AIBodyColor" + +@interface AITextAttributes : NSObject { + + NSMutableDictionary *dictionary; + + NSString *fontFamilyName; + NSFontTraitMask fontTraitsMask; + int fontSize; + +} + ++ (id)textAttributesWithFontFamily:(NSString *)inFamilyName traits:(NSFontTraitMask)inTraits size:(int)inSize; +- (void)dealloc; +- (void)setFontFamily:(NSString *)inName; +- (void)setFontSize:(int)inSize; +- (void)enableTrait:(NSFontTraitMask)inTrait; +- (void)disableTrait:(NSFontTraitMask)inTrait; +- (NSDictionary *)dictionary; +- (void)setUnderline:(BOOL)inUnderline; +- (void)setTextColor:(NSColor *)inColor; +- (void)setTextBackgroundColor:(NSColor *)inColor; +- (void)setBackgroundColor:(NSColor *)inColor; +- (void)setLinkURL:(NSString *)inURL; + +@end diff --git a/sc4pd/headers/app/ChangeCounter.h b/sc4pd/headers/app/ChangeCounter.h new file mode 100644 index 0000000..db74fe5 --- /dev/null +++ b/sc4pd/headers/app/ChangeCounter.h @@ -0,0 +1,30 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +class ChangeCounter +{ + int changes, updates; +public: + ChangeCounter() { changes = updates = 0; } + bool NeedsUpdate() { return changes != updates; } + void Update() { updates = changes; } + void Change() { changes++; } +}; + diff --git a/sc4pd/headers/app/ControlSpec.h b/sc4pd/headers/app/ControlSpec.h new file mode 100644 index 0000000..7446759 --- /dev/null +++ b/sc4pd/headers/app/ControlSpec.h @@ -0,0 +1,36 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* +struct ControlSpec { + float minval, maxval, initial; + int numticks; + bool constrained; + + ControlSpec(); +}; + +inline ControlSpec() + : minval(0.), maxval(1.), initial(0.), numticks(11), constrained(false) +{ +} + + +*/ \ No newline at end of file diff --git a/sc4pd/headers/app/DrawBackground.h b/sc4pd/headers/app/DrawBackground.h new file mode 100644 index 0000000..e5fe040 --- /dev/null +++ b/sc4pd/headers/app/DrawBackground.h @@ -0,0 +1,83 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#import "SCGeom.h" + +class DrawBackground +{ +public: + DrawBackground(); + virtual void draw(CGContextRef cgc, CGRect rect); + virtual void drawSelf(CGContextRef cgc, CGRect rect); +}; + + +class SolidColorBackground : public DrawBackground +{ +public: + SolidColorBackground(SCColor inColor); + virtual void drawSelf(CGContextRef cgc, CGRect rect); +private: + SCColor mColor; +}; + +enum { + grad_Horizontal, + grad_Vertical, + grad_Narrow, + grad_Wide +}; + +class GradientBackground : public DrawBackground +{ +public: + GradientBackground(SCColor inStartColor, SCColor inEndColor, int inDirection, int inSteps); + virtual void drawSelf(CGContextRef cgc, CGRect rect); + +protected: + SCColor mStartColor, mEndColor; + int mDirection, mSteps; +}; + +class HiliteGradientBackground : public GradientBackground +{ +public: + HiliteGradientBackground(SCColor inStartColor, SCColor inEndColor, int inDirection, int inSteps, float inFrac = .33); + + virtual void drawSelf(CGContextRef cgc, CGRect rect); + +protected: + float mFrac, mFrac1; +}; + +/* +class TiledBackground : public DrawBackground +{ +public: + TiledBackground(NSImage* inTile); + + virtual void drawSelf(CGContextRef cgc, CGRect rect); + +protected: + NSImage* mTile; + CGRect mTiledBounds; +}; + +*/ diff --git a/sc4pd/headers/app/GetStringFromUser.h b/sc4pd/headers/app/GetStringFromUser.h new file mode 100644 index 0000000..0e13d71 --- /dev/null +++ b/sc4pd/headers/app/GetStringFromUser.h @@ -0,0 +1,46 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#import + +@interface GetStringFromUser : NSObject { + NSString *string; + id textField; + id promptField; + id okButton; + id cancelButton; +} + ++ (id)sharedInstance; + +/* Loads UI lazily */ +- (NSPanel *)getStringPanel; + +- (NSString *)string; +- (void)setString:(NSString *)string; + +- (void)setPrompt:(NSString *)string; + +/* Action methods, sent from the find panel UI; can also be connected to menu items */ +- (void)ok:(id)sender; +- (void)cancel:(id)sender; + +@end diff --git a/sc4pd/headers/app/GoToPanel.h b/sc4pd/headers/app/GoToPanel.h new file mode 100644 index 0000000..6808884 --- /dev/null +++ b/sc4pd/headers/app/GoToPanel.h @@ -0,0 +1,52 @@ +/* + * GoToPanel.M + * SC3lang + * + * Created by j. trutzschler on 02 sept 2003. + derived from TextFinder.m by Ali Ozer + + a panel that searches and selects a line + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#import + +@interface GoToPanel : NSObject { + id findTextField; + id okButton; +} + +/* Common way to get a text finder. One instance of TextFinder per app is good enough. */ ++ (id)sharedInstance; + +/* Main method for external users; does a find in the first responder. Selects found range or beeps. */ +- (void)selectLine:(id)sender; +- (void) getAndDisplayCurrentLine; +- (void)prselectLine:(int)linenum; + +/* Loads UI lazily */ +- (NSPanel *)gotoLinePanel; + +/* Gets the first responder and returns it if it's an NSTextView */ +- (NSTextView *)textObjectToSelectIn; + +- (void)orderFrontGotoLinePanel:(id)sender; + +/* Misc internal methods */ +- (void)appDidActivate:(NSNotification *)notification; + + +@end diff --git a/sc4pd/headers/app/MyDocument.h b/sc4pd/headers/app/MyDocument.h new file mode 100644 index 0000000..d52eabc --- /dev/null +++ b/sc4pd/headers/app/MyDocument.h @@ -0,0 +1,107 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#import +#import "UserPanel.h" +#include "PyrObject.h" +#include "PyrKernel.h" +#include "GC.h" +#include "VMGlobals.h" + +extern pthread_mutex_t gLangMutex; +extern PyrSymbol *s_closed; + +@interface MyDocument : NSDocument +{ + IBOutlet NSTextView* initTextView; + IBOutlet NSTextView* textView; + IBOutlet NSScrollView* scrollView; + Boolean isRichText; + struct PyrObject *mWindowObj; +} + + +- (NSTextView*)makeTextView; +- (NSTextView*) textView; + +- (void)windowControllerDidLoadNib:(NSWindowController*) aController; + +- (void)addDocument; + +- (IBAction)openCode:(id)sender; +- (IBAction)methodTemplates: (id)sender; +- (IBAction)methodReferences: (id)sender; + +- (IBAction)balanceParens: (id)sender; + +- (IBAction)syntaxColorize: (id)sender; +- (void) insertText: (char*) text length: (int)length; +- (IBAction)shiftLeft: (id)sender; +- (IBAction)shiftRight: (id)sender; +- (IBAction)commentCode: (id)sender; +- (IBAction)uncommentCode:(id)sender; + +- (IBAction) executeSelection: (id) sender; +- (NSString*)currentlySelectedTextOrLine: (NSRange*) outRange; +-(void)selectRangeStart:(int)rangeStart size:(int)rangeSize; + +- (IBAction) showHelp: (id) sender; + +- (BOOL) textView: (NSTextView *) textView + clickedOnLink: (id) link + atIndex: (unsigned) charIndex; +- (IBAction) createLink: (id) sender; + +- (void)sendSelection: (char*) methodName; + +- (NSString *)windowNibName; + +- (BOOL)writeToFile:(NSString*) path ofType:(NSString *)aType; +- (BOOL)readFromFile:(NSString *)path ofType:(NSString *)aType; + +- (BOOL) shouldRunSavePanelWithAccessoryView; + +- (BOOL)windowShouldClose:(id)sender; +- (void)windowWillClose:(NSNotification *)aNotification; +- (IBAction) becomePostWindow: (id) sender; +- (BOOL) isDocumentEdited; + +- (void)doToggleRich; +// toggleRich: puts up an alert before ultimately calling doToggleRich +- (IBAction)toggleRich:(id)sender; +- (void)setRichText:(BOOL)flag; + +- (BOOL)validateMenuItem:(NSMenuItem *)aCell; + +- (void)setSCObject: (struct PyrObject*)inObject; +- (struct PyrObject*)getSCObject; +- (void) closeWindow; +- (void)setBackgroundColor:(NSColor *)color; +- (NSScrollView*) scrollView; +- (NSTextView*) initTextView; +-(void)selectLine:(int)linenum; +- (IBAction)selectLineWindow: (id) sender; +- (void) callSCLangWithMethod: (PyrSymbol*) method; + +@end + +NSString* pathOfHelpFileFor(NSString* selection); +void showHelpFor(NSString* selection); + diff --git a/sc4pd/headers/app/RendezvousClient.h b/sc4pd/headers/app/RendezvousClient.h new file mode 100644 index 0000000..e66f518 --- /dev/null +++ b/sc4pd/headers/app/RendezvousClient.h @@ -0,0 +1,39 @@ +// +// RendezvousClient.h +// SC3lang +// +// Created by C. Ramakrishnan on Mon Feb 24 2003. +// Copyright (c) 2003 __MyCompanyName__. All rights reserved. +// + +#import + +@interface OSCService : NSObject { +// a glorified struct (declared as an Obj-C class so I can put it in NSArrays) +// stored in the oscServices ivar of RendezvousClient +@public + NSNetService* netService; + BOOL isResolved; + NSString* hostName; + const struct sockaddr_in* sockaddr; + unsigned hostAddress; + unsigned short port; + int refCount; +} + +@end + +@interface RendezvousClient : NSObject { + NSNetServiceBrowser* browser; + NSMutableArray* oscServices; +} + ++ (RendezvousClient*)sharedClient; + +// interface +- (void)findOSCServices; +- (OSCService*)oscServiceAtIndex:(unsigned)index; +- (unsigned)numberOfOSCServices; + +@end + diff --git a/sc4pd/headers/app/SCDialog.h b/sc4pd/headers/app/SCDialog.h new file mode 100644 index 0000000..fdebdbb --- /dev/null +++ b/sc4pd/headers/app/SCDialog.h @@ -0,0 +1,41 @@ +// +// SCDialogs.h +// SC3lang +// +// Created by cruxxial on Tue Dec 17 2002. +// Copyright (c) 2002 crucial-systems. All rights reserved. +// + +#import + +#include "PyrPrimitive.h" +#include "PyrObject.h" +#include "PyrKernel.h" +#include "VMGlobals.h" +#include "GC.h" +#include "PyrSched.h" +#import "SCVirtualMachine.h" + +@interface SCDialog : NSObject { + PyrObject *receiver; + PyrObject *result; + NSOpenPanel *openPanel; +} + ++(id)receiver:(PyrObject*)argReceiver result:(PyrObject*)argResult; +-(id)initWithReceiver:(PyrObject*)argReceiver result:(PyrObject*)argResult; + +-(void)ok; +-(void)cancel; +-(void)error; + +-(void)returnPaths:(NSArray*)urls; +-(void)getPaths; +-(void)returnPath:(NSString*)path; + + +// call method on self when SCVM is ready for sclang usage +-(void)scvmDeferWithSelector:(SEL)selector; + + +@end diff --git a/sc4pd/headers/app/SCGeom.h b/sc4pd/headers/app/SCGeom.h new file mode 100644 index 0000000..04904a4 --- /dev/null +++ b/sc4pd/headers/app/SCGeom.h @@ -0,0 +1,90 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#import +#include "SC_BoundsMacros.h" + +struct SCColor { + float red, green, blue, alpha; +}; +typedef struct SCColor SCColor; + +inline SCColor SCMakeColor(float red, float green, float blue, float alpha) +{ + SCColor sccolor; + sccolor.red = red; + sccolor.green = green; + sccolor.blue = blue; + sccolor.alpha = alpha; + return sccolor; +} + +struct SCPoint { + float x, y; +}; + +inline SCPoint SCMakePoint(float x, float y) +{ + SCPoint p; + p.x = x; + p.y = y; + return p; +} + +struct SCRect { + float x, y, width, height; +}; + +inline SCRect SCRectUnion(SCRect a, SCRect b) +{ + if (a.height <= 0. && a.width <= 0.) return b; + if (b.height <= 0. && b.width <= 0.) return a; + + SCRect u; + u.x = sc_min(a.x, b.x); + u.y = sc_min(a.y, b.y); + u.width = sc_max(a.x + a.width, b.x + b.width) - u.x; + u.height = sc_max(a.y + a.height, b.y + b.height) - u.y; + return u; +} + +inline bool SCRectsDoIntersect(SCRect a, SCRect b) +{ + if (a.x + a.width < b.x) return false; + if (a.y + a.height < b.y) return false; + if (a.x > b.x + b.width) return false; + if (a.y > b.y + b.height) return false; + return true; +} + +inline SCRect SCMakeRect(float x, float y, float width, float height) +{ + SCRect r; + r.x = x; r.y = y; r.width = width; r.height = height; + return r; +} + +inline bool SCPointInRect(SCPoint p, SCRect r) +{ + return + p.x >= r.x && p.x <= r.x + r.width + && p.y >= r.y && p.y <= r.y + r.height; + +} diff --git a/sc4pd/headers/app/SCGraphView.h b/sc4pd/headers/app/SCGraphView.h new file mode 100644 index 0000000..84b259d --- /dev/null +++ b/sc4pd/headers/app/SCGraphView.h @@ -0,0 +1,55 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#import +#import "SCView.h" + +@interface SCGraphView : NSView +{ + struct PyrObject *mWindowObj; + SCTopView *mTopView; + bool mDragStarted; + SCView* mMenuView; + bool windowShouldClose; +} + +- (void)drawRect: (NSRect)bounds; +- (void) keyDown: (NSEvent*) event; +- (void) keyUp: (NSEvent*) event; +- (void) mouseDown: (NSEvent*) event; +- (void)setSCObject: (struct PyrObject*)inObject; +- (struct PyrObject*)getSCObject; +- (BOOL)isFlipped; +- (BOOL)mouseDownCanMoveWindow; + +- (void)setSCTopView: (SCTopView*)inView; +//- (void)dealloc; +- (void)closeWindow; +- (void)willClose; +- (void)setWindowShouldClose:(BOOL)boo; +- (BOOL)windowShouldClose; +- (void) beginDragFrom: (NSPoint)where of: (PyrSlot*)slot; + +- (NSMenu*) menuForEvent:(NSEvent*)event; +- (void)startMenuTracking: (SCView*) inView; + +- (IBAction) toggleUIEditMode: (id) sender; + +@end diff --git a/sc4pd/headers/app/SCService.h b/sc4pd/headers/app/SCService.h new file mode 100644 index 0000000..64a78a0 --- /dev/null +++ b/sc4pd/headers/app/SCService.h @@ -0,0 +1,16 @@ +// +// SCService.h +// SC3lang +// +// Created by C. Ramakrishnan on Mon Oct 20 2003. +// Copyright (c) 2003 __MyCompanyName__. All rights reserved. +// + +#import + + +@interface SCService : NSObject { + +} + +@end diff --git a/sc4pd/headers/app/SCTextView.h b/sc4pd/headers/app/SCTextView.h new file mode 100644 index 0000000..b1b721c --- /dev/null +++ b/sc4pd/headers/app/SCTextView.h @@ -0,0 +1,33 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#import + +@interface SCTextView : NSTextView +{ + +} + + - (void) keyDown: (NSEvent*) event; + - (void) mouseDown: (NSEvent*) event; + - (void) autoIndent: (NSEvent*) event; + - (void) mouseDownAction; + +@end diff --git a/sc4pd/headers/app/SCView.h b/sc4pd/headers/app/SCView.h new file mode 100644 index 0000000..a752445 --- /dev/null +++ b/sc4pd/headers/app/SCView.h @@ -0,0 +1,784 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#import "DrawBackground.h" +#include "PyrObject.h" + +enum { + layout_NoResize, + layout_Resize +}; + +enum { + // mHResize + layout_FixedLeft = -1, + layout_HElastic, + layout_FixedRight, +}; +enum { + // mVResize + layout_FixedTop = -1, + layout_VElastic, + layout_FixedBottom +}; + + +struct Layout +{ + Layout(); + + // layout params for dynamic layout views + float mMinWidth, mMaxWidth, mMinHeight, mMaxHeight; + float mWeight; + bool mShouldResize; + // layout params for composite views + char mHResize, mVResize; +}; + + + +class SCView; +class SCContainerView; +class SCTopView; + +typedef SCView* (*SCViewCtor)(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + +struct SCViewMaker +{ + SCViewMaker(const char* inName, SCViewCtor inCtor); + static SCView* MakeSCView(PyrObject* inObj, SCContainerView *inParent, SCRect inBounds, const char* classname); + + SCViewMaker *mNext; + SCViewCtor mCtor; + const char* mName; +}; + +extern SCViewMaker *gSCViewMakers; +extern SCView *gAnimatedViews; + +class SCView +{ +public: + SCView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCView(); + + virtual void draw(SCRect inDamage); + virtual void drawFocus(SCRect inDamage); + virtual void drawDisabled(SCRect inDamage); + virtual void drawDragHilite(SCRect inDamage); + virtual void drawIfNecessary(SCRect inDamage); + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseEndTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseOver(SCPoint where); + virtual void keyDown(int character, int modifiers, unsigned short keycode); + virtual void keyUp(int character, int modifiers, unsigned short keycode); + virtual bool shouldDim(); + void beginDrag(SCPoint where); + + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + + bool isFocus() const; + bool hit(SCPoint p) const; + void refresh(); + void refreshFocus(); + void setDragHilite(bool inFlag); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + + virtual bool isDragSource() const; + virtual SCView* findView(SCPoint where); + virtual SCView* findViewByID(int32 inID); + virtual void makeFocus(bool focus); + virtual SCView* nextFocus(bool *foundFocus, bool canFocus); + virtual SCView* prevFocus(SCView **prevView, bool canFocus); + virtual bool canFocus(); + + void sendMessage(PyrSymbol *method, int numargs, PyrSlot *args, PyrSlot *result); + + virtual void setBounds(SCRect inBounds); + virtual SCRect getBounds(); + virtual Layout getLayout(); + + SCView* next() { return mNext; } + SCContainerView* parent() { return mParent; } + + virtual NSMenu* contextMenu(SCPoint inPoint); + + virtual void setMenuItemChosen(int inItem) {} + + PyrObject* GetSCObj() { return mObj; } + SCView* NextAnimatedView() const { return mNextAnimatedView; } + + void startAnimation(); + void stopAnimation(); + virtual void animate() { refresh(); } + +protected: + friend class SCContainerView; + + SCView *mNext; + SCView *mNextAnimatedView; + SCView *mPrevAnimatedView; + SCContainerView *mParent; + SCTopView *mTop; + PyrObject* mObj; + SCRect mBounds; + Layout mLayout; + DrawBackground* mBackground; + bool mVisible; + bool mEnabled; + bool mCanFocus; + bool mDragHilite; + int32 mID; +}; + + +class SCContainerView : public SCView +{ +public: + SCContainerView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCContainerView(); + + virtual void drawIfNecessary(SCRect inDamage); + + virtual void add(SCView *inChild); + virtual void remove(SCView *inChild); + virtual SCView* findView(SCPoint where); + virtual SCView* findViewByID(int32 inID); + virtual void makeFocus(bool focus); + virtual SCView* nextFocus(bool *foundFocus, bool canFocus); + virtual SCView* prevFocus(SCView **prevView, bool canFocus); + virtual bool canFocus(); + +protected: + SCView *mChildren; + int mNumChildren; +}; + +class SCCompositeView : public SCContainerView +{ +public: + SCCompositeView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCCompositeView(); + + virtual void setBounds(SCRect inBounds); + +protected: +}; + +class SCLayoutView : public SCContainerView +{ +public: + SCLayoutView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCLayoutView(); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + +protected: + float mSpacing; +}; + +class SCHLayoutView : public SCLayoutView +{ +public: + SCHLayoutView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCHLayoutView(); + + virtual void setBounds(SCRect inBounds); + +protected: +}; + +class SCVLayoutView : public SCLayoutView +{ +public: + SCVLayoutView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCVLayoutView(); + + virtual void setBounds(SCRect inBounds); + +protected: +}; + +// tell host to draw stuff. +typedef void (*DamageCallback)(SCRect inRect, void *inData); +typedef void (*DragCallback)(SCPoint where, PyrSlot* inSlot, void *inData); + +class SCTopView : public SCCompositeView +{ +public: + SCTopView(PyrObject* inObj, SCRect inBounds); + + SCView *focusView() { return mFocusView; } + + void resetFocus(); + void addDamage(SCRect inRect); + void beginDragCallback(SCPoint where, PyrSlot* slot); + + void setDamageCallback(DamageCallback inFunc, void *inHostData) + { mDamageCallback = inFunc; mHostData = inHostData; } + void setDragCallback(DragCallback inFunc) + { mDragCallback = inFunc; } + + void tabNextFocus(); + void tabPrevFocus(); + void setDragView(SCView *inView); + + NSView* GetNSView() { return mNSView; } + void SetNSView(NSView* inView) { mNSView = inView; } + + bool ConstructionMode() { return mConstructionMode; } + void SetConstructionMode(bool inFlag) { mConstructionMode = inFlag; } + + virtual void drawFocus(SCRect inDamage); + +protected: + friend class SCView; + void focusIs(SCView *inView) { mFocusView = inView; } + + DamageCallback mDamageCallback; + DragCallback mDragCallback; + void *mHostData; + SCView *mFocusView; + SCView *mDragView; + NSView *mNSView; + + bool mConstructionMode; +}; + +inline bool SCView::isFocus() const { return mTop->focusView() == this; } + +class SCSlider : public SCView +{ +public: + SCSlider(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + virtual void draw(SCRect inDamage); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + + double value() { return mValue; } + bool setValue(double inValue, bool send); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + +protected: + virtual void setValueFromPoint(SCPoint point); + void calcThumbRect(); + + SCRect mThumbRect; + double mValue, mStepSize, mStepScale; + DrawBackground* mKnob; +}; +SCView* NewSCSlider(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + +class SCRangeSlider : public SCView +{ +public: + SCRangeSlider(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + virtual void draw(SCRect inDamage); + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + + bool setValue(double inLo, double inHi, bool send); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + +protected: + virtual void setValueFromPoint(SCPoint point); + // sc.solar addition + void moveRangeFromPoint(SCPoint point); + void adjustLoFromPoint(SCPoint point); + void adjustHiFromPoint(SCPoint point); + // sc.solar addition end + void calcRangeRect(); + + SCRect mRangeRect; + double mLo, mHi, mStepSize, mStepScale; + SCPoint mAnchor; + DrawBackground* mKnob; +}; +SCView* NewSCRangeSlider(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + + +class SC2DSlider : public SCView +{ +public: + SC2DSlider(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + virtual void draw(SCRect inDamage); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + + virtual bool setValue(double inLo, double inHi, bool send); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + +protected: + virtual void setValueFromPoint(SCPoint point); + void calcThumbRect(); + + SCRect mThumbRect; + double mX, mY; + double mStepSize, mStepScale; + DrawBackground* mKnob; +}; +SCView* NewSC2DSlider(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + +class SC2DTabletSlider : public SC2DSlider +{ +public: + SC2DTabletSlider(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseEndTrack(SCPoint where, int modifiers,NSEvent *theEvent); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + + virtual bool setValue(double inX, double inY,bool send); + +protected: + int mClipInBounds; + +}; +SCView* NewSC2DTabletSlider(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + +#include "SC_SndBuf.h" + +const int kMaxScopeChannels = 16; +class SCScope : public SCView +{ +public: + SCScope(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCScope(); + + virtual void draw(SCRect inDamage); + virtual void draw0(CGContextRef cgc); + virtual void draw1(CGContextRef cgc); + virtual void draw2(CGContextRef cgc); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void animate(); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + + SCPoint pixelToUnits(SCPoint p, SCRect r) + { + return SCMakePoint( + (p.x - r.x) * mZoom.x + mScroll.x, + (p.y - r.y) * mZoom.y + mScroll.y); + } + SCPoint unitsToPixel(SCPoint u, SCRect r) + { + return SCMakePoint( + (u.x - mScroll.x) * mInvZoom.x + r.x, + (u.y - mScroll.y) * mInvZoom.y + r.y); + } + +protected: + + int mBufNum; + SndBuf mSndBuf; + SCPoint mZoom, mInvZoom, mScroll; + int mStyle; // 0 = separate, 1 = overlay, 2 = x,y. + SCColor mWaveColors[kMaxScopeChannels]; + SCColor mGridColor; + bool mGridOn; +}; +SCView* NewSCScope(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + + +const int kLabelSize = 64; +struct SCButtonState +{ + char mLabel[kLabelSize]; + SCColor mLabelColor; + SCColor mButtonColor; +}; + +const int kFontNameSize = 80; + +class SCButton : public SCView +{ +public: + SCButton(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCButton(); + + virtual void draw(SCRect inDamage); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseEndTrack(SCPoint where, int modifiers,NSEvent *theEvent); + + bool setValue(int inValue, bool send); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + +protected: + + int mValue; + char mFontName[kFontNameSize]; + float mFontSize; + int mNumStates; + SCButtonState *mStates; + bool mPushed; +}; +SCView* NewSCButton(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + +class SCPopUpMenu : public SCView +{ +public: + SCPopUpMenu(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCPopUpMenu(); + + virtual void draw(SCRect inDamage); + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + + bool setValue(int inValue, bool send); + virtual void setMenuItemChosen(int inItem) { setValue(inItem, true); } + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + +protected: + + int mValue; + MenuHandle mMenuH; + char mFontName[kFontNameSize]; + float mFontSize; + SCColor mStringColor; +}; +SCView* NewSCPopUpMenu(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + +class SCListView : public SCView +{ +public: + SCListView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCListView(); + + virtual void draw(SCRect inDamage); + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseTrack(SCPoint where, int modifiers, NSEvent *theEvent); + + bool setValue(int inValue, bool send); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + + void scrollToValue(); + +protected: + + int mValue; + CFMutableArrayRef mArray; + char mFontName[kFontNameSize]; + float mFontSize; + float mScroll; + float mAnchorScroll; + SCPoint mAnchor; + SCColor mStringColor; + SCColor mSelectedStringColor; + SCColor mHiliteColor; + int mAlignment; + NSSize mStrSize; + bool mScrolling; +}; +SCView* NewSCListView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + +//by jan trutzschler (jt@kandos.de) +class SCMultiSliderView : public SCView +{ +public: + SCMultiSliderView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCMultiSliderView(); + + virtual void draw(SCRect inDamage); + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseEndTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + + void setSelection(SCPoint where); + bool setValue(int inX, double inY, bool send); + //virtual void setPoint(int x, double y, bool send); + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + void setVisibleSize(); + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + +protected: + int indexFromPoint(SCPoint where); +// int getVisibleMax(); + + double valueFromPoint(SCPoint where); + void setValueFromPoint(SCPoint point); + SCRect calcThumbRect(int xIn, double valIn, double step); + int mThumbSize, mThumbSizeY; // size of the rect + int mTabSize, mVisibleSize; // size of the table + SCColor mFillColor; + SCColor mStrokeColor; + SCRect mThumbRect; + double mCurrentY, mCurrentX; + int mCurrentIndex, mStartIndex, mSelectionSize; + double mStepSize, mStepScale; + double * mYValues; + double * mSecYValues; + DrawBackground* mKnob; + float mXOffset ; //space between points + bool mReadOnly, mDrawLinesActive, mShowIndex, mDrawRectsActive, mIsHorizontal, mIsFilled; + SCPoint mPrevPoint; + int mElasticMode; + double mElasticIndexStep; + +}; +SCView* NewSCMultiSliderView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); +//// +//by jan truetzschler jt@kandos.de +struct SCEnvObject { + SCColor mColor; //changes between selected and mObjectColor + SCColor mObjectColor; //if its not selected + SCRect mRect; + int mNumConnection; + SCPoint mDrawPoint; + double * mConnections; //tells to where it is connected + int mNumInputs, mNumOutputs; + double x, y; + bool mIsSelected, mIsVisible, mIsStatic; + char *mString; +}; +typedef struct SCEnvObject SCEnvObject; + +class SCEnvelopeView : public SCView +{ +public: + SCEnvelopeView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCEnvelopeView(); + virtual void draw(SCRect inDamage); + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseEndTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + + void setSelection(SCPoint where, bool fixed, bool checkForConnection); + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + +protected: + + void setValueFromPoint(SCPoint point); + bool setValue(SCEnvObject * envob, double x, double y, bool send); + int allocSlotEnvObjArray(PyrSlot *slot, SCEnvObject **arr); + bool setEnvRect(double valX, double valY, SCEnvObject * envobIn); + + int mThumbSize, mThumbSizeY; // size of the rect + int mTabSize, mVisibleSize, mActiveSize; // size of the table + SCColor mFillColor, mSelectedColor, mStrokeColor; + SCRect mThumbRect; + double mCurrentY, mCurrentX, mAbsoluteX; + int mCurrentIndex, mStartIndex, mSelectionSize, mLastIndex; + double mStepSize, mStepScale; + SCEnvObject * mEnvObj; + //DrawBackground* mKnob; + bool mDrawLinesActive, mShowIndex, mDrawRectsActive, mIsFilled, mIsFixedSelection, mIsEnvView; + int mSelectedIndex; + SCPoint mMousePoint; + + double xGridMultiplier; + + //draw string in box + char mFontName[kFontNameSize]; + float mFontSize; + SCColor mStringColor; + int mAlignment; + bool mDrawCenteredConnection; + + +}; +SCView* NewSCEnvelopeView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + +// + +class SCUserView : public SCView +{ +public: + SCUserView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + virtual void draw(SCRect inDamage); + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseEndTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void keyDown(int character, int modifiers); + virtual void keyUp(int character, int modifiers); + +protected: + void mouseAction(PyrSymbol *method, SCPoint where, int modifiers); +}; +SCView* NewSCUserView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + +enum { + kSCAlignLeft = -1, + kSCAlignCenter, + kSCAlignRight +}; + +class SCStaticText : public SCView +{ +public: + SCStaticText(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCStaticText(); + + virtual void draw(SCRect inDamage); + virtual bool shouldDim(); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + +protected: + virtual void drawString(SCRect bounds); + + char *mString; + char mFontName[kFontNameSize]; + float mFontSize; + SCColor mStringColor; + int mAlignment; + +}; +SCView* NewSCStaticText(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + +class SCNumberBox : public SCStaticText +{ +public: + SCNumberBox(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCNumberBox(); + + virtual void draw(SCRect inDamage); + virtual bool shouldDim(); + + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + //virtual void mouseEndTrack(SCPoint where, int modifiers); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + +protected: + SCColor mBoxColor; +}; +SCView* NewSCNumberBox(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + +class SCDragSource : public SCStaticText +{ +public: + SCDragSource(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCDragSource(); + + virtual void draw(SCRect inDamage); + virtual bool shouldDim(); + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + +protected: +}; +SCView* NewSCDragSource(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + +class SCDragSink : public SCStaticText +{ +public: + SCDragSink(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCDragSink(); + + virtual void draw(SCRect inDamage); + virtual bool shouldDim(); + + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + +protected: +}; +SCView* NewSCDragSink(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + +class SCDragBoth : public SCDragSink +{ +public: + SCDragBoth(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + virtual void draw(SCRect inDamage); + + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + +protected: +}; +SCView* NewSCDragBoth(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + +//felix +class SCTabletView : public SCView +{ +public: + SCTabletView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCTabletView(); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseEndTrack(SCPoint where, int modifiers,NSEvent *theEvent); +protected: + int mClipToBounds; +}; +SCView* NewSCTabletView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + diff --git a/sc4pd/headers/app/SCVirtualMachine.h b/sc4pd/headers/app/SCVirtualMachine.h new file mode 100644 index 0000000..354e8a5 --- /dev/null +++ b/sc4pd/headers/app/SCVirtualMachine.h @@ -0,0 +1,65 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#import + + +@interface SCVirtualMachine : NSObject { + NSMutableArray *deferredOperations; + NSMutableArray *guiWindows; + NSTimer *deferredTaskTimer; + NSTimer *appClockTimer; +} + ++ (id)sharedInstance; + +- (id)init; +- (void)start; +- (void)doPeriodicTask: (NSTimer*) timer; +- (void)doClockTask: (NSTimer*) timer; +- (void)setCmdLine: (const char*) text length: (int)length; +- (void)sendMain: (char*) methodName; + +- (void)defer: (NSInvocation*) action; +- (void)performDeferredOperations; +- (void)doAnimatedViews; + +- (void)addWindow: (NSWindow*)window; +- (void)closeAllGUIWindows; + +- (IBAction) runMain: (id) sender; +- (IBAction) stopMain: (id) sender; +- (IBAction) compileLibrary: (id) sender; +- (IBAction) newSCWindow: (id) sender; +- (IBAction)clearPostWindow:(id)sender; +- (void)postWindowToFront:(id)sender; + +// deferred primitives + + +- (void)becomeFullScreen: (NSWindow*)window; +- (void)endFullScreen: (NSWindow*)window; +- (void)loadUserPanel:(NSString*)filename SCObject: (void*)scobj; + + +-(IBAction)showHelp:(id)sender; + + +@end diff --git a/sc4pd/headers/app/TabletEvents.h b/sc4pd/headers/app/TabletEvents.h new file mode 100755 index 0000000..3607ab9 --- /dev/null +++ b/sc4pd/headers/app/TabletEvents.h @@ -0,0 +1,75 @@ +/*---------------------------------------------------------------------------- + +FILE NAME + +TabletEvents.h - Header file for TabletEvent Category. + This is an extension to the NSEvent class. + +COPYRIGHT + +Copyright WACOM Technology, Inc. 2001. + +All rights reserved. + +----------------------------------------------------------------------------*/ + +#import +#import + +@interface NSEvent ( TabletEvents ) + +- (void *)eventRef; +- (BOOL) isTabletPointerEvent; +- (BOOL) isTabletProximityEvent; +- (void) setLocation:(NSPoint)loc; +- (TabletPointerRec) tabletRec; +- (SInt32) absoluteX; +- (SInt32) absoluteY; +- (SInt32) absoluteZ; +- (void) getAbsoluteX:(SInt32*)absX Y:(SInt32*)absY Z:(SInt32*)absZ; +- (NSPoint) tilt; +- (UInt16) rawTabletPressure; +- (float) scaledTabletPressure; +- (float) rotationInDegrees; /* 0¡ <-> +359.9999¡ */ +- (float) rotationInRadians; /* 0 <-> 2¹ */ +- (UInt16) deviceID; + +@end + +/////////////////////////////////////////////////////////////////////////// +/* This is the name of the Notification sent when a proximity event is + captured by the application */ +extern NSString *kProximityNotification; + +/* vendor-defined ID - typically will be USB vendor ID */ +extern NSString *kVendorID; + +/* vendor-defined tablet ID */ +extern NSString *kTabletID; + +/* vendor-defined ID of the specific pointing device */ +extern NSString *kPointerID; + +/* unique device ID - matches to deviceID field in tablet event */ +extern NSString *kDeviceID; + +/* unique tablet ID */ +extern NSString *kSystemTabletID; + +/* vendor-defined pointer type */ +extern NSString *kVendorPointerType; + + /* vendor-defined serial number of the specific pointing device */ +extern NSString *kPointerSerialNumber; + + /* vendor-defined unique ID for this pointer */ +extern NSString *kUniqueID; + +/* mask representing the capabilities of the device */ +extern NSString *kCapabilityMask; + + /* type of pointing device - enum to be defined */ +extern NSString *kPointerType; + + /* non-zero = entering; zero = leaving */ +extern NSString *kEnterProximity; diff --git a/sc4pd/headers/app/TextFinder.h b/sc4pd/headers/app/TextFinder.h new file mode 100644 index 0000000..66de160 --- /dev/null +++ b/sc4pd/headers/app/TextFinder.h @@ -0,0 +1,64 @@ +/* + Reusable find panel functionality (find, replace). + Need one shared instance of TextFinder to which the menu items and widgets in the find panel are connected. + Loads UI lazily. + Works on first responder, assumed to be an NSTextView. +*/ + +#import + +#define Forward YES +#define Backward NO + +@interface TextFinder : NSObject { + NSString *findString; + NSString *replaceString; + id findTextField; + id replaceTextField; + id ignoreCaseButton; + id findNextButton; + id replaceAllScopeMatrix; + id statusField; + BOOL lastFindWasSuccessful; +} + +/* Common way to get a text finder. One instance of TextFinder per app is good enough. */ ++ (id)sharedInstance; + +/* Main method for external users; does a find in the first responder. Selects found range or beeps. */ +- (BOOL)find:(BOOL)direction; + +/* Loads UI lazily */ +- (NSPanel *)findPanel; + +/* Gets the first responder and returns it if it's an NSTextView */ +- (NSTextView *)textObjectToSearchIn; + +/* Get/set the current find string. Will update UI if UI is loaded */ +- (NSString *)findString; +- (void)setFindString:(NSString *)string; +- (void)setFindString:(NSString *)string writeToPasteboard:(BOOL)flag; + +/* Get/set the current replace string. Will update UI if UI is loaded */ +- (NSString *)replaceString; +- (void)setReplaceString:(NSString *)string; + +/* Misc internal methods */ +- (void)appDidActivate:(NSNotification *)notification; +- (void)loadFindStringFromPasteboard; +- (void)loadStringToPasteboard:(NSString *)string; + +/* Action methods, sent from the find panel UI; can also be connected to menu items */ +- (void)findNext:(id)sender; +- (void)findPrevious:(id)sender; +- (void)findNextAndOrderFindPanelOut:(id)sender; +- (void)replace:(id)sender; +- (void)replaceAndFind:(id)sender; +- (void)replaceAll:(id)sender; +- (void)orderFrontFindPanel:(id)sender; +- (void)takeFindStringFromSelection:(id)sender; +- (void)takeReplaceStringFromSelection:(id)sender; +- (void)jumpToSelection:(id)sender; + +@end + diff --git a/sc4pd/headers/app/UserPanel.h b/sc4pd/headers/app/UserPanel.h new file mode 100644 index 0000000..4dd724b --- /dev/null +++ b/sc4pd/headers/app/UserPanel.h @@ -0,0 +1,40 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#import + +@interface UserPanel : NSObject +{ + IBOutlet id window; + void *scobject; +} + ++ (void)closeAll; + +- (id)init; +- (NSWindow*)window; +- (void)close; +- (void)windowWillClose:(NSNotification *)aNotification; +- (void)setSCObject: (void*)inObject; +- (void*) getSCObject; + +- (IBAction) panelAction: (id) sender; + +@end diff --git a/sc4pd/headers/common/SC_AllocPool.h b/sc4pd/headers/common/SC_AllocPool.h new file mode 100755 index 0000000..fc9d72a --- /dev/null +++ b/sc4pd/headers/common/SC_AllocPool.h @@ -0,0 +1,278 @@ + +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* +This is based on Doug Lea's allocator but rewritten so I can read and understand it... +also features of free all-at-once pools are added. +Now uses 16 byte alignment, which does increase the minimum allocation size to 32 bytes +including the overhead. +Improved bit block scanning by using a count leading zeroes instruction. + +*/ + +#ifndef _AllocPool_ +#define _AllocPool_ + +#include "SC_List.h" +#include "clz.h" +#include + +const int kNumAllocBins = 128; +const int kNumSmallBins = 64; +const int kMaxSmallBin = kNumSmallBins - 1; +const int kBinWidth = 8; +const int kMaxSmallBinSize = kNumSmallBins * kBinWidth; +const int kBinBlockWidth = 4; +const int kBinBlockMask = kBinBlockWidth - 1; + +const size_t kAlign = 16; +const size_t kAlignMask = kAlign - 1; +const size_t kChunkFree = 0; +const size_t kChunkInUse = 1; +const size_t kSizeBits = ~kChunkInUse; + +class AllocChunk; +class AllocPool; +typedef AllocChunk *AllocChunkPtr; +typedef Link AllocBin; +typedef AllocBin* AllocBinPtr; + +class AllocChunk : public Link +{ + friend class AllocPool; + + size_t Size() + { return mSize & kSizeBits; } + + size_t PrevSize() + { return mPrevSize & kSizeBits; } + + AllocChunkPtr ChunkAtOffset(size_t inSize) + { return AllocChunkPtr((char*)this + inSize); } + + AllocChunkPtr NextChunk() + { return ChunkAtOffset(Size()); } + + AllocChunkPtr PrevChunk() + { return ChunkAtOffset(-PrevSize()); } + + bool InUse() + { return (bool)(mSize & kChunkInUse); } + + bool PrevInUse() + { return (bool)(mPrevSize & kChunkInUse); } + + void SetSizeFree(size_t inSize) + { mSize = ChunkAtOffset(inSize)->mPrevSize = inSize; } + + void SetSizeInUse(size_t inSize) + { mSize = ChunkAtOffset(inSize)->mPrevSize = inSize | kChunkInUse; } + + void SetNeighborsInUse(size_t inOffset) + { mPrevSize = ChunkAtOffset(inOffset)->mSize = kChunkInUse; } + + bool IsArea() + { return mPrevSize == kChunkInUse && NextChunk()->mSize == kChunkInUse; } + + void* ToPtr() + { return (void*)((char*)this + sizeof(AllocChunk)); } + + size_t mPrevSize; + size_t mSize; +}; + +class AllocArea; +typedef AllocArea* AllocAreaPtr; + +class AllocAreaHdr /* for size calculations */ +{ +protected: + friend class AllocPool; + + AllocAreaPtr mPrev, mNext; + size_t mSize; + void *mUnalignedPointerToThis; +}; + +class AllocArea : public AllocAreaHdr +{ +public: + void SanityCheck(); + +private: + friend class AllocPool; + + AllocChunk mChunk; +}; + +const size_t kMinAllocSize = 2 * kAlign; +// FIXME: add kAlign to overhead? +const size_t kAreaOverhead = sizeof(AllocAreaHdr) + 2 * sizeof(AllocChunk); + +typedef void* (*NewAreaFunc)(size_t size); +typedef void (*FreeAreaFunc)(void *); + +class AllocPool +{ +public: + AllocPool(NewAreaFunc allocArea, FreeAreaFunc freeArea, + size_t areaInitSize, size_t areaMoreSize); + ~AllocPool(); + + void Reinit(); + + void *Alloc(size_t inBytes); + void *Realloc(void* inPtr, size_t inBytes); + void Free(void* inPtr); + void FreeAll(); + void FreeAllInternal(); + + // debugging + size_t TotalFree(); + size_t LargestFreeChunk(); + + void DoCheckPool(); + void DoCheckInUseChunk(AllocChunkPtr p); + + static AllocChunkPtr MemToChunk(void *inPtr) + { return (AllocChunkPtr)((char*)(inPtr) - sizeof(AllocChunk)); } + +private: + void InitAlloc(); + void InitBins(); + AllocAreaPtr NewArea(size_t inAreaSize); + void FreeArea(AllocChunkPtr chunk); + + // debugging + void DoCheckArea(AllocAreaPtr area); + void DoCheckBin(AllocChunkPtr bin, long idx); + void DoCheckChunk(AllocChunkPtr p); + void DoCheckFreeChunk(AllocChunkPtr p); + void DoCheckAllocedChunk(AllocChunkPtr p, size_t s); + void DoGarbageFill(AllocChunkPtr p); + void DoGarbageFill(AllocChunkPtr p, long size); + + // inlines + + static size_t RequestToSize(size_t inReqSize) + { + size_t sizePlusOverhead = inReqSize + sizeof(AllocChunk); + if (sizePlusOverhead <= kMinAllocSize) return kMinAllocSize; + else return (sizePlusOverhead + kAlignMask) & ~kAlignMask; + } + + static int SmallBinIndex(size_t inSize) + { return inSize >> 4; } + + static int BinIndex2(size_t inSize) + { + return + ((inSize < 1024) ? (inSize>>4): + (inSize < 2048) ? 56 + (inSize>>7): + (inSize < 4096) ? 64 + (inSize>>8): + (inSize < 8192) ? 72 + (inSize>>9): + (inSize < 16384) ? 80 + (inSize>>10): + (inSize < 32768) ? 88 + (inSize>>11): + (inSize < 65536) ? 96 + (inSize>>12): + (inSize < 131072) ? 104 + (inSize>>13): + (inSize < 262144) ? 112 + (inSize>>14):127); + } + + static int BinIndex(size_t inSize) + { + if (inSize < 1024) return inSize >> 4; + if (inSize >= 262144) return 127; + int bits = 28 - CLZ(inSize); + return (bits << 3) + (inSize >> bits) ; + } + + void MarkBinBlock(int inIndex) + { + unsigned long word = inIndex >> 5; + unsigned long bitPosition = inIndex & 31; + unsigned long bitValue = 1L << bitPosition; + mBinBlocks[word] |= bitValue; + } + + void ClearBinBlock(int inIndex) + { + unsigned long word = inIndex >> 5; + unsigned long bitPosition = inIndex & 31; + unsigned long bitValue = 1L << bitPosition; + mBinBlocks[word] &= ~bitValue; + } + + int NextFullBin(int inStartingBinIndex) + { + if (inStartingBinIndex >= 128) return -1; + int word = inStartingBinIndex >> 5; + int bitPosition = inStartingBinIndex & 31; + unsigned long bitValue = 1L << bitPosition; + unsigned long binBits = mBinBlocks[word]; + + if (binBits >= bitValue) { + binBits = (~(bitValue - 1) & binBits); + } else { + for (++word; word<4 && !mBinBlocks[word]; ++word) {} + if (word==4) return -1; + binBits = mBinBlocks[word]; + } + bitPosition = CTZ((int32)binBits); + + return (word << 5) + bitPosition; + } + + void LinkFree(AllocChunkPtr inChunk); + /* + { + size_t size = inChunk->Size(); + int index = BinIndex(size); + + AllocChunkPtr bin = mBins + index; + + if (index < kNumSmallBins || bin->IsEmpty()) { + inChunk->InsertAfter(bin); + MarkBinBlock(index); + } else { + AllocChunkPtr link = bin->Next(); + while (link != bin && size < link->Size()) link = link->Next(); + inChunk->InsertBefore(link); + } + } + */ + + void UnlinkFree(AllocChunkPtr inChunk) + { + inChunk->RemoveLeaveDangling(); + size_t size = inChunk->Size(); + int index = BinIndex(size); + AllocChunkPtr bin = mBins + index; + if (bin->IsEmpty()) ClearBinBlock(index); + } + + AllocChunk mBins[kNumAllocBins]; + AllocAreaPtr mAreas; + NewAreaFunc mAllocArea; + FreeAreaFunc mFreeArea; + size_t mAreaInitSize, mAreaMoreSize; + unsigned long mBinBlocks[4]; +}; + +#endif diff --git a/sc4pd/headers/common/SC_Altivec.h b/sc4pd/headers/common/SC_Altivec.h new file mode 100644 index 0000000..8ae3f66 --- /dev/null +++ b/sc4pd/headers/common/SC_Altivec.h @@ -0,0 +1,118 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2003 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SC_Altivec_ +#define _SC_Altivec_ + +#if defined(SC_LINUX) && defined(__ALTIVEC__) +# include +#endif + +#if __VEC__ + +typedef vector signed int vint32; +typedef vector unsigned int vuint32; +typedef vector float vfloat32; + +// Since gcc 3.3 vector initializers are surrounded by brackets. +#if defined(__GNUC__) && (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 3) +# define vinit(x) { x, x, x, x } +#else +# define vinit(x) ( x ) +#endif + +//#define vload(x) (*vtempptr = (x), vec_splat(vtemp,0)) +#define define_vtemp vfloat32 vtemp; float *vtempptr = (float*)&vtemp; +#define define_vones vfloat32 vones = vec_ctf(vec_splat_s32(1),0); +#define define_vzero vfloat32 vzero = (vfloat32)vec_splat_s32(0); +#define vi0123 (vec_unpackh(vec_unpackh((vector signed char)vec_lvsl(0,(int*)0)))) +#define v0123 (vec_ctf(vec_unpackh(vec_unpackh((vector signed char)vec_lvsl(0,(int*)0))), 0)) +#define v0123_4ths (vec_ctf(vec_unpackh(vec_unpackh((vector signed char)vec_lvsl(0,(int*)0))), 2)) +#define vstart(x, vslope) (vec_madd(vslope, v0123_4ths, vload(x))) + +#define vec_not(a) (vtemp = (a); vec_nor(vtemp, vtemp)) +#define vec_cmplt(a, b) (vec_cmpgt(b, a)) +#define vec_cmple(a, b) (vec_cmpge(b, a)) +#define vec_mul(a, b) (vec_madd(a, b, vzero)) +#define vec_2sComp(x) (vec_sub(vec_sub (x, x), x)) + +#define USEVEC (ft->mAltivecAvailable && !(BUFLENGTH & 3)) + +typedef union vec_union { + int32 i[4]; + float32 f[4]; + vint32 vi; + vfloat32 vf; +} vec_union; + +inline vfloat32 vload( float f ) +{ + vec_union temp; + temp.f[0] = f; + return vec_splat( vec_lde( 0, temp.f ), 0 ); +} + +inline vint32 vload( int32 i ) +{ + vec_union temp; + temp.i[0] = i; + return vec_splat( vec_lde( 0, temp.i ), 0 ); +} + +inline vint32 vload( int32 a, int32 b, int32 c, int32 d ) +{ + vec_union temp; + temp.i[0] = a; + temp.i[1] = b; + temp.i[2] = c; + temp.i[3] = d; + return temp.vi; +} + +inline vector float vec_float_1( void ) +{ + return vec_ctf( vec_splat_u32(1), 0); +} + +inline vector float vec_reciprocal( vector float v ) +{ + vector float reciprocal = vec_re( v ); + return vec_madd( reciprocal, vec_nmsub( reciprocal, v, vec_float_1()), reciprocal ); //Newton Rapheson refinement +} + +#define vec_div(a, b) vec_mul(a, vec_reciprocal(b)) + +// seed = ((seed & mask) << shift1) ^ (((seed << shift2) ^ seed) >> shift3); + +#define define_trshifts \ + vuint32 trmask = ((vuint32)(0xFFFFFFFE,0xFFFFFFF8,0xFFFFFFF0,0)); \ + vuint32 trshift1 = ((vuint32)(12, 14, 7, 0)); \ + vuint32 trshift2 = ((vuint32)(13, 2, 3, 0)); \ + vuint32 trshift3 = ((vuint32)(19, 25, 11, 0)); + +inline vuint32 trands(vuint32 seed, vuint32 trmask, vuint32 shift1, vuint32 shift2, vuint32 shift3) +{ + return vec_xor(vec_sl(vec_and(seed, trmask),shift1), vec_sr(vec_xor(vec_sl(seed,shift2),seed),shift3)); +} + +#endif +#endif + + diff --git a/sc4pd/headers/common/SC_Endian.h b/sc4pd/headers/common/SC_Endian.h new file mode 100644 index 0000000..ba127f5 --- /dev/null +++ b/sc4pd/headers/common/SC_Endian.h @@ -0,0 +1,64 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* NOTE: This file should declare/define the following functions/macros: + + htonl + htons + ntohl + ntohs + + either explicitly or implicitly by including system headers. +*/ + +#ifndef SC_ENDIAN_H_INCLUDED +#define SC_ENDIAN_H_INCLUDED + +#ifdef SC_DARWIN + +# include + +#elif defined(SC_WIN32) + +# define LITTLE_ENDIAN 1234 +# define BIG_ENDIAN 4321 +# define BYTE_ORDER LITTLE_ENDIAN +# include + +#else + +# include +# include + +#endif + +#ifndef BYTE_ORDER +# error BYTE_ORDER undefined, check __FILE__ +#endif // BYTE_ORDER + +#ifndef BIG_ENDIAN +# error BIG_ENDIAN undefined, check __FILE__ +#endif // BIG_ENDIAN + +#ifndef LITTLE_ENDIAN +# error LITTLE_ENDIAN undefined, check __FILE__ +#endif // LITTLE_ENDIAN + +#endif // SC_ENDIAN_H_INCLUDED diff --git a/sc4pd/headers/common/SC_Sem.h b/sc4pd/headers/common/SC_Sem.h new file mode 100755 index 0000000..22a2ffa --- /dev/null +++ b/sc4pd/headers/common/SC_Sem.h @@ -0,0 +1,43 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Semaphore_ +#define _SC_Semaphore_ + +#include + +class SC_Semaphore +{ +public: + SC_Semaphore(int initialCount); + ~SC_Semaphore(); + + void Acquire(); + void Release(); + +private: + pthread_cond_t available; + pthread_mutex_t mutex; + int count; +}; + +#endif + diff --git a/sc4pd/headers/common/SC_StringBuffer.h b/sc4pd/headers/common/SC_StringBuffer.h new file mode 100644 index 0000000..24bcd4d --- /dev/null +++ b/sc4pd/headers/common/SC_StringBuffer.h @@ -0,0 +1,67 @@ +// emacs: -*- c++ -*- +// file: SC_StringBuffer.h +// copyright: 2003 stefan kersten +// cvs: $Id: SC_StringBuffer.h,v 1.1.1.1 2004-07-14 16:21:36 timblech Exp $ + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA + +#ifndef SC_STRINGBUFFER_H_INCLUDED +#define SC_STRINGBUFFER_H_INCLUDED + +#include +#include + +// ===================================================================== +// SC_StringBuffer - Autogrowing string buffer. +// ===================================================================== + +class SC_StringBuffer +{ +public: + SC_StringBuffer(size_t initialSize=0); + SC_StringBuffer(const SC_StringBuffer& other); + ~SC_StringBuffer(); + + size_t getCapacity() const { return mCapacity; } + size_t getSize() const { return mPtr - mData; } + size_t getRemaining() const { return mCapacity - getSize(); } + char* getData() const { return mData; } + + bool isEmpty() const { return getSize() == 0; } + + void finish() { append('\0'); } + void reset() { mPtr = mData; } + void append(const char* src, size_t len); + void append(char c); + void append(const char* str); + void vappendf(const char* fmt, va_list vargs); + void appendf(const char* fmt, ...); + +protected: + enum { + kGrowAlign = 256, + kGrowMask = kGrowAlign - 1 + }; + + void growBy(size_t request); + +private: + size_t mCapacity; + char* mPtr; + char* mData; +}; + +#endif // SC_STRINGBUFFER_H_INCLUDED diff --git a/sc4pd/headers/common/SC_StringParser.h b/sc4pd/headers/common/SC_StringParser.h new file mode 100644 index 0000000..f2d414e --- /dev/null +++ b/sc4pd/headers/common/SC_StringParser.h @@ -0,0 +1,40 @@ +// emacs: -*- c++ -*- +// file: SC_StringParser.h +// copyright: 2003 stefan kersten +// cvs: $Id: SC_StringParser.h,v 1.1.1.1 2004-07-14 16:21:37 timblech Exp $ + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA + +#ifndef _SC_StringParser_ +#define _SC_StringParser_ + +#define SC_MAX_TOKEN_LENGTH 256 + +class SC_StringParser +{ + char *mSpec, *mStart, *mEnd; + char mSep, mBuf[SC_MAX_TOKEN_LENGTH]; + +public: + SC_StringParser(); + SC_StringParser(char *spec, char sep); + + bool AtEnd() const; + const char *NextToken(); +}; + +#endif + diff --git a/sc4pd/headers/common/dfftlib.h b/sc4pd/headers/common/dfftlib.h new file mode 100755 index 0000000..409267e --- /dev/null +++ b/sc4pd/headers/common/dfftlib.h @@ -0,0 +1,62 @@ +long dFFTInit(long *fftMptr, long fftN, double *Utbl); +/* Compute cosine table and check size for complex ffts */ +/* INPUTS */ +/* fftN = size of fft */ +/* OUTPUTS */ +/* *fftMptr = log2 of fft size */ +/* *Utbl = cosine table with fftN/4 + 1 entries (angles = 0 to pi/2 inclusive) */ +/* RETURNS */ +/* 1 if fftN is invalid, 0 otherwise */ + +long drFFTInit(long *fftMptr, long fftN, double *Utbl); +/* Compute cosine table and check size for a real input fft */ +/* INPUTS */ +/* fftN = size of fft */ +/* OUTPUTS */ +/* *fftMptr = log2 of fft size */ +/* *Utbl = cosine table with fftN/4 + 1 entries (angles = 0 to pi/2 inclusive) */ +/* RETURNS */ +/* 1 if fftN is invalid, 0 otherwise */ + +void dffts(double *ioptr, long M, long Rows, double *Utbl); +/* Compute in-place complex fft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = input data array */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = output data array */ + +void diffts(double *ioptr, long M, long Rows, double *Utbl); +/* Compute in-place inverse complex fft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = input data array */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = output data array */ + +void drffts(double *ioptr, long M, long Rows, double *Utbl); +/* Compute in-place real fft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = real input data array */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = output data array in the following order */ +/* Re(x[0]), Re(x[N/2]), Re(x[1]), Im(x[1]), Re(x[2]), Im(x[2]), ... Re(x[N/2-1]), Im(x[N/2-1]). */ + + +void driffts(double *ioptr, long M, long Rows, double *Utbl); +/* Compute in-place real ifft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = input data array in the following order */ +/* Re(x[0]), Re(x[N/2]), Re(x[1]), Im(x[1]), Re(x[2]), Im(x[2]), ... Re(x[N/2-1]), Im(x[N/2-1]). */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = real output data array */ diff --git a/sc4pd/headers/common/dlfcn.h b/sc4pd/headers/common/dlfcn.h new file mode 100755 index 0000000..62966d0 --- /dev/null +++ b/sc4pd/headers/common/dlfcn.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.1 (the "License"). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. + * + * The Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +#ifdef __cplusplus +extern "C" +{ +#endif + void * dlopen(const char *path, int mode); + void * dlsym(void * handle, const char *symbol); + const char * dlerror(void); + int dlclose(void * handle); +#ifdef __cplusplus +} +#endif + +#define RTLD_LAZY 0x1 +#define RTLD_NOW 0x2 +#define RTLD_LOCAL 0x4 +#define RTLD_GLOBAL 0x8 +#define RTLD_NOLOAD 0x10 +#define RTLD_SHARED 0x20 /* not used, the default */ +#define RTLD_UNSHARED 0x40 +#define RTLD_NODELETE 0x80 +#define RTLD_LAZY_UNDEF 0x100 diff --git a/sc4pd/headers/common/fftlib.h b/sc4pd/headers/common/fftlib.h new file mode 100755 index 0000000..b03317d --- /dev/null +++ b/sc4pd/headers/common/fftlib.h @@ -0,0 +1,62 @@ +long FFTInit(long *fftMptr, long fftN, float *Utbl); +/* Compute cosine table and check size for complex ffts */ +/* INPUTS */ +/* fftN = size of fft */ +/* OUTPUTS */ +/* *fftMptr = log2 of fft size */ +/* *Utbl = cosine table with fftN/4 + 1 entries (angles = 0 to pi/2 inclusive) */ +/* RETURNS */ +/* 1 if fftN is invalid, 0 otherwise */ + +long rFFTInit(long *fftMptr, long fftN, float *Utbl); +/* Compute cosine table and check size for a real input fft */ +/* INPUTS */ +/* fftN = size of fft */ +/* OUTPUTS */ +/* *fftMptr = log2 of fft size */ +/* *Utbl = cosine table with fftN/4 + 1 entries (angles = 0 to pi/2 inclusive) */ +/* RETURNS */ +/* 1 if fftN is invalid, 0 otherwise */ + +void ffts(float *ioptr, long M, long Rows, float *Utbl); +/* Compute in-place complex fft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = input data array */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = output data array */ + +void iffts(float *ioptr, long M, long Rows, float *Utbl); +/* Compute in-place inverse complex fft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = input data array */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = output data array */ + +void rffts(float *ioptr, long M, long Rows, float *Utbl); +/* Compute in-place real fft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = real input data array */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = output data array in the following order */ +/* Re(x[0]), Re(x[N/2]), Re(x[1]), Im(x[1]), Re(x[2]), Im(x[2]), ... Re(x[N/2-1]), Im(x[N/2-1]). */ + + +void riffts(float *ioptr, long M, long Rows, float *Utbl); +/* Compute in-place real ifft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = input data array in the following order */ +/* Re(x[0]), Re(x[N/2]), Re(x[1]), Im(x[1]), Re(x[2]), Im(x[2]), ... Re(x[N/2-1]), Im(x[N/2-1]). */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = real output data array */ diff --git a/sc4pd/headers/common/scsynthsend.h b/sc4pd/headers/common/scsynthsend.h new file mode 100644 index 0000000..97f345b --- /dev/null +++ b/sc4pd/headers/common/scsynthsend.h @@ -0,0 +1,191 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _scpacket_ +#define _scpacket_ + +#include "SC_Endian.h" +#include "SC_Types.h" +#include + +struct netaddr { + int socket; + int addr; + int port; +}; +typedef struct netaddr netaddr; + +#define kSCMaxPacketSize 8192 + +struct scpacket { + int32 *wrpos, *endpos, *msgsizepos; + char *tagwrpos; + int inbundle; + int32 buf[kSCMaxPacketSize]; + + scpacket(); + void reset(); + void addi(int i); + void addii(int64 ii); + void addf(float f); + void addd(double f); + void adds(char *cstr); + void adds(char *src, size_t len); + void addb(uint8 *src, size_t len); + void addtag(char c); + void skip(int n); + void maketags(int n); + int size() { return (char*)wrpos - (char*)buf; } + char* data() { return (char*)buf; } + + void sendudp(int socket, int addr, int port); + + void OpenBundle(int64 time); + void CloseBundle(); + + void BeginMsg(); + void EndMsg(); +}; + +inline scpacket::scpacket() { reset(); } + +// ways to fail +#define BUFFEROVERFLOW return +//#define BUFFEROVERFLOW throw std::runtime_error("buffer overflow") + +inline void scpacket::reset() +{ + wrpos = buf; + endpos = buf + kSCMaxPacketSize; + inbundle = 0; +} + +inline void scpacket::skip(int n) +{ + if (wrpos + n > endpos) BUFFEROVERFLOW; + wrpos += n; +} + +inline void scpacket::addtag(char c) +{ + *tagwrpos++ = c; +} + +inline void scpacket::maketags(int n) +{ + int size4 = (n + 4) >> 2; + tagwrpos = (char*)wrpos; + skip(size4); + wrpos[-1] = 0; +} + + +inline void scpacket::addi(int i) +{ + if (wrpos >= endpos) BUFFEROVERFLOW; + *wrpos++ = htonl(i); +} + +inline void scpacket::addii(int64 ii) +{ + int i; + i = (int)(ii >> 32); + addi(i); + i = (int)ii; + addi(i); +} + +inline void scpacket::addf(float f) +{ + if (wrpos >= endpos) BUFFEROVERFLOW; + elem32 slot; + slot.f = f; + *wrpos++ = htonl(slot.i); +} + +inline void scpacket::addd(double f) +{ + if (wrpos >= endpos) BUFFEROVERFLOW; + elem64 slot; + slot.f = f; + *wrpos++ = htonl(slot.i >> 32); + *wrpos++ = htonl(slot.i & 0x00000000FFFFFFFF); +} + +inline void scpacket::adds(char *src) +{ + size_t len = strlen(src); + size_t len4 = (len + 4) >> 2; + if (wrpos + len4 > endpos) BUFFEROVERFLOW; + wrpos[len4 - 1] = 0; + memcpy(wrpos, src, (size_t)len); + wrpos += len4; +} + +inline void scpacket::adds(char *src, size_t len) +{ + size_t len4 = (len + 4) >> 2; + if (wrpos + len4 > endpos) BUFFEROVERFLOW; + wrpos[len4 - 1] = 0; + memcpy(wrpos, src, (size_t)len); + wrpos += len4; +} + +// support binary objects +inline void scpacket::addb(uint8 *src, size_t len) +{ + size_t len4 = (len + 3) >> 2; + if (wrpos + (len4 + 1) > endpos) BUFFEROVERFLOW; + wrpos[len4 - 1] = 0; + int32 swaplen = len; + *wrpos++ = htonl(swaplen); + memcpy(wrpos, src, (size_t)len); + wrpos += len4; +} + +inline void scpacket::OpenBundle(int64 time) +{ + inbundle++; + adds("#bundle"); + addii(time); +} + +inline void scpacket::CloseBundle() +{ + if (inbundle) inbundle--; +} + +inline void scpacket::BeginMsg() +{ + if (inbundle) { + msgsizepos = wrpos; + addi(0); + } +} + +inline void scpacket::EndMsg() +{ + if (inbundle) { + *msgsizepos = htonl(((wrpos - msgsizepos) - 1) * sizeof(int32)); + } +} + +#endif + diff --git a/sc4pd/headers/lang/AdvancingAllocPool.h b/sc4pd/headers/lang/AdvancingAllocPool.h new file mode 100755 index 0000000..b89d69b --- /dev/null +++ b/sc4pd/headers/lang/AdvancingAllocPool.h @@ -0,0 +1,82 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +AdvancingAllocPool implements a simple advancing pointer allocation scheme. +There is no Free(). All objects in the pool are freed at once with FreeAll(). +Thus it is very fast. + +*/ + +#ifndef _AdvancingAllocPool_ +#define _AdvancingAllocPool_ + +#include +#include + +class AllocPool; + +struct AdvancingAllocPoolChunk; + +typedef int int32; + +inline void FailNil(void *ptr) { + if (!ptr) throw std::runtime_error("alloc failed"); +} + +struct AdvancingAllocPoolChunkHdr { + AdvancingAllocPoolChunk *mNext; + size_t mSize; + int32 mPad1, mPad2; +}; + +struct AdvancingAllocPoolChunk { + AdvancingAllocPoolChunk *mNext; + size_t mSize; + int32 mPad1, mPad2; + char mSpace[16]; +}; + +class AdvancingAllocPool +{ +public: + AdvancingAllocPool(); + ~AdvancingAllocPool() { FreeAll(); } + + void Init(AllocPool *inAllocPool, size_t initSize, size_t growSize, size_t tooBigSize); + + void *Alloc(size_t inBytes); + void FreeAll(); + + bool SanityCheck(); + +private: + void AddChunk(size_t inSize); + + AllocPool* mAllocPool; + size_t mInitSize; + size_t mGrowSize; + size_t mCurSize; + size_t mTooBig; + AdvancingAllocPoolChunk *mChunks; + AdvancingAllocPoolChunk *mFatties; +}; + +#endif diff --git a/sc4pd/headers/lang/AllocPools.h b/sc4pd/headers/lang/AllocPools.h new file mode 100755 index 0000000..111f7c3 --- /dev/null +++ b/sc4pd/headers/lang/AllocPools.h @@ -0,0 +1,34 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +Pools for memory allocation. + +*/ + + +#ifndef _AllocPools_ +#define _AllocPools_ + +class AllocPool; +extern AllocPool *pyr_pool_compile; +extern AllocPool *pyr_pool_runtime; + +#endif diff --git a/sc4pd/headers/lang/ByteCodeArray.h b/sc4pd/headers/lang/ByteCodeArray.h new file mode 100755 index 0000000..5ec1520 --- /dev/null +++ b/sc4pd/headers/lang/ByteCodeArray.h @@ -0,0 +1,50 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +typedef unsigned char Byte; + +#define BYTE_CODE_CHUNK_SIZE 64 + +typedef struct { + Byte *bytes; + Byte *ptr; + long size; +} ByteCodeArray, *ByteCodes; + +extern ByteCodes gCompilingByteCodes; +extern long totalByteCodes; + +void initByteCodes(); +void compileByte(long byte); +void compileAndFreeByteCodes(ByteCodes byteCodes); +void copyByteCodes(Byte *dest, ByteCodes byteCodes); +ByteCodes getByteCodes(); +ByteCodes saveByteCodeArray(); +void restoreByteCodeArray(ByteCodes byteCodes); +int byteCodeLength(ByteCodes byteCodes); +void compileByteCodes(ByteCodes byteCodes); +ByteCodes allocByteCodes(); +void reallocByteCodes(ByteCodes byteCodes); +void freeByteCodes(ByteCodes byteCodes); +int compileOpcode(long opcode, long operand1); +void compileJump(long opcode, long jumplen); +int compileNumber(unsigned long value); +int compileNumber24(unsigned long value); + diff --git a/sc4pd/headers/lang/FIFOT.h b/sc4pd/headers/lang/FIFOT.h new file mode 100755 index 0000000..52b6203 --- /dev/null +++ b/sc4pd/headers/lang/FIFOT.h @@ -0,0 +1,75 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +A Fifo for sending/receiving some type of object. + +*/ + +#ifndef _FIFOT_ +#define _FIFOT_ + +template class FIFOT +{ +public: + FIFOT() + : mMask(N-1), mReadHead(0), mWriteHead(0) + { + } + void MakeEmpty() { mReadHead = mWriteHead; } + bool IsEmpty() { return mReadHead == mWriteHead; } + int CanGet() { + int diff = mWriteHead - mReadHead; + return diff >= 0 ? diff : N - diff; + } + int CanPut() { return N-1-CanGet(); } + + int NextPos(int inPos) { return (inPos + 1) & mMask; } + + bool Put(const T& inItem) + { + long next = NextPos(mWriteHead); + if (next == mReadHead) return false; // fifo is full + mItems[next] = inItem; + mWriteHead = next; + return true; + } + + bool Get(T& outItem) // get next and advance + { + if (IsEmpty()) return false; + long next = NextPos(mReadHead); + outItem = mItems[next]; + mReadHead = next; + return true; + } + void DebugDump() + { + post("FIFO N %d mMask %d mReadHead %d mWriteHead%d\n", + N, mMask, mReadHead, mWriteHead); + } + +private: + long mMask; + volatile long mReadHead, mWriteHead;// mReclaimHead; + T mItems[N]; +}; + +#endif \ No newline at end of file diff --git a/sc4pd/headers/lang/GC.h b/sc4pd/headers/lang/GC.h new file mode 100755 index 0000000..4dc162a --- /dev/null +++ b/sc4pd/headers/lang/GC.h @@ -0,0 +1,263 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +The garbage collector for SuperCollider. +Based on Wilson and Johnstone's real time collector and the Baker treadmill. + +*/ + +#ifndef _GC_ +#define _GC_ + +#include "PyrObject.h" +#include "VMGlobals.h" +#include "AdvancingAllocPool.h" + +void DumpSimpleBackTrace(VMGlobals *g); + +const int kMaxPoolSet = 7; +const int kNumGCSizeClasses = 28; +const int kFinalizerSet = kNumGCSizeClasses; +const int kNumGCSets = kNumGCSizeClasses + 1; + +class GCSet +{ +public: + GCSet() {} + void Init(int inSizeClass); + + bool HasFree() { return mFree != &mBlack; } + +private: + friend class PyrGC; + + void MoveWhiteToFree(); + + PyrObjectHdr mBlack; + PyrObjectHdr mWhite; + PyrObjectHdr* mFree; +}; + +struct SlotRef { + SlotRef(PyrObject* inObj, int32 inIndex) : obj(inObj), slotIndex(inIndex) {} + + PyrObject *obj; + int32 slotIndex; +}; + +class PyrGC +{ +public: + PyrGC(VMGlobals *g, AllocPool *inPool, PyrClass *mainProcessClass, long poolSize); + + PyrObject* New(size_t inNumBytes, long inFlags, long inFormat, bool inCollect); + + static PyrObject* NewPermanent(size_t inNumBytes, + long inFlags, long inFormat); + + PyrObject* NewFinalizer(ObjFuncPtr finalizeFunc, PyrObject *inObject, bool inCollect); + + int32 ProcessID() { return mProcessID; } + +#if 0 +// Codewarrior is not inlining these.. why? + bool IsBlack(PyrObjectHdr* inObj) { return inObj->gc_color == mBlackColor; } + bool IsWhite(PyrObjectHdr* inObj) { return inObj->gc_color == mWhiteColor; } + bool IsGrey(PyrObjectHdr* inObj) { return inObj->gc_color == mGreyColor; } + bool IsMarker(PyrObjectHdr* inObj) { return inObj->gc_color == obj_gcmarker; } +#else + +#define IsBlack(inObj) ((inObj)->gc_color == mBlackColor) +#define IsWhite(inObj) ((inObj)->gc_color == mWhiteColor) +#define IsGrey(inObj) ((inObj)->gc_color == mGreyColor) +#define IsFree(inObj) (!(IsMarker(inObj) || inObj->IsPermanent() || \ + IsBlack(inObj) || IsWhite(inObj) || IsGrey(inObj))) +#define IsMarker(inObj) ((inObj)->gc_color == obj_gcmarker) +#endif + + bool ObjIsBlack(PyrObjectHdr* inObj) { return IsBlack(inObj); } + bool ObjIsGrey(PyrObjectHdr* inObj) { return IsGrey(inObj); } + bool ObjIsFree(PyrObjectHdr* inObj) { return IsFree(inObj); } + + + // general purpose write barriers: + void GCWrite(PyrObjectHdr* inParent, PyrSlot* inSlot) + { + if (IsBlack(inParent) && IsObj(inSlot) && IsWhite(inSlot->uo)) { + ToGrey(inSlot->uo); + } + } + void GCWrite(PyrObjectHdr* inParent, PyrObjectHdr* inChild) + { + if (IsBlack(inParent) && IsWhite(inChild)) { + ToGrey(inChild); + } + } + // when you know the parent is black: + void GCWriteBlack(PyrSlot* inSlot) + { + if (IsObj(inSlot)) { + if (IsWhite(inSlot->uo)) { + ToGrey(inSlot->uo); + } + } + } + void GCWriteBlack(PyrObjectHdr* inChild) + { + if (IsWhite(inChild)) { + ToGrey(inChild); + } + } + // when you know the child is white + void GCWriteNew(PyrObjectHdr* inParent, PyrObjectHdr* inChild) + { + if (IsBlack(inParent)) { + ToGrey(inChild); + } + } + +// users should not call anything below. + + void Collect(); + void Collect(int32 inNumToScan); + void FullCollection(); + void ScanFinalizers(); + GCSet* GetGCSet(PyrObjectHdr* inObj); + void CompletePartialScan(PyrObject *obj); + + void ToGrey(PyrObjectHdr* inObj); + void ToGrey2(PyrObjectHdr* inObj); + void ToBlack(PyrObjectHdr* inObj); + void ToWhite(PyrObjectHdr *obj); + + int32 StackDepth() { return mVMGlobals->sp - mStack->slots + 1; } + PyrObject* Stack() { return mStack; } + void SetStack(PyrObject* inStack) { mStack = inStack; } + + bool SanityCheck(); + bool SanityCheck2(); + bool LinkSanity(); + bool ListSanity(); + bool BlackToWhiteCheck(PyrObject *objA); + bool SanityMarkObj(PyrObject *objA, PyrObject *fromObj, int level); + bool SanityClearObj(PyrObject *objA, int level); + void DumpInfo(); + void DumpEverything(); + + void BecomePermanent(PyrObject *inObject); + void BecomeImmutable(PyrObject *inObject); + +private: + void Free(PyrObject* inObj); + void ScanSlots(PyrSlot *inSlots, long inNumToScan); + void SweepBigObjects(); + void DoPartialScan(int32 inObjSize); + bool ScanOneObj(); + void Flip(); + void ScanStack(); + void DLRemove(PyrObjectHdr *obj); + void DLInsertAfter(PyrObjectHdr *after, PyrObjectHdr *obj); + void DLInsertBefore(PyrObjectHdr *before, PyrObjectHdr *obj); + + void ClearMarks(); + void Finalize(PyrObject *obj); + + VMGlobals *mVMGlobals; + AllocPool *mPool; + AdvancingAllocPool mNewPool; + GCSet mSets[kNumGCSets]; + PyrProcess *mProcess; // the root is the pyrprocess which contains this struct + PyrObject *mStack; + PyrObject *mPartialScanObj; + PyrObjectHdr mGrey; + + GCSet *mPartialScanSet; + int32 mPartialScanSlot; + int32 mNumToScan; + int32 mNumGrey; + int32 mCurSet; + + int32 mFlips, mCollects, mAllocTotal, mScans, mNumAllocs; + + unsigned char mBlackColor, mGreyColor, mWhiteColor, mFreeColor; + int8 mProcessID; + bool mCanSweep; + bool mRunning; +}; + +inline void PyrGC::DLRemove(PyrObjectHdr *obj) +{ + obj->next->prev = obj->prev; + obj->prev->next = obj->next; +} + +inline void PyrGC::DLInsertAfter(PyrObjectHdr *after, PyrObjectHdr *obj) +{ + obj->next = after->next; + obj->prev = after; + after->next->prev = obj; + after->next = obj; +} + +inline void PyrGC::DLInsertBefore(PyrObjectHdr *before, PyrObjectHdr *obj) +{ + obj->prev = before->prev; + obj->next = before; + before->prev->next = obj; + before->prev = obj; +} + +inline GCSet* PyrGC::GetGCSet(PyrObjectHdr* inObj) +{ + return mSets + (inObj->classptr == class_finalizer ? kFinalizerSet : inObj->obj_sizeclass); +} + +inline void PyrGC::ToBlack(PyrObjectHdr *obj) +{ + if (IsGrey(obj)) { + mNumGrey--; + //post("ToBlack %d\n", mNumGrey); + } + + DLRemove(obj); + + GCSet *gcs = GetGCSet(obj); + DLInsertAfter(&gcs->mBlack, obj); + + obj->gc_color = mBlackColor; +} + +inline void PyrGC::ToWhite(PyrObjectHdr *obj) +{ + if (IsGrey(obj)) { + mNumGrey--; + //post("ToWhite %d\n", mNumGrey); + } + + DLRemove(obj); + + GCSet *gcs = GetGCSet(obj); + DLInsertAfter(&gcs->mWhite, obj); + + obj->gc_color = mWhiteColor; +} + +#endif diff --git a/sc4pd/headers/lang/HashTable.h b/sc4pd/headers/lang/HashTable.h new file mode 100755 index 0000000..835f593 --- /dev/null +++ b/sc4pd/headers/lang/HashTable.h @@ -0,0 +1,274 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _HashTable_ +#define _HashTable_ + +#include "SC_Types.h" +#include "SC_BoundsMacros.h" +#include "Hash.h" +#include + +template +class HashTable +{ + Allocator *mPool; + int32 mNumItems, mMaxItems, mTableSize, mHashMask; + T** mItems; + bool mCanResize; + +public: + + HashTable(Allocator *inPool, int32 inMaxItems, bool inCanResize = true) + : mPool(inPool) + { + mNumItems = 0; + mMaxItems = inMaxItems; + mTableSize = mMaxItems << 1; + mItems = AllocTable(mTableSize); + mHashMask = mTableSize - 1; + mCanResize = inCanResize; + } + + ~HashTable() { + mPool->Free(mItems); + } + + int32 TableSize() const { return mTableSize; } + int32 MaxItems() const { return mMaxItems; } + int32 NumItems() const { return mNumItems; } + + T** AllocTable(int inTableSize) + { + size_t size = inTableSize * sizeof(T*); + T** items = static_cast(mPool->Alloc(size)); + for (int i=0; i> 1; + mHashMask = mTableSize - 1; + mPool->Free(oldItems); + //printf("mMaxItems %d mTableSize %d newSize %d\n", mMaxItems, mTableSize, newSize); + } + + bool Add(T* inItem) + { + //printf("mNumItems %d\n", mNumItems); + //printf("mMaxItems %d\n", mMaxItems); + //printf("mCanResize %d\n", mCanResize); + if (mNumItems >= mMaxItems) { + if (!mCanResize) return false; + Resize(); + } + + //printf("GetHash(inItem) %d\n", GetHash(inItem)); + //printf("GetKey(inItem) %s\n", GetKey(inItem)); + int32 index = IndexFor(GetHash(inItem), GetKey(inItem)); + //printf("index %d\n", index); + + T *item = mItems[index]; + if (item) return item == inItem; + + mItems[index] = inItem; + mNumItems++; + return true; + } + + bool Remove(T* inItem) + { + int32 index = IndexFor(GetHash(inItem), GetKey(inItem)); + if (mItems[index] != inItem) return false; + mItems[index] = 0; + + FixCollisionsFrom(index); + mNumItems--; + return true; + } + + int32 IndexFor(int32 inHashID, KeyType inKey) const + { + int index = inHashID & mHashMask; + for(;;) { + T *item = mItems[index]; + if (!item) return index; + if (GetHash(item) == inHashID + && strcmp(inKey, GetKey(item)) == 0) return index; + index = (index + 1) & mHashMask; + } + } + + T* Get(KeyType inKey) const + { + return Get(Hash(inKey), inKey); + } + + T* Get(int32 inHashID, KeyType inKey) const + { + int32 index = IndexFor(inHashID, inKey); + return mItems[index]; + } + + bool Includes(T* inItem) const + { + return Get(GetHash(inItem), GetKey(inItem)) == inItem; + } + + T* AtIndex(int32 inIndex) const + { + return mItems[inIndex]; + } + +private: + void FixCollisionsFrom(int32 inIndex) + { + int oldIndex = inIndex; + for (;;) { + oldIndex = (oldIndex + 1) & mHashMask; + T *oldItem = mItems[oldIndex]; + if (!oldItem) break; + int newIndex = IndexFor(GetHash(oldItem), GetKey(oldItem)); + if (oldIndex != newIndex) { + mItems[oldIndex] = mItems[newIndex]; + mItems[newIndex] = oldItem; + } + } + } +}; + +template +class StaticHashTable +{ + int32 mNumItems, mTableSize, mHashMask; + T* mItems[kMaxItems*2]; + +public: + + StaticHashTable() + { + mNumItems = 0; + mTableSize = kMaxItems << 1; + ClearTable(); + mHashMask = mTableSize - 1; + } + + ~StaticHashTable() { + } + + int32 TableSize() const { return mTableSize; } + int32 MaxItems() const { return kMaxItems; } + int32 NumItems() const { return mNumItems; } + + void ClearTable() + { + for (int i=0; i= kMaxItems) return false; + + int32 index = IndexFor(GetHash(inItem), GetKey(inItem)); + + T *item = mItems[index]; + if (item) return item == inItem; + + mItems[index] = inItem; + mNumItems++; + return true; + } + + bool Remove(T* inItem) + { + int32 index = IndexFor(GetHash(inItem), GetKey(inItem)); + if (mItems[index] != inItem) return false; + mItems[index] = 0; + + FixCollisionsFrom(index); + mNumItems--; + return true; + } + + int32 IndexFor(int32 inHashID, KeyType inKey) const + { + int index = inHashID & mHashMask; + for(;;) { + T *item = mItems[index]; + if (!item) return index; + if (GetHash(item) == inHashID + && strcmp(inKey, GetKey(item)) == 0) return index; + index = (index + 1) & mHashMask; + } + } + + T* Get(KeyType inKey) const + { + return Get(Hash(inKey), inKey); + } + + T* Get(int32 inHashID, KeyType inKey) const + { + int32 index = IndexFor(inHashID, inKey); + return mItems[index]; + } + + bool Includes(T* inItem) const + { + return Get(GetHash(inItem), GetKey(inItem)) == inItem; + } + + T* AtIndex(int32 inIndex) const + { + return mItems[inIndex]; + } + +private: + void FixCollisionsFrom(int32 inIndex) + { + int oldIndex = inIndex; + for (;;) { + oldIndex = (oldIndex + 1) & mHashMask; + T *oldItem = mItems[oldIndex]; + if (!oldItem) break; + int newIndex = IndexFor(GetHash(oldItem), GetKey(oldItem)); + if (oldIndex != newIndex) { + mItems[oldIndex] = mItems[newIndex]; + mItems[newIndex] = oldItem; + } + } + } +}; + + +#endif diff --git a/sc4pd/headers/lang/InitAlloc.h b/sc4pd/headers/lang/InitAlloc.h new file mode 100755 index 0000000..762b940 --- /dev/null +++ b/sc4pd/headers/lang/InitAlloc.h @@ -0,0 +1,32 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _InitAlloc_ +#define _InitAlloc_ + +#include "SCBase.h" +#include "SC_AllocPool.h" +#include + +#define MEMFAIL(ptr) if (!(ptr)) { throw std::runtime_error("Out of memory!\n"); } +#define MEMFAILED throw std::runtime_error("Out of memory!\n"); + +#endif + diff --git a/sc4pd/headers/lang/MiscInlineMath.h b/sc4pd/headers/lang/MiscInlineMath.h new file mode 100755 index 0000000..6dd33ab --- /dev/null +++ b/sc4pd/headers/lang/MiscInlineMath.h @@ -0,0 +1,54 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#define NUMPRIMES 6542 +long nthPrime(int n); +long findPrime(int n); +long prevPrime(int n); +long nextPrime(int n); + + +inline double linlin(double x, double a, double b, double c, double d) +{ + if (x <= a) return c; + if (x >= b) return d; + return (x-a)/(b-a) * (d-c) + c; +} + +inline double explin(double x, double a, double b, double c, double d) +{ + if (x <= a) return c; + if (x >= b) return d; + return (log(x/a)) / (log(b/a)) * (d-c) + c; +} + +inline double expexp(double x, double a, double b, double c, double d) +{ + if (x <= a) return c; + if (x >= b) return d; + return pow(d/c, log(x/a)) / (log(b/a)) * c; +} + +inline double linexp(double x, double a, double b, double c, double d) +{ + if (x <= a) return c; + if (x >= b) return d; + return pow(d/c, (x-a)/(b-a)) * c; +} diff --git a/sc4pd/headers/lang/OSCData.h b/sc4pd/headers/lang/OSCData.h new file mode 100755 index 0000000..b2721b0 --- /dev/null +++ b/sc4pd/headers/lang/OSCData.h @@ -0,0 +1 @@ +/* SuperCollider real time audio synthesis system Copyright (c) 2002 James McCartney. All rights reserved. http://www.audiosynth.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _OSCData_ #define _OSCData_ #include "PyrObject.h" #include "FIFOT.h" #include #endif \ No newline at end of file diff --git a/sc4pd/headers/lang/Opcodes.h b/sc4pd/headers/lang/Opcodes.h new file mode 100755 index 0000000..c5e1c7a --- /dev/null +++ b/sc4pd/headers/lang/Opcodes.h @@ -0,0 +1,426 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _OPCODES_H_ +#define _OPCODES_H_ + +/* opcodes */ +enum { + opExtended, // 0 + opPushInstVar, + opPushTempVar, + opPushTempZeroVar, + opPushLiteral, + opPushClassVar, // 5 + opPushSpecialValue, + opStoreInstVar, + opStoreTempVar, + opStoreClassVar, + opSendMsg, // 10 + opSendSuper, + opSendSpecialMsg, + opSendSpecialUnaryArithMsg, + opSendSpecialBinaryArithMsg, + opSpecialOpcode, // 15 + + + opNumOpcodes +}; + +/* special opcodes */ +enum { + opcDrop, // 0 + opcDup, + opcFunctionReturn, + opcReturn, + opcReturnSelf, + opcReturnTrue, // 5 + opcReturnFalse, + opcReturnNil, + opcJumpIfFalse, // IF 3 args + opcJumpIfFalsePushNil, // IF 2 args + opcJumpIfFalsePushFalse, // AND: (10) + opcJumpIfTruePushTrue, // OR: + opcJumpFwd, + opcJumpBak, + opcSpecialBinaryOpWithAdverb, + opcSuperNew, // 15 + + opcNewList, + + opcNumSpecialOpcodes +/* + opcSlotAt, + opcByteAt, // 15 + opcShortAt, + opcInt32At, + opcColorAt, + opcFloatAt, + opcDoubleAt +*/ +}; + +/* special unary math operators */ +enum { + opNeg, + opNot, + opIsNil, + opNotNil, + opBitNot, + opAbs, + opAsFloat, + opAsInt, + opCeil, //5 + opFloor, + opFrac, + opSign, + opSquared, + opCubed, //10 + opSqrt, + opExp, + opRecip, + opMIDICPS, + opCPSMIDI, //15 + + opMIDIRatio, + opRatioMIDI, + opDbAmp, + opAmpDb, + opOctCPS, //20 + opCPSOct, + opLog, + opLog2, + opLog10, + opSin, //25 + opCos, + opTan, + opArcSin, + opArcCos, + opArcTan, + opSinH, + opCosH, //30 + opTanH, + opRand, + opRand2, + opLinRand, + opBiLinRand, + +// opExpRand, +// opBiExpRand, + opSum3Rand, +// opGammaRand, +// opGaussRand, +// opPoiRand, + + opDistort, + opSoftClip, + opCoin, + + opDigitValue, + opSilence, + opThru, + opRectWindow, + opHanWindow, + opWelchWindow, + opTriWindow, + + opRamp, + opSCurve, + + opNumUnarySelectors +}; + +#define IS_UNARY_BOOL_OP(op) ((op)>=opCoin && (op)<=opOdd) +#define IS_BINARY_BOOL_OP(op) ((op)>=opEQ && (op)<=opGE) + +/* special binary math operators */ +enum { + opAdd, + opSub, + opMul, + opIDiv, + opFDiv, + opMod, + opEQ, + opNE, + opLT, + opGT, + opLE, + opGE, + //opIdentical, + //opNotIdentical, + + opMin, + opMax, + opBitAnd, + opBitOr, + opBitXor, + opLCM, + opGCD, + opRound, + opRoundUp, + opTrunc, + opAtan2, + opHypot, + opHypotx, + opPow, + opShiftLeft, + opShiftRight, + opUnsignedShift, + opFill, + opRing1, // a * (b + 1) == a * b + a + opRing2, // a * b + a + b + opRing3, // a*a*b + opRing4, // a*a*b - a*b*b + opDifSqr, // a*a - b*b + opSumSqr, // a*a + b*b + opSqrSum, // (a + b)^2 + opSqrDif, // (a - b)^2 + opAbsDif, // |a - b| + opThresh, + opAMClip, + opScaleNeg, + opClip2, + opExcess, + opFold2, + opWrap2, + opFirstArg, + opRandRange, + opExpRandRange, + + opNumBinarySelectors +}; + +/* other special math operators */ +enum { + /* 3 operands */ + opDivz, + opClip, + opWrap, + opFold, + opRampMult, + opMix, + /* 4 operands */ + opPoly3, + /* 5 operands */ + opMapRange +}; + +enum { + opmNew, // 0 + opmInit, + opmAt, + opmPut, + opmNext, + opmReset, // 5 + opmValue, + opmCopyToEnd, // used by multi assign + opmAdd, // used by dynamic list + //opmIsNil, + //opmNotNil, // 10 + opmSize, + opmClass, + opmIf, + opmWhile, + opmFor, // 15 + opmAnd, + opmOr, + opmIdentical, + opmNotIdentical, + opmPrint, // 20 + opmRemove, + opmIndexOf, + opmWrapAt, + opmClipAt, + opmFoldAt, // 25 + opmWrapPut, + opmClipPut, + opmFoldPut, + opmDo, + opmCollect, // 30 + opmSelect, + opmReject, + opmAny, + opmEvery, + opmFind, + opmChoose, + opmValueList, + opmAddFirst, + opmPrimitiveFailed, + opmSubclassResponsibility, + opmShouldNotImplement, + opmNotYetImplemented, + opmDoesNotUnderstand, + + opmAtSign, + opmWrapAtSign, + opmClipAtSign, + opmFoldAtSign, + + opmNewClear, + opmNewCopyArgs, + opmMultiNew, + opmMultiNewList, + opmAR, + opmKR, + opmIR, + + opmCopy, + opmPerformList, + opmIsKindOf, + opmPostln, + opmAsString, + + opmEnvirGet, + opmEnvirPut, + + opmHalt, + opmForBy, + opmReverseDo, + opmLoop, + + opmNonBooleanError, + + opmPlusPlus, + opmLTLT, + opmQuestionMark, + opmDoubleQuestionMark, + + opmYield, + opmName, + opmMulAdd, + + opmNumSpecialSelectors +}; + +enum { + opsvSelf, // 0 + opsvMinusOne, + opsvNegOne, + opsvZero, + opsvOne, + opsvTwo, // 5 + opsvFHalf, + opsvFNegOne, + opsvFZero, + opsvFOne, + opsvFTwo, // 10 + opsvPlusOne, + opsvTrue, + opsvFalse, + opsvNil, + opsvInf, // 15 + + opsvNumSpecialValues +}; + +enum { + opgProcess, + opgMethod, + opgFunctionDef, + opgFunction, + opgThread, + //opgSampleRate, + //opgAudioClock, + //opgLogicalClock, + + opgNumPseudoVars +}; + +/* selector types */ +enum { + selNormal, + selSpecial, + selUnary, + selBinary, + selIf, + selWhile, + selAnd, + selOr, + selLoop, + selSuperNew, + + selNumSelectorTypes +}; + + + +/* + special classes: + Object, List, Number, Int, Float, Signal, Complex, Point +*/ +enum { + op_class_object, + op_class_symbol, + op_class_nil, + op_class_boolean, + op_class_true, + op_class_false, + op_class_magnitude, + op_class_char, + op_class_number, + op_class_complex, + op_class_simple_number, + op_class_int, + op_class_float, + op_class_method, + op_class_fundef, + op_class_stream, + op_class_func, + op_class_frame, + op_class_process, + op_class_main, + op_class_class, + op_class_string, + op_class_collection, + op_class_sequenceable_collection, + op_class_arrayed_collection, + op_class_array, + op_class_int8array, + op_class_int16array, + op_class_int32array, + op_class_floatarray, + op_class_signal, + op_class_doublearray, + op_class_symbolarray, + op_class_list, + op_class_linkedlist, + op_class_bag, + op_class_set, + op_class_identityset, + op_class_dictionary, + op_class_identitydictionary, + op_class_sortedlist, + op_class_synth, + op_class_ref, + op_class_environment, + op_class_wavetable, + op_class_env, + + op_class_routine, + op_class_color, + op_class_rect, + + op_NumSpecialClasses +}; + + + +#endif diff --git a/sc4pd/headers/lang/PowerOfTwoAllocPool.h b/sc4pd/headers/lang/PowerOfTwoAllocPool.h new file mode 100755 index 0000000..8dde18f --- /dev/null +++ b/sc4pd/headers/lang/PowerOfTwoAllocPool.h @@ -0,0 +1,154 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +// Implements a power of two size class allocator. +// There is no consolidation of free space. Once a chunk is allocated it +// remains at that size from then on whether free or allocated. +// It uses AdvancingAllocPool as its parent allocator. +// It is very fast. This is used to allocate Unit output buffers. + +#ifndef _PowerOfTwoAllocPool_ +#define _PowerOfTwoAllocPool_ + +#include +#include +#include "clz.h" +#include "AdvancingAllocPool.h" +#include "SC_AllocPool.h" +void post(const char *fmt, ...); +void postbuf(const char *fmt, ...); + +template +class PowerOfTwoAllocPool +{ +public: + PowerOfTwoAllocPool(::AllocPool *inPool, + size_t initSize = 64*1024, + size_t growSize = 64*1024 + ) + { + mLargeObjPool = inPool; + mNumLargeObjects = 0; + mNumAlloc = 0; + mNumFree = 0; + size_t tooBigSize = (sizeof(Hdr) + (sizeof(Elem) << (LargeObjSizeClass-1))) + 1; + mSmallObjPool.Init(inPool, initSize, growSize, tooBigSize); + Init(); + assert(SanityCheck()); + } + ~PowerOfTwoAllocPool() + { + assert(SanityCheck()); + assert(mNumLargeObjects == 0); // you have to free the big ones yourself + mSmallObjPool.FreeAll(); + } + + Obj* Alloc(int32 inNumElems) + { + //mNumAlloc++; + assert(SanityCheck()); + int sizeclass = LOG2CEIL(inNumElems); + if (sizeclass >= LargeObjSizeClass) { + mNumLargeObjects++; + size_t size = sizeof(Hdr) + (sizeof(Elem) * inNumElems); + return (Obj*)mLargeObjPool->Alloc(size); + } + + // get from free list + Obj* obj = mFreeLists[sizeclass]; + if (obj != NULL) { + // set free list to next element. + mFreeLists[sizeclass] = *(Obj**)obj; + } else { + // have to allocate it + size_t size = mSizes[sizeclass]; + obj = (Obj*)mSmallObjPool.Alloc(size); + if (!obj) throw runtime_error("PowerOfTwoAllocPool out of memory"); + } + //obj->mMagic = 'magk'; + assert(SanityCheck()); + return obj; + } + void Free(Obj* inObjPtr) + { + //mNumFree++; + assert(SanityCheck()); + if (inObjPtr == 0) return; /* free(0) has no effect */ + /*if (inObjPtr->mMagic != 'magk') { + postbuf("bad object\n"); + throw runtime_error("bad object"); + }*/ + int sizeclass = inObjPtr->SizeClass(); + if (sizeclass >= LargeObjSizeClass) { + mLargeObjPool->Free(inObjPtr); + mNumLargeObjects--; + } else { + Obj* nextfree = mFreeLists[sizeclass]; + mFreeLists[sizeclass] = inObjPtr; + *(Obj**)inObjPtr = nextfree; + } + assert(SanityCheck()); + } + void FreeAll() + { + assert(mNumLargeObjects == 0); // you have to free the big ones yourself + mSmallObjPool.FreeAll(); + Init(); + } + + bool SanityCheck() + { + //postbuf("PowerOfTwoAllocPool::SanityCheck %d %d\n", mNumAlloc, mNumFree); + mLargeObjPool->DoCheckPool(); + mSmallObjPool.SanityCheck(); + for (int i=0; i=1000) { + post("linked loop??\n"); + throw runtime_error("linked loop??\n"); + return false; + } + obj = *(Obj**)obj; + } + } + return true; + } +private: + void Init() + { + for (int i=0; i + +template +class PriorityQueueT +{ +public: + PriorityQueueT() { + Empty(); + } + + bool Add(Event& inEvent) + { + if (mSize >= N) return false; + long mom = mSize++; + long me = mom; + for (; mom>0;) { /* percolate up heap */ + mom = mom - 1 >> 1; + if (inEvent.mTime < mEvents[mom].mTime) { + mEvents[me] = mEvents[mom]; + me = mom; + } else break; + } + mEvents[me] = inEvent; + return true; + } + void Perform(TimeType inNow) + { + while (NextTime() <= inNow) { + Event event = Remove(); + event.Perform(); + } + } + TimeType NextTime() { return mEvents[0].mTime; } + bool Ready(TimeType inTime) { return NextTime() <= inTime; } + void Flush() { Perform(std::numeric_limits::max()); } + void Empty() { mSize = 0; SetEmptyTime(); } + void SetEmptyTime() { mEvents[0].mTime = std::numeric_limits::max(); } + + Event Remove() + { + Event event = mEvents[0]; + if (--mSize == 0) SetEmptyTime(); + else { + Event temp = mEvents[mSize]; + long mom = 0; + long me = 1; + for (;me < mSize;) { /* demote heap */ + if (me+1 < mSize && mEvents[me].mTime > mEvents[me+1].mTime) { + me ++; + } + if (temp.mTime > mEvents[me].mTime) { + mEvents[mom] = mEvents[me]; + mom = me; + me = (me << 1) + 1; + } else break; + } + mEvents[mom] = temp; + } + return event; + } + +private: + long mSize; + Event mEvents[N]; +}; + +#endif \ No newline at end of file diff --git a/sc4pd/headers/lang/PyrArchiverT.h b/sc4pd/headers/lang/PyrArchiverT.h new file mode 100755 index 0000000..3beaa0c --- /dev/null +++ b/sc4pd/headers/lang/PyrArchiverT.h @@ -0,0 +1,619 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +An object archiving system for SuperCollider. + +*/ + + +#ifndef _PyrArchiver_ +#define _PyrArchiver_ + +#include "PyrObject.h" +#include "SC_AllocPool.h" + +#include "PyrKernel.h" +#include "PyrPrimitive.h" +#include "VMGlobals.h" +#include "GC.h" +#include "ReadWriteMacros.h" + +const int32 kArchHdrSize = 12; +const int32 kObjectArrayInitialCapacity = 32; + +template +class PyrArchiver +{ +public: + PyrArchiver(VMGlobals *inG, bool inSameAddressSpace = false) + : g(inG), mObjectArray(mInitialObjectArray), mNumObjects(0), + mObjectArrayCapacity( kObjectArrayInitialCapacity ), + mSameAddressSpace(inSameAddressSpace), mReadArchiveVersion(0) + { + } + + ~PyrArchiver() + { + if (mObjectArray != mInitialObjectArray) { + g->allocPool->Free(mObjectArray); + } + } + + void setStream(S s) { mStream.SetStream(s); } + + int32 calcArchiveSize() + { + PyrSlot *slot; + int32 size = kArchHdrSize; + if (mNumObjects == 0) { + size += sizeOfElem(&mTopSlot) + 1; + } else { + // object table size + for (int i=0; iclassptr->name.us->length + 1; // class name symbol + size += sizeof(int32); // size + if (obj->obj_format <= obj_slot) { + size += obj->size; // tags + slot = obj->slots; + for (int j=0; jsize; ++j, ++slot) { + size += sizeOfElem(slot); + } + } else if (obj->obj_format == obj_symbol) { + PyrSymbol **symbol = ((PyrSymbolArray*)obj)->symbols; + for (int j=0; jsize; ++j, ++symbol) { + size += (**symbol).length + 1; + } + } else { + size += obj->size * gFormatElemSize[obj->obj_format]; + } + } + } + return size; + } + + long prepareToWriteArchive(PyrSlot *objectSlot) + { + long err = errNone; + + try { + mTopSlot.ucopy = objectSlot->ucopy; + if (IsObj(objectSlot)) constructObjectArray(objectSlot->uo); + } catch (std::exception &ex) { + error(ex.what()); + err = errFailed; + } + return err; + } + + long writeArchive() + { + long err = errNone; + + try { + writeArchiveHeader(); + + if (mNumObjects == 0) { + writeSlot(&mTopSlot); + } else { + for (int i=0; ireadArchive\n"); + long err = errNone; + + + SetNil(objectSlot); + + try { + readArchiveHeader(); + //postfl("readObjectHeaders %d\n", mNumObjects); + if (mNumObjects == 0) { + readSlot(objectSlot); + } else { + for (int i=0; i kObjectArrayInitialCapacity) { + mObjectArray = (PyrObject**)g->allocPool->Alloc(mNumObjects * sizeof(PyrObject*)); + mObjectArrayCapacity = mNumObjects; + } + + } + + void recurse(PyrObject *obj, int n) + { + PyrSlot *slot = obj->slots; + for (int i=0; iuo); + } + } + + void growObjectArray() + { + int32 newObjectArrayCapacity = mObjectArrayCapacity << 1; + + int32 newSize = newObjectArrayCapacity * sizeof(PyrObject*); + PyrObject** newArray = (PyrObject**)g->allocPool->Alloc(newSize); + memcpy(newArray, mObjectArray, mNumObjects * sizeof(PyrObject*)); + if (mObjectArray != mInitialObjectArray) { + g->allocPool->Free(mObjectArray); + } + mObjectArrayCapacity = newObjectArrayCapacity; + mObjectArray = newArray; + } + + void putObject(PyrObject *obj) + { + obj->SetMark(); + obj->scratch1 = mNumObjects; + + // expand array if needed + if (mNumObjects >= mObjectArrayCapacity) growObjectArray(); + + // add to array + mObjectArray[mNumObjects++] = obj; + } + + void constructObjectArray(PyrObject *obj) + { + if (!obj->IsMarked()) { + if (isKindOf(obj, class_class)) { + } else if (isKindOf(obj, class_process)) { + } else if (isKindOf(obj, s_interpreter->u.classobj)) { + } else if (isKindOf(obj, class_method)) { + throw std::runtime_error("cannot archive Methods.\n"); + } else if (isKindOf(obj, class_thread)) { + throw std::runtime_error("cannot archive Threads.\n"); + } else if (isKindOf(obj, class_frame)) { + throw std::runtime_error("cannot archive Frames.\n"); + } else if (isKindOf(obj, class_func)) { + if (NotNil(&((PyrClosure*)obj)->block.uoblk->context)) { + throw std::runtime_error("open Function can not be archived.\n"); + } + putObject(obj); + recurse(obj, obj->size); + } else { + if (mSameAddressSpace && obj->IsPermanent()) { + // skip it + } else { + if (isKindOf(obj, class_rawarray)) { + putObject(obj); + } else if (isKindOf(obj, class_array)) { + putObject(obj); + recurse(obj, obj->size); + + } else { + putObject(obj); + recurse(obj, obj->size); + } + } + } + } + } + + int32 sizeOfElem(PyrSlot *slot) + { + //postfl("writeSlot %08X\n", slot->utag); + switch (slot->utag) { + case tagObj : + if (isKindOf(slot->uo, class_class)) { + return slot->uoc->name.us->length + 1; + } else if (isKindOf(slot->uo, class_process)) { + return 0; + } else if (isKindOf(slot->uo, s_interpreter->u.classobj)) { + return 0; + } else { + return sizeof(int32); + } + break; + case tagHFrame : + case tagSFrame : + return 0; + case tagInt : + return sizeof(int32); + case tagSym : + return slot->us->length + 1; + case tagChar : + return sizeof(int32); + case tagNil : + return 0; + case tagFalse : + return 0; + case tagTrue : + return 0; + case tagInf : + return 0; + case tagPtr : + throw std::runtime_error("cannot archive RawPointers."); + return 0; + default : + return sizeof(double); + } + } + + PyrSymbol* readSymbolID() + { + char str[256]; + mStream.readSymbol(str); + return getsym(str); + } + + + PyrObject* readObjectID() + { + int32 objID = mStream.readInt32_be(); + //postfl("readObjectID %d\n", objID); + return mObjectArray[objID]; + } + + void writeObjectHeader(PyrObject *obj) + { + obj->ClearMark(); + + //postfl("writeObjectHeader %s\n", obj->classptr->name.us->name); + mStream.writeSymbol(obj->classptr->name.us->name); + + mStream.writeInt32_be(obj->size); + } + + PyrObject* readObjectHeader() + { + PyrSymbol* classname = readSymbolID(); + //post("readObjectHeader %s\n", classname->name); + PyrObject *obj; + int32 size = mStream.readInt32_be(); + if (classname->u.classobj->classFlags.ui & classHasIndexableInstances) { + obj = instantiateObject(g->gc, classname->u.classobj, size, false, false); + obj->size = size; + } else { + obj = instantiateObject(g->gc, classname->u.classobj, 0, false, false); + } + return obj; + } + + void writeSlots(PyrObject *obj) + { + //postfl(" writeSlots %s\n", obj->classptr->name.us->name); + if (isKindOf(obj, class_rawarray)) { + writeRawArray(obj); + } else if (isKindOf(obj, class_func)) { + PyrClosure* closure = (PyrClosure*)obj; + writeSlot(&closure->block); + } else { + for (int i=0; isize; ++i) { + writeSlot(obj->slots + i); + } + } + } + + void readSlots(PyrObject *obj) + { + //postfl("readSlots\n"); + if (isKindOf(obj, class_rawarray)) { + readRawArray(obj); + } else if (isKindOf(obj, class_func)) { + PyrClosure* closure = (PyrClosure*)obj; + readSlot(&closure->block); + closure->context.ucopy = g->process->interpreter.uoi->context.ucopy; + } else { + for (int i=0; isize; ++i) { + readSlot(obj->slots + i); + } + } + } + + void writeSlot(PyrSlot *slot) + { + PyrObject *obj; + //postfl(" writeSlot %08X\n", slot->utag); + switch (slot->utag) { + case tagObj : + obj = slot->uo; + if (isKindOf(obj, class_class)) { + mStream.writeInt8('C'); + mStream.writeSymbol(slot->uoc->name.us->name); + } else if (isKindOf(obj, class_process)) { + mStream.writeInt8('P'); + } else if (isKindOf(obj, s_interpreter->u.classobj)) { + mStream.writeInt8('R'); + } else { + if (mSameAddressSpace && obj->IsPermanent()) { + mStream.writeInt8('z'); + mStream.writeInt32_be((int32)obj); + } else { + mStream.writeInt8('o'); + mStream.writeInt32_be(obj->scratch1); + } + } + break; + case tagHFrame : + case tagSFrame : + mStream.writeInt8('N'); + break; + case tagInt : + mStream.writeInt8('i'); + mStream.writeInt32_be(slot->ui); + break; + case tagSym : + mStream.writeInt8('s'); + mStream.writeSymbol(slot->us->name); + break; + case tagChar : + mStream.writeInt8('c'); + mStream.writeInt32_be(slot->ui); + break; + case tagNil : + mStream.writeInt8('N'); + break; + case tagFalse : + mStream.writeInt8('F'); + break; + case tagTrue : + mStream.writeInt8('T'); + break; + case tagInf : + mStream.writeInt8('I'); + break; + case tagPtr : + mStream.writeInt8('N'); + break; + default : + mStream.writeInt8('f'); + mStream.writeDouble_be(slot->uf); + break; + } + } + + void readSlot(PyrSlot *slot) + { + char tag = mStream.readInt8(); + switch (tag) { + case 'o' : + slot->utag = tagObj; + slot->uo = readObjectID(); + break; + case 'z' : + slot->utag = tagObj; + slot->ui = mStream.readInt32_be(); + break; + case 'C' : + slot->utag = tagObj; + slot->uo = (PyrObject*)readSymbolID()->u.classobj; + break; + case 'P' : + slot->utag = tagObj; + slot->uo = (PyrObject*)g->process; + break; + case 'R' : + slot->utag = tagObj; + slot->uo = g->process->interpreter.uo; + break; + case 'i' : + slot->utag = tagInt; + slot->ui = mStream.readInt32_be(); + break; + case 's' : + slot->utag = tagSym; + slot->us = readSymbolID(); + break; + case 'c' : + slot->utag = tagChar; + slot->ui = mStream.readInt32_be(); + break; + case 'f' : + slot->uf = mStream.readDouble_be(); + break; + case 'N' : + slot->utag = tagNil; + slot->ui = 0; + break; + case 'T' : + slot->utag = tagTrue; + slot->ui = 0; + break; + case 'F' : + slot->utag = tagFalse; + slot->ui = 0; + break; + case 'I' : + slot->utag = tagInf; + slot->ui = 0; + break; + default : + slot->utag = tagNil; + slot->ui = 0; + break; + } + } + + void writeRawArray(PyrObject *obj) + { + int32 size = obj->size; + //postfl("writeRawArray %d\n", size); + switch (obj->obj_format) { + case obj_char : + case obj_int8 : { + char *data = (char*)obj->slots; + mStream.writeData(data, size); + } break; + case obj_int16 : { + int16 *data = (int16*)obj->slots; + for (int i=0; islots; + for (int i=0; islots; + for (int i=0; islots; + for (int i=0; iname); + } + } break; + } + } + + void readRawArray(PyrObject *obj) + { + //postfl("readRawArray\n"); + int32 size = obj->size; + switch (obj->obj_format) { + case obj_char : + case obj_int8 : { + int8 *data = (int8*)obj->slots; + for (int i=0; islots; + for (int i=0; islots; + for (int i=0; islots; + for (int i=0; islots; + for (int i=0; i mStream; + int32 mReadArchiveVersion; + + PyrObject *mInitialObjectArray[kObjectArrayInitialCapacity]; +}; + +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +An object archiving system for SuperCollider. + +*/ + + + +#endif + diff --git a/sc4pd/headers/lang/PyrDeepCopier.h b/sc4pd/headers/lang/PyrDeepCopier.h new file mode 100755 index 0000000..3b46280 --- /dev/null +++ b/sc4pd/headers/lang/PyrDeepCopier.h @@ -0,0 +1,221 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +An object archiving system for SuperCollider. + +*/ + + +#ifndef _PyrDeepCopier_ +#define _PyrDeepCopier_ + +#include "PyrObject.h" +#include "SC_AllocPool.h" + +#include "PyrKernel.h" +#include "PyrPrimitive.h" +#include "VMGlobals.h" +#include "GC.h" +#include "ReadWriteMacros.h" + +const int32 kDeepCopierObjectArrayInitialCapacity = 32; + +class PyrDeepCopier +{ +public: + PyrDeepCopier(VMGlobals *inG) + : g(inG), objectArray(initialObjectArray), numObjects(0), + objectArrayCapacity( kDeepCopierObjectArrayInitialCapacity ) + { + } + + ~PyrDeepCopier() + { + if (objectArrayCapacity > kDeepCopierObjectArrayInitialCapacity) { + g->allocPool->Free(objectArray); + } + } + + long doDeepCopy(PyrSlot *objectSlot) + { + long err = errNone; + + try { + if (IsObj(objectSlot)) { + constructObjectArray(objectSlot->uo); + for (int i=0; iClearMark(); + } + + } + } catch (std::exception &ex) { + error(ex.what()); + err = errFailed; + } + return err; + } + +private: + + void recurse(PyrObject *obj, int n) + { + //post("->recurse %s %08X\n", obj->classptr->name.us->name, obj); + PyrSlot *slot = obj->slots; + for (int i=0; iuo); + } + //post("<-recurse %s %08X\n", obj->classptr->name.us->name, obj); + } + + void growObjectArray() + { + int32 newObjectArrayCapacity = objectArrayCapacity << 1; + + int32 newSize = newObjectArrayCapacity * sizeof(PyrObject*); + PyrObject** newArray = (PyrObject**)g->allocPool->Alloc(newSize); + memcpy(newArray, objectArray, numObjects * sizeof(PyrObject*)); + if (objectArrayCapacity > kDeepCopierObjectArrayInitialCapacity) { + g->allocPool->Free(objectArray); + } + objectArrayCapacity = newObjectArrayCapacity; + objectArray = newArray; + } + + void putSelf(PyrObject *obj) + { + obj->SetMark(); + obj->scratch1 = numObjects; + + // expand array if needed + if (numObjects >= objectArrayCapacity) growObjectArray(); + + //post("putSelf %d %08X\n", numObjects, obj); + // add to array + objectArray[numObjects++] = obj; + } + + void putCopy(PyrObject *obj) + { + obj->SetMark(); + obj->scratch1 = numObjects; + + // expand array if needed + if (numObjects+2 >= objectArrayCapacity) growObjectArray(); + + // add a shallow copy to object array + PyrObject *copy = copyObject(g->gc, obj, false); + copy->ClearMark(); + + //post("putCopy %d %08X\n", numObjects, copy); + + // add to array + objectArray[numObjects++] = copy; + objectArray[numObjects++] = obj; + } + + void constructObjectArray(PyrObject *obj) + { + //post("->constructObjectArray %s %08X\n", obj->classptr->name.us->name, obj); + if (!obj->IsMarked()) { + if (isKindOf(obj, class_class)) { + putSelf(obj); + } else if (isKindOf(obj, class_process)) { + putSelf(obj); + } else if (isKindOf(obj, s_interpreter->u.classobj)) { + putSelf(obj); + } else if (isKindOf(obj, class_rawarray)) { + putCopy(obj); + } else if (isKindOf(obj, class_array)) { + putCopy(obj); + recurse(obj, obj->size); + } else if (isKindOf(obj, class_func)) { + putSelf(obj); + } else if (isKindOf(obj, class_method)) { + putSelf(obj); + } else if (isKindOf(obj, class_thread)) { + putSelf(obj); + } else { + putCopy(obj); + recurse(obj, obj->size); + } + } + //post("<-constructObjectArray %s %08X\n", obj->classptr->name.us->name, obj); + } + + void fixObjSlot(PyrSlot* slot) + { + //post("fixObjSlot %s %08X %d %08X\n", slot->uo->classptr->name.us->name, slot->uo, slot->uo->scratch1, objectArray[slot->uo->scratch1]); + slot->uo = objectArray[slot->uo->scratch1]; + } + + void fixSlots(PyrObject *obj) + { + //post("fixSlots %s %08X %d\n", obj->classptr->name.us->name, obj, obj->IsMarked()); + if (!obj->IsMarked() && obj->obj_format <= obj_slot) { // it is a copy + PyrSlot *slot = obj->slots; + for (int i=0; isize; ++i, ++slot) { + if (IsObj(slot)) fixObjSlot(slot); + } + } + } + + VMGlobals *g; + + PyrObject **objectArray; + int32 numObjects; + int32 objectArrayCapacity; + + PyrObject *initialObjectArray[kDeepCopierObjectArrayInitialCapacity]; +}; + +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +An object archiving system for SuperCollider. + +*/ + + + +#endif + diff --git a/sc4pd/headers/lang/PyrDeepFreezer.h b/sc4pd/headers/lang/PyrDeepFreezer.h new file mode 100755 index 0000000..28d9a12 --- /dev/null +++ b/sc4pd/headers/lang/PyrDeepFreezer.h @@ -0,0 +1,178 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +An object archiving system for SuperCollider. + +*/ + +#ifndef _PyrDeepFreezer_ +#define _PyrDeepFreezer_ + +#include "PyrObject.h" +#include "SC_AllocPool.h" +#include "PyrKernel.h" +#include "PyrPrimitive.h" +#include "VMGlobals.h" +#include "GC.h" + +const int32 kDeepFreezerObjectArrayInitialCapacity = 32; + +class PyrDeepFreezer +{ +public: + PyrDeepFreezer(VMGlobals *inG) + : g(inG), objectArray(initialObjectArray), numObjects(0), + objectArrayCapacity( kDeepCopierObjectArrayInitialCapacity ) + { + } + + ~PyrDeepFreezer() + { + if (objectArrayCapacity > kDeepCopierObjectArrayInitialCapacity) { + g->allocPool->Free(objectArray); + } + } + + long doDeepFreeze(PyrSlot *objectSlot) + { + long err = errNone; + + try { + if (IsObj(objectSlot)) { + constructObjectArray(objectSlot->uo); + for (int i=0; igc->BecomePermanent( objectArray[i] ); + } + } + } catch (std::exception &ex) { + error(ex.what()); + err = errFailed; + } + return err; + } + +private: + + void recurse(PyrObject *obj, int n) + { + PyrSlot *slot = obj->slots; + for (int i=0; iuo); + } + } + + void growObjectArray() + { + int32 newObjectArrayCapacity = objectArrayCapacity << 1; + + int32 newSize = newObjectArrayCapacity * sizeof(PyrObject*); + PyrObject** newArray = (PyrObject**)g->allocPool->Alloc(newSize); + memcpy(newArray, objectArray, numObjects * sizeof(PyrObject*)); + if (objectArrayCapacity > kDeepCopierObjectArrayInitialCapacity) { + g->allocPool->Free(objectArray); + } + objectArrayCapacity = newObjectArrayCapacity; + objectArray = newArray; + } + + void putObject(PyrObject *obj) + { + obj->SetMark(); + obj->scratch1 = numObjects; + + // expand array if needed + if (numObjects >= objectArrayCapacity) growObjectArray(); + + // add to array + objectArray[numObjects++] = obj; + } + + void constructObjectArray(PyrObject *obj) + { + if (obj->IsPermanent()) return; + + if (!obj->IsMarked()) { + if (isKindOf(obj, class_process)) { + throw std::runtime_error("cannot freeze Process.\n"); + } else if (isKindOf(obj, s_interpreter->u.classobj)) { + throw std::runtime_error("cannot freeze Interpreter.\n"); + } else if (isKindOf(obj, class_rawarray)) { + putObject(obj); + } else if (isKindOf(obj, class_array)) { + putObject(obj); + recurse(obj, obj->size); + } else if (isKindOf(obj, class_func)) { + if (NotNil(&((PyrClosure*)obj)->block.uoblk->context)) { + throw std::runtime_error("open Function can not be frozen.\n"); + } + putObject(obj); + recurse(obj, obj->size); + } else if (isKindOf(obj, class_method)) { + throw std::runtime_error("cannot freeze Methods.\n"); + } else if (isKindOf(obj, class_thread)) { + throw std::runtime_error("cannot freeze Threads.\n"); + } else if (isKindOf(obj, class_frame)) { + throw std::runtime_error("cannot freeze Frames.\n"); + } else { + putObject(obj); + recurse(obj, obj->size); + } + } + } + + VMGlobals *g; + + PyrObject **objectArray; + int32 numObjects; + int32 objectArrayCapacity; + + PyrObject *initialObjectArray[kDeepCopierObjectArrayInitialCapacity]; +}; + +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +An object archiving system for SuperCollider. + +*/ + + + +#endif + diff --git a/sc4pd/headers/lang/PyrErrors.h b/sc4pd/headers/lang/PyrErrors.h new file mode 100755 index 0000000..b2be76e --- /dev/null +++ b/sc4pd/headers/lang/PyrErrors.h @@ -0,0 +1,49 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +virtual machine error codes. + +*/ + +#ifndef _SCErrors_ +#define _SCErrors_ + +enum { // primitive errors + errReturn = -1, // not really an error.. primitive executed a non-local return + errNone, + errFailed = 5000, + errBadPrimitive, + errWrongType, + errIndexNotAnInteger, + errIndexOutOfRange, + errImmutableObject, + errNotAnIndexableObject, + errStackOverflow, + errOutOfMemory, + errCantCallOS, + errException, + + errPropertyNotFound = 6000, + + errLastError +}; + +#endif diff --git a/sc4pd/headers/lang/PyrFilePrim.h b/sc4pd/headers/lang/PyrFilePrim.h new file mode 100755 index 0000000..3574927 --- /dev/null +++ b/sc4pd/headers/lang/PyrFilePrim.h @@ -0,0 +1,62 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +#ifndef _PYRFILEPRIM_H_ +#define _PYRFILEPRIM_H_ + +#include "PyrObject.h" + +struct PyrFile : public PyrObjectHdr +{ + PyrSlot fileptr; +}; + +void initFilePrimitives(); + +long prFileDelete(VMGlobals *g, long numArgsPushed); +long prFileOpen(VMGlobals *g, long numArgsPushed); +long prFileClose(VMGlobals *g, long numArgsPushed); +long prFileSeek(VMGlobals *g, long numArgsPushed); +long prFilePos(VMGlobals *g, long numArgsPushed); +long prFileLength(VMGlobals *g, long numArgsPushed); +long prFileWrite(VMGlobals *g, long numArgsPushed); +long prFileReadLine(VMGlobals *g, long numArgsPushed); + +long prFilePutRGB(VMGlobals *g, long numArgsPushed); +long prFilePutInt32(VMGlobals *g, long numArgsPushed); +long prFilePutInt16(VMGlobals *g, long numArgsPushed); +long prFilePutInt8(VMGlobals *g, long numArgsPushed); +long prFilePutChar(VMGlobals *g, long numArgsPushed); +long prFilePutFloat(VMGlobals *g, long numArgsPushed); +long prFilePutDouble(VMGlobals *g, long numArgsPushed); + +long prFileGetRGB(VMGlobals *g, long numArgsPushed); +long prFileGetInt32(VMGlobals *g, long numArgsPushed); +long prFileGetInt16(VMGlobals *g, long numArgsPushed); +long prFileGetInt8(VMGlobals *g, long numArgsPushed); +long prFileGetChar(VMGlobals *g, long numArgsPushed); +long prFileGetFloat(VMGlobals *g, long numArgsPushed); +long prFileGetDouble(VMGlobals *g, long numArgsPushed); + +long prFilePutString(VMGlobals *g, long numArgsPushed); +long prFileRead(VMGlobals *g, long numArgsPushed); + + +#endif + diff --git a/sc4pd/headers/lang/PyrFileUtils.h b/sc4pd/headers/lang/PyrFileUtils.h new file mode 100755 index 0000000..1fd682b --- /dev/null +++ b/sc4pd/headers/lang/PyrFileUtils.h @@ -0,0 +1,50 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +Some utils for file i/o. + +*/ + +#ifndef _PYRFILEUTIL_H_ +#define _PYRFILEUTIL_H_ + +int headerFormatFromSymbol(struct PyrSymbol *inSymbol); +int sampleFormatFromSymbol(struct PyrSymbol *inSymbol, int inHeaderFormat); + +#ifdef __MAC__ + +#include + +long setTypeCreator(unsigned char *filename, long type, long creator); +bool filelen(FILE *file, size_t *length); + +int allocasync(int fildes, int count, IOParam *pb, IOCompletionUPP completionFunc); +int createasync(unsigned char *path, int oflag, HParamBlockRec *hpb, IOCompletionUPP completionFunc); +int openasync(unsigned char *path, int oflag, HParamBlockRec *hpb, IOCompletionUPP completionFunc); +int closeasync(int fildes, HParamBlockRec *hpb, IOCompletionUPP completionFunc); +int writeasync(int fildes, const char *buf, int count, IOParam *pb, IOCompletionUPP completionFunc); +int readasync(int fildes, char *buf, int count, IOParam *pb, IOCompletionUPP completionFunc); +int seekwriteasync(int fildes, const char *buf, int count, int pos, IOParam *pb, IOCompletionUPP completionFunc); +int seekreadasync(int fildes, char *buf, int count, int pos, IOParam *pb, IOCompletionUPP completionFunc); + + +#endif +#endif diff --git a/sc4pd/headers/lang/PyrInterpreter.h b/sc4pd/headers/lang/PyrInterpreter.h new file mode 100755 index 0000000..a21126d --- /dev/null +++ b/sc4pd/headers/lang/PyrInterpreter.h @@ -0,0 +1,47 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _PYRINTERPRETER_H_ +#define _PYRINTERPRETER_H_ + +#include "PyrSlot.h" +#include "VMGlobals.h" + +extern bool gRunningInterpreterThread; + +extern int gNumClasses; + +bool initInterpreter(VMGlobals *g, PyrSymbol *selector, int numArgsPushed); +bool initRuntime(VMGlobals *g, int poolSize, AllocPool *inPool, int processID); +void Interpret(VMGlobals *g); +void endInterpreter(VMGlobals *g); + +int doSpecialUnaryArithMsg(VMGlobals *g, int numArgsPushed); +int prSpecialBinaryArithMsg(VMGlobals *g, int numArgsPushed); +int doSpecialBinaryArithMsg(VMGlobals *g, int numArgsPushed, bool isPrimitive); +void DumpBackTrace(VMGlobals *g); +void DumpStack(VMGlobals *g, PyrSlot *sp); +void DumpFrame(struct PyrFrame *frame); +bool FrameSanity(PyrFrame *frame, char *tagstr); +struct PyrProcess* newPyrProcess(VMGlobals *g, struct PyrClass *classobj); +void startProcess(VMGlobals *g, PyrSymbol *selector); +void runInterpreter(VMGlobals *g, PyrSymbol *selector, int numArgsPushed); + +#endif diff --git a/sc4pd/headers/lang/PyrKernel.h b/sc4pd/headers/lang/PyrKernel.h new file mode 100755 index 0000000..d5c6af7 --- /dev/null +++ b/sc4pd/headers/lang/PyrKernel.h @@ -0,0 +1,256 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +This file contains the definitions of the core objects that implement the class system. + +*/ + +#ifndef _PYRKERNEL_H_ +#define _PYRKERNEL_H_ + +#include "PyrObject.h" +#include "VMGlobals.h" + +#define classClassNumInstVars 16 + +enum { classIsIntrinsic = 1, classHasIndexableInstances = 2, classCompileUGen = 4 }; + +struct PyrClass : public PyrObjectHdr +{ + PyrSlot name; + PyrSlot nextclass; + PyrSlot superclass; + PyrSlot subclasses; + PyrSlot methods; + + PyrSlot instVarNames; + PyrSlot classVarNames; + PyrSlot iprototype; // instance prototype + PyrSlot cprototype; // class var prototype + + PyrSlot instanceFormat; + PyrSlot instanceFlags; + PyrSlot classIndex; + PyrSlot classFlags; + PyrSlot maxSubclassIndex; // used by isKindOf + PyrSlot filenameSym; + PyrSlot charPos; +}; + + + +inline bool isKindOf(PyrObjectHdr *obj, struct PyrClass *testclass) +{ + int objClassIndex = obj->classptr->classIndex.ui; + return objClassIndex >= testclass->classIndex.ui && objClassIndex <= testclass->maxSubclassIndex.ui; +} + +inline bool isKindOfSlot(PyrSlot *slot, struct PyrClass *testclass) +{ + return IsObj(slot) && isKindOf(slot->uo, testclass); +} + +/* + operations on class: + numInstVars() + numClassVars() + +*/ + +struct PyrFrame { + PyrSlot vars[1]; + PyrSlot myself; + PyrSlot method; + PyrSlot caller; + PyrSlot context; + PyrSlot homeContext; + PyrSlot ip; +}; + +#define FRAMESIZE 6 +#define USESTACKFRAMES 1 + +struct PyrProcess : public PyrObjectHdr +{ + + PyrSlot classVars; + PyrSlot interpreter; + PyrSlot curThread, mainThread; + PyrSlot processID; + PyrSlot sysSchedulerQueue; +}; + + +enum { tInit, tStart, tReady, tRunning, tSleeping, tBlocked, tYieldToChild, tYieldToParent, tDone }; + +struct PyrThread : public PyrObjectHdr +{ + + PyrSlot state, func, stack, stackSize, method, block, frame, ip, sp; + PyrSlot numpop, returnLevels, receiver, numArgsPushed; + PyrSlot parent, terminalValue; + PyrSlot primitiveError; + PyrSlot primitiveIndex; + PyrSlot randData; + PyrSlot beats, seconds, clock; + PyrSlot environment; + PyrSlot exceptionHandler; +}; + +#define EVALSTACKDEPTH 8192 + + + +struct PyrMethodRaw { + + unsigned short unused1; + unsigned short specialIndex; + unsigned short methType; + unsigned short frameSize; + + unsigned char unused2; + unsigned char numargs; + unsigned char varargs; + unsigned char numvars; + unsigned char numtemps; + unsigned char needsHeapContext; + unsigned char popSize; + unsigned char posargs; + +}; + + +#define METHRAW(obj) ((PyrMethodRaw*)&(((PyrBlock*)obj)->rawData1)) + +struct PyrBlock : public PyrObjectHdr +{ + + PyrSlot rawData1; + PyrSlot rawData2; + PyrSlot code; // byte codes, nil if inlined + PyrSlot selectors; // method selectors, class names, closures table + PyrSlot constants; // floating point constants table (to alleviate the literal table problem) + PyrSlot prototypeFrame; // prototype of an activation frame + PyrSlot context; // ***defining block context + PyrSlot argNames; // ***arguments to block + PyrSlot varNames; // ***variables in block + PyrSlot sourceCode; // source code if it is a closed function. +}; + +struct PyrMethod : public PyrBlock +{ + PyrSlot ownerclass; + PyrSlot name; + PyrSlot primitiveName; + PyrSlot filenameSym; + PyrSlot charPos; + //PyrSlot byteMeter; + //PyrSlot callMeter; +}; + +enum { + methNormal = 0, + methReturnSelf, + methReturnLiteral, + methReturnArg, + methReturnInstVar, + methAssignInstVar, + methReturnClassVar, + methAssignClassVar, + methRedirect, + methForward, + methPrimitive, + methBlock +}; + +struct PyrClosure : public PyrObjectHdr +{ + + PyrSlot block; + PyrSlot context; +}; + +struct PyrInterpreter : public PyrObjectHdr +{ + + PyrSlot cmdLine, context; + PyrSlot a, b, c, d, e, f, g, h, i, j; + PyrSlot k, l, m, n, o, p, q, r, s, t; + PyrSlot u, v, w, x, y, z; + PyrSlot codeDump; +}; + +/* special values */ +enum { + svNil, + svFalse, + svTrue, + svNegOne, + svZero, + svOne, + svTwo, + svFHalf, + svFNegOne, + svFZero, + svFOne, + svFTwo, + svInf, + + svNumSpecialValues +}; + +extern double gSpecialValues[svNumSpecialValues]; + +extern PyrMethod *gNullMethod; // used to fill row table + +PyrObject* instantiateObject(class PyrGC *gc, PyrClass* classobj, int size, + bool fill, bool collect); + +PyrObject* newPyrObject(class PyrGC *gc, size_t inNumBytes, int inFlags, int inFormat, bool inCollect); +PyrString* newPyrString(class PyrGC *gc, const char *s, int flags, bool collect); +PyrString* newPyrStringN(class PyrGC *gc, int size, int flags, bool collect); +PyrObject* newPyrArray(class PyrGC *gc, int size, int flags, bool collect); +PyrSymbolArray* newPyrSymbolArray(class PyrGC *gc, int size, int flags, bool collect); +PyrInt8Array* newPyrInt8Array(class PyrGC *gc, int size, int flags, bool collect); +PyrInt32Array* newPyrInt32Array(class PyrGC *gc, int size, int flags, bool collect); +PyrDoubleArray* newPyrDoubleArray(class PyrGC *gc, int size, int flags, bool collect); + +PyrObject* copyObject(class PyrGC *gc, PyrObject *inobj, bool collect); +PyrObject* copyObjectRange(class PyrGC *gc, PyrObject *inobj, int start, int end, bool collect); + +inline void SetFrame(PyrSlot* slot, PyrFrame* frame) +{ + (slot)->ui = ((int)(frame)); + (slot)->utag = tagSFrame - METHRAW((frame)->method.uoblk)->needsHeapContext; +} + +inline void SetFrameOrNil(PyrSlot* slot, PyrFrame* frame) +{ + if (frame) { + (slot)->ui = ((int)(frame)); + (slot)->utag = tagSFrame - METHRAW((frame)->method.uoblk)->needsHeapContext; + } else { + (slot)->utag = tagNil; + (slot)->ui = 0; + } +} + +#endif diff --git a/sc4pd/headers/lang/PyrKernelProto.h b/sc4pd/headers/lang/PyrKernelProto.h new file mode 100755 index 0000000..f040507 --- /dev/null +++ b/sc4pd/headers/lang/PyrKernelProto.h @@ -0,0 +1,62 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _PYRKERNELPROTO_H_ +#define _PYRKERNELPROTO_H_ + +PyrClass* newClassObj(PyrClass *classObjSuperClass, + PyrSymbol* className, PyrSymbol* superClassName, + int numInstVars, int numClassVars, int numInstMethods, + int instFormat, int instFlags); + +void reallocClassObj(PyrClass* classobj, + int numInstVars, int numClassVars, int numMethods, + int instFormat, int instFlags); + +int numInstVars(PyrClass* classobj); +int numClassVars(PyrClass* classobj); +int numSuperInstVars(PyrClass *superclassobj); +bool classFindInstVar(PyrClass* classobj, PyrSymbol *name, int *index); +bool classFindClassVar(PyrClass** classobj, PyrSymbol *name, int *index); + +void buildClassTree(); +void indexClassTree(PyrClass *classobj, int numSuperMethods); +void postClassTree(PyrClass *classobj, int level); +void setSelectorFlags(); +void buildBigMethodMatrix(); +void fillClassRow(PyrClass *classobj, struct PyrMethod** bigTable); + +bool funcFindArg(PyrBlock* func, PyrSymbol *name, int *index); +bool funcFindVar(PyrBlock* func, PyrSymbol *name, int *index); +void addMethod(PyrClass *classobj, PyrMethod *method); + + +PyrMethod* classFindDirectMethod(PyrClass* classobj, PyrSymbol *name); + +PyrBlock* newPyrBlock(int flags); +PyrMethod* newPyrMethod(); +PyrClass* makeIntrinsicClass(PyrSymbol *className, PyrSymbol *superClassName, + int numInstVars, int numClassVars); +void addIntrinsicVar(PyrClass *classobj, char *varName, PyrSlot *slot); + + + +#endif \ No newline at end of file diff --git a/sc4pd/headers/lang/PyrLexer.h b/sc4pd/headers/lang/PyrLexer.h new file mode 100755 index 0000000..5166337 --- /dev/null +++ b/sc4pd/headers/lang/PyrLexer.h @@ -0,0 +1,136 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _PYRLEXER_H_ +#define _PYRLEXER_H_ + +#include "PyrSymbol.h" + +extern int charno, lineno, linepos; +extern int *linestarts; + +struct ClassExtFile { + struct ClassExtFile *next; + PyrSymbol *fileSym; +}; + +typedef struct classdep { + struct classdep *next; + struct classdep *superClassDep; + struct classdep *subclasses; + PyrSymbol *className; + PyrSymbol *superClassName; + PyrSymbol *fileSym; +} ClassDependancy; + +extern PyrSymbol *gCompilingFileSym; + +ClassDependancy* newClassDependancy(PyrSymbol *className, PyrSymbol *superClassName, + PyrSymbol *fileSym); +bool parseOneClass(PyrSymbol *fileSym); +void initPassOne(); +void finiPassOne(); +bool passOne(); +void buildDepTree(); +void traverseFullDepTree(); +void traverseDepTree(ClassDependancy *classdep, int level); +void traverseFullDepTree2(); +void traverseDepTree2(ClassDependancy *classdep, int level); +void compileClassExtensions(); +void compileFileSym(PyrSymbol *fileSym); + +void runLibrary(PyrSymbol* selector); + +void interpretCmdLine(const char *textbuf, int textlen, char *methodname); + + +int input(); +int input0(); +void unput(int c); +void unput0(int c); + +void finiLexer() ; +bool startLexer(char* filename) ; +void startLexerCmdLine(char *textbuf, int textbuflen); +int yylex() ; +void yyerror(char *s) ; +void fatal() ; +bool isValidSourceFileName(char *filename); +bool passOne_ProcessOneFile(char *filename, int level); + +extern void asRelativePath(char *inPath,char *outPath); + +void initLexer(); +void init_SuperCollider(); + +int processbinop(char *token); +int processident(char *token); +int processfloat(char *token, int sawpi); +int processint(char *token); +int processchar(int c); +int processintradix(char *s); +int processfloatradix(char *s); +int processhex(char *s); +int processsymbol(char *token); +int processstring(char *token); +int processkeywordbinop(char *token); + +void postErrorLine(int linenum, int start, int charpos); +bool scanForClosingBracket(); +void parseClasses(); + +extern int parseFailed; +extern bool compilingCmdLine; +extern bool compilingCmdLineErrorWindow; +extern bool compiledOK; + +#define MAXYYLEN 8192 + +extern int gNumCompiledFiles; +extern int gClassCompileOrderNum; +extern ClassDependancy **gClassCompileOrder; +extern char curfilename[PATH_MAX]; + +extern int runcount; + +extern char *binopchars; +extern char yytext[MAXYYLEN]; +extern char linebuf[256]; +extern char curfilename[PATH_MAX]; + +extern int yylen; +extern int lexCmdLine; +extern bool compilingCmdLine; +extern bool compilingCmdLineErrorWindow; +extern long zzval; + +extern int lineno, charno, linepos; +extern int *linestarts; +extern int maxlinestarts; + +extern char *text; +extern int textlen; +extern int textpos; +extern int parseFailed; +extern bool compiledOK; +extern int radixcharpos, decptpos; + +#endif diff --git a/sc4pd/headers/lang/PyrListPrim.h b/sc4pd/headers/lang/PyrListPrim.h new file mode 100755 index 0000000..43288a7 --- /dev/null +++ b/sc4pd/headers/lang/PyrListPrim.h @@ -0,0 +1,34 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _PYRARRAYPRIM_H_ +#define _PYRARRAYPRIM_H_ + +void initArrayPrimitives(); + +int prArrayMultiChanExpand(VMGlobals *g, int numArgsPushed); + +int arrayAtIdentityHash(PyrObject *array, PyrSlot *key); +int arrayAtIdentityHashInPairs(PyrObject *array, PyrSlot *key); +int arrayAtIdentityHashInPairsWithHash(PyrObject *array, PyrSlot *key, int hash); + + +#endif \ No newline at end of file diff --git a/sc4pd/headers/lang/PyrMathPrim.h b/sc4pd/headers/lang/PyrMathPrim.h new file mode 100755 index 0000000..f4e2dd1 --- /dev/null +++ b/sc4pd/headers/lang/PyrMathPrim.h @@ -0,0 +1,51 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _PYRMATHPRIM_H_ +#define _PYRMATHPRIM_H_ + +void initMathPrimitives(); + +int prAddNum(VMGlobals *g, int numArgsPushed); +int prSubNum(VMGlobals *g, int numArgsPushed); +int prMulNum(VMGlobals *g, int numArgsPushed); + +int prAddInt(VMGlobals *g, int numArgsPushed); +int prSubInt(VMGlobals *g, int numArgsPushed); +int prMulInt(VMGlobals *g, int numArgsPushed); + +int prAddFloat(VMGlobals *g, int numArgsPushed); +int prSubFloat(VMGlobals *g, int numArgsPushed); +int prMulFloat(VMGlobals *g, int numArgsPushed); + +int mathClip(VMGlobals *g, int numArgsPushed); +int mathWrap(VMGlobals *g, int numArgsPushed); +int mathFold(VMGlobals *g, int numArgsPushed); +int mathClipInt(VMGlobals *g, int numArgsPushed); +int mathWrapInt(VMGlobals *g, int numArgsPushed); +int mathFoldInt(VMGlobals *g, int numArgsPushed); +int mathClipFloat(VMGlobals *g, int numArgsPushed); +int mathWrapFloat(VMGlobals *g, int numArgsPushed); +int mathFoldFloat(VMGlobals *g, int numArgsPushed); +int mathClipSignal(VMGlobals *g, int numArgsPushed); +int mathWrapSignal(VMGlobals *g, int numArgsPushed); +int mathFoldSignal(VMGlobals *g, int numArgsPushed); + +#endif diff --git a/sc4pd/headers/lang/PyrMessage.h b/sc4pd/headers/lang/PyrMessage.h new file mode 100755 index 0000000..436128a --- /dev/null +++ b/sc4pd/headers/lang/PyrMessage.h @@ -0,0 +1,55 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _PYRMESSAGE_H_ +#define _PYRMESSAGE_H_ + +#include "PyrKernel.h" + +#define MAXKEYSLOTS 128 +extern PyrSlot keywordstack[MAXKEYSLOTS]; +extern bool gKeywordError; +extern PyrMethod **gRowTable; + +void initUniqueMethods(); + +void sendMessageWithKeys(VMGlobals *g, PyrSymbol *selector, + long numArgsPushed, long numKeyArgsPushed); +void sendMessage(VMGlobals *g, PyrSymbol *selector, long numArgsPushed); +void sendSuperMessageWithKeys(VMGlobals *g, PyrSymbol *selector, + long numArgsPushed, long numKeyArgsPushed); +void sendSuperMessage(VMGlobals *g, PyrSymbol *selector, long numArgsPushed); +void doesNotUnderstandWithKeys(VMGlobals *g, PyrSymbol *selector, + long numArgsPushed, long numKeyArgsPushed); +void doesNotUnderstand(VMGlobals *g, PyrSymbol *selector, + long numArgsPushed); +void returnFromBlock(VMGlobals *g); +void returnFromMethod(VMGlobals *g); +void executeMethod(VMGlobals *g, PyrMethod *meth, long numArgsPushed); +void executeMethodWithKeys(VMGlobals *g, PyrMethod *meth, long allArgsPushed, + long numKeyArgsPushed); +void keywordFixStack(VMGlobals *g, PyrMethod *meth, PyrMethodRaw *methraw, long allArgsPushed, + long numKeyArgsPushed); + +#endif + + + diff --git a/sc4pd/headers/lang/PyrObject.h b/sc4pd/headers/lang/PyrObject.h new file mode 100755 index 0000000..05abf21 --- /dev/null +++ b/sc4pd/headers/lang/PyrObject.h @@ -0,0 +1,288 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +PyrObject represents the structure of all SC Objects. + +*/ + +#ifndef _PYROBJECT_H_ +#define _PYROBJECT_H_ + +#include "PyrSlot.h" + +/* special gc colors */ +enum { + obj_permanent = 1, // sent to gc->New as a flag + obj_gcmarker = 2 // gc treadmill marker +}; + +/* obj flag fields */ +enum { + obj_immutable = 16, + obj_marked = 128 +}; + +/* format types : */ +enum { + obj_notindexed, + obj_slot, + obj_double, + obj_float, + obj_int32, + obj_int16, + obj_int8, + obj_char, + obj_symbol, + + NUMOBJFORMATS +}; + + +/* + PyrObjectHdr : object header fields + prev, next : pointers in the GC treadmill + classptr : pointer to the object's class + size : number of slots or indexable elements. + + obj_format : what kind of data this object holds + obj_sizeclass : power of two size class of the object + obj_flags : + immutable : set if object may not be updated. + finalize : set if object requires finalization. + marked : used by garbage collector debug sanity check. may be used by primitives but must be cleared before exiting primitive. + gc_color : GC color : black, grey, white, free, permanent + scratch1 : undefined value. may be used within primitives as a temporary scratch value. +*/ + +struct PyrObjectHdr { + struct PyrObjectHdr *prev, *next; + struct PyrClass *classptr; + int size; + + unsigned char obj_format; + unsigned char obj_sizeclass; + unsigned char obj_flags; + unsigned char gc_color; + + int scratch1; + + int SizeClass() { return obj_sizeclass; } + + void SetMark() { obj_flags |= obj_marked; } + void ClearMark() { obj_flags &= ~obj_marked; } + bool IsMarked() { return obj_flags & obj_marked; } + bool IsPermanent() { return gc_color == obj_permanent; } +}; + +struct PyrObject : public PyrObjectHdr { + PyrSlot slots[1]; +}; + +struct PyrList : public PyrObjectHdr +{ + PyrSlot array; +}; + +struct PyrDoubleArray : public PyrObjectHdr +{ + double d[1]; +}; + +struct PyrFloatArray : public PyrObjectHdr +{ + float f[1]; +}; + +struct PyrInt32Array : public PyrObjectHdr +{ + uint32 i[1]; +}; + +struct PyrInt16Array : public PyrObjectHdr +{ + uint16 i[1]; +}; + +struct PyrInt8Array : public PyrObjectHdr +{ + uint8 b[1]; +}; + +struct PyrRGBArray : public PyrObjectHdr +{ + RGBColor8 r[1]; +}; + +struct PyrString : public PyrObjectHdr +{ + char s[1]; +}; + +struct PyrSymbolArray : public PyrObjectHdr +{ + PyrSymbol* symbols[1]; +}; + +extern struct PyrClass *class_object; +extern struct PyrClass *class_array; +extern struct PyrClass *class_list, *class_method, *class_fundef, *class_frame, *class_class; +extern struct PyrClass *class_symbol, *class_nil; +extern struct PyrClass *class_boolean, *class_true, *class_false; +extern struct PyrClass *class_int, *class_char, *class_float, *class_complex; +extern struct PyrClass *class_rawptr; +extern struct PyrClass *class_string; +extern struct PyrClass *class_magnitude, *class_number, *class_collection; +extern struct PyrClass *class_sequenceable_collection; +extern struct PyrClass *class_arrayed_collection; +extern struct PyrClass *class_simple_number; +extern struct PyrClass *class_signal; +extern struct PyrClass *class_wavetable; +extern struct PyrClass *class_rawarray; +extern struct PyrClass *class_int8array; +extern struct PyrClass *class_int16array; +extern struct PyrClass *class_int32array; +extern struct PyrClass *class_symbolarray; +extern struct PyrClass *class_floatarray; +extern struct PyrClass *class_doublearray; +extern struct PyrClass *class_func, *class_absfunc; +extern struct PyrClass *class_stream; +extern struct PyrClass *class_process; +extern struct PyrClass *class_thread; +extern struct PyrClass *class_routine; +extern struct PyrClass *class_inf; +extern struct PyrClass *class_finalizer; + +extern PyrSymbol *s_none; +extern PyrSymbol *s_object; +extern PyrSymbol *s_bag; +extern PyrSymbol *s_set; +extern PyrSymbol *s_identityset; +extern PyrSymbol *s_dictionary; +extern PyrSymbol *s_identitydictionary; +extern PyrSymbol *s_linkedlist; +extern PyrSymbol *s_sortedlist; +extern PyrSymbol *s_array; +extern PyrSymbol *s_list, *s_method, *s_fundef, *s_frame, *s_class; +extern PyrSymbol *s_symbol, *s_nil, *s_inf; +extern PyrSymbol *s_boolean, *s_true, *s_false; +extern PyrSymbol *s_int, *s_char, *s_color, *s_float, *s_complex; +extern PyrSymbol *s_rawptr, *s_objptr; +extern PyrSymbol *s_string; +extern PyrSymbol *s_magnitude, *s_number, *s_collection; +extern PyrSymbol *s_ordered_collection; +extern PyrSymbol *s_sequenceable_collection; +extern PyrSymbol *s_arrayed_collection; +extern PyrSymbol *s_simple_number; +extern PyrSymbol *s_signal; +extern PyrSymbol *s_wavetable; +extern PyrSymbol *s_int8array; +extern PyrSymbol *s_int16array; +extern PyrSymbol *s_int32array; +extern PyrSymbol *s_symbolarray; +extern PyrSymbol *s_floatarray; +extern PyrSymbol *s_doublearray; +extern PyrSymbol *s_point; +extern PyrSymbol *s_rect; +extern PyrSymbol *s_stream; +extern PyrSymbol *s_process; +extern PyrSymbol *s_main; +extern PyrSymbol *s_thread; +extern PyrSymbol *s_routine; +extern PyrSymbol *s_linear, *s_exponential, *s_gate; +extern PyrSymbol *s_env; + +extern PyrSymbol *s_audio, *s_control, *s_scalar; +extern PyrSymbol *s_run; +extern PyrSymbol *s_next; +extern PyrSymbol *s_at; +extern PyrSymbol *s_put; +extern PyrSymbol *s_series, *s_copyseries, *s_putseries; +extern PyrSymbol *s_value; +extern PyrSymbol *s_performList; +extern PyrSymbol *s_superPerformList; +extern PyrSymbol *s_ugen, *s_outputproxy; +extern PyrSymbol *s_new, *s_ref; +extern PyrSymbol *s_synth, *s_spawn, *s_environment, *s_event; +extern PyrSymbol *s_interpreter; +extern PyrSymbol *s_finalizer; +extern PyrSymbol *s_awake; +extern PyrSymbol *s_appclock; +extern PyrSymbol *s_systemclock; + + +extern int gFormatElemSize[NUMOBJFORMATS]; +extern int gFormatElemCapc[NUMOBJFORMATS]; +extern int gFormatElemTag[NUMOBJFORMATS]; + +void dumpObject(PyrObject *obj); +void dumpObjectSlot(PyrSlot *slot); + +bool respondsTo(PyrSlot *slot, PyrSymbol *selector); +bool isSubclassOf(struct PyrClass *classobj, struct PyrClass *testclass); + +const int kFloatTagIndex = 12; +extern struct PyrClass* gTagClassTable[16]; + +inline struct PyrClass* classOfSlot(PyrSlot *slot) +{ + PyrClass *classobj; + int tag; + if (IsFloat(slot)) classobj = gTagClassTable[kFloatTagIndex]; + else if ((tag = slot->utag & 0xF) == 1) classobj = slot->uo->classptr; + else classobj = gTagClassTable[tag]; + + return classobj; +} + +typedef int (*ObjFuncPtr)(struct VMGlobals*, struct PyrObject*); + +void stringFromPyrString(PyrString *obj, char *str, int maxlength); +void pstringFromPyrString(PyrString *obj, unsigned char *str, int maxlength); + +int instVarOffset(char *classname, char *instvarname); +int classVarOffset(char *classname, char *classvarname, PyrClass** classobj); + +void fillSlots(PyrSlot* slot, int size, PyrSlot* fillslot); +void nilSlots(PyrSlot* slot, int size); +void zeroSlots(PyrSlot* slot, int size); + +int calcHash(PyrSlot *a); +int getIndexedFloat(struct PyrObject *obj, int index, float *value); +int getIndexedDouble(struct PyrObject *obj, int index, double *value); +void getIndexedSlot(struct PyrObject *obj, PyrSlot *a, int index); +int putIndexedSlot(struct VMGlobals *g, struct PyrObject *obj, PyrSlot *c, int index); +int putIndexedFloat(PyrObject *obj, double val, int index); + +inline int ARRAYMAXINDEXSIZE(PyrObjectHdr* obj) +{ + return (1L << obj->obj_sizeclass); +} + +inline int MAXINDEXSIZE(PyrObjectHdr* obj) +{ + return ((1L << obj->obj_sizeclass) * gFormatElemCapc[ obj->obj_format ]); +} + +void InstallFinalizer(VMGlobals* g, PyrObject *inObj, int slotIndex, ObjFuncPtr inFunc); + +///// + +#endif diff --git a/sc4pd/headers/lang/PyrObjectProto.h b/sc4pd/headers/lang/PyrObjectProto.h new file mode 100755 index 0000000..b66ecc2 --- /dev/null +++ b/sc4pd/headers/lang/PyrObjectProto.h @@ -0,0 +1,44 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _PYROBJPROTO_H_ +#define _PYROBJPROTO_H_ + +#include "PyrObject.h" + +void initSymbols(); +void initClasses(); +void buildClassTree(); + +void freePyrSlot(PyrSlot *slot); +void freePyrObject(PyrObject* obj); + +bool objAddIndexedSlot(PyrObject *obj, PyrSlot *slot); +bool objAddIndexedSymbol(PyrSymbolArray *obj, PyrSymbol *symbol); +bool objAddIndexedObject(PyrObject *obj, PyrObject *obj2); + +void CallStackSanity(struct VMGlobals *g, char* tagstr); +bool FrameSanity(struct PyrFrame *frame, char* tagstr); + +void dumpBadObject(PyrObject *obj); +void initRawRegistry(); + +#endif + diff --git a/sc4pd/headers/lang/PyrParseNode.h b/sc4pd/headers/lang/PyrParseNode.h new file mode 100755 index 0000000..cd6688c --- /dev/null +++ b/sc4pd/headers/lang/PyrParseNode.h @@ -0,0 +1,456 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _PYRPARSENODE_H_ +#define _PYRPARSENODE_H_ + +#include "PyrSlot.h" +#include "PyrKernel.h" +#include "ByteCodeArray.h" +#include "Opcodes.h" +#include "AdvancingAllocPool.h" + +extern AdvancingAllocPool gParseNodePool; + +#define ALLOCNODE(type) (type*)gParseNodePool.Alloc(sizeof(type)) +//#define FREENODE(node) if (node) (*parseNodeClasses[(node)->classno]->deleteFunc)(node); +#define DUMPNODE(node, level) if (node) (*parseNodeClasses[(node)->classno]->dumpFunc)((node),(level)); +#define COMPILENODE(node, result) (*parseNodeClasses[(node)->classno]->compileFunc)((node),(result)); + +typedef void (*PyrCompileNodeFunc)(void*, void*); +typedef void (*PyrDumpNodeFunc)(void*,int); + +typedef struct pyrparsenodeclass { + int type; + PyrCompileNodeFunc compileFunc; + PyrDumpNodeFunc dumpFunc; +} PyrParseNodeClass; + + +struct PyrParseNode { + struct PyrParseNode *next; + struct PyrParseNode *tail; + short lineno; + unsigned char charno, classno; +}; + + +struct PyrSlotNode : public PyrParseNode { + PyrSlot slot; +}; + +extern PyrParseNodeClass *pyrSlotNodeClass; + +struct PyrPushNameNode : public PyrParseNode { + PyrSlot varName; +} ; + +extern PyrParseNodeClass *pyrPushNameNodeClass; + +struct PyrClassExtNode : public PyrParseNode { + struct PyrSlotNode* className; + struct PyrMethodNode *methods; +} ; + +extern PyrParseNodeClass *pyrClassExtNodeClass; + +struct PyrClassNode : public PyrParseNode { + struct PyrSlotNode* className; + struct PyrSlotNode* superClassName; + struct PyrSlotNode* indexType; + struct PyrVarListNode *varlists; + struct PyrMethodNode *methods; + int varTally[3]; + int numsuperinstvars; +} ; + +extern PyrParseNodeClass *pyrClassNodeClass; + +struct PyrMethodNode : public PyrParseNode { + struct PyrSlotNode* methodName; + struct PyrSlotNode* primitiveName; + struct PyrArgListNode *arglist; + struct PyrVarListNode *varlist; + struct PyrParseNode *body; + int isClassMethod; // is class method? + bool extension; +} ; + +extern PyrParseNodeClass *pyrMethodNodeClass; + +struct PyrVarListNode : public PyrParseNode { + struct PyrVarDefNode *varDefs; + int flags; +} ; + +extern PyrParseNodeClass *pyrVarListNodeClass; + +struct PyrVarDefNode : public PyrParseNode { + struct PyrSlotNode* varName; + struct PyrLiteralNode* defVal; + int flags; +} ; + +extern PyrParseNodeClass *pyrVarDefNodeClass; + +struct PyrCallNode : public PyrParseNode { + struct PyrSlotNode* selector; + struct PyrParseNode *arglist; + struct PyrParseNode *keyarglist; +} ; + +extern PyrParseNodeClass *pyrCallNodeClass; + +struct PyrBinopCallNode : public PyrParseNode { + struct PyrSlotNode* selector; + struct PyrParseNode *arg1; + struct PyrParseNode *arg2; + struct PyrParseNode *arg3; +} ; + +extern PyrParseNodeClass *pyrBinopCallNodeClass; + +struct PyrDropNode : public PyrParseNode { + struct PyrParseNode *expr1; + struct PyrParseNode *expr2; +} ; + +extern PyrParseNodeClass *pyrDropNodeClass; + +struct PyrPushLitNode : public PyrParseNode { + PyrSlot literalSlot; +} ; + +extern PyrParseNodeClass *pyrPushLitNodeClass; + +struct PyrPushKeyArgNode : public PyrParseNode { + struct PyrSlotNode* selector; + struct PyrParseNode *expr; +} ; + +extern PyrParseNodeClass *pyrPushKeyArgNodeClass; + +struct PyrLiteralNode : public PyrParseNode { + PyrSlot literalSlot; +} ; + +extern PyrParseNodeClass *pyrLiteralNodeClass; + + +struct PyrReturnNode : public PyrParseNode { + struct PyrParseNode *expr; // if null, return self +} ; + +extern PyrParseNodeClass *pyrReturnNodeClass; + +struct PyrBlockReturnNode : public PyrParseNode { + struct PyrParseNode *expr; // if null, return self +} ; + +extern PyrParseNodeClass *pyrBlockReturnNodeClass; + + +struct PyrAssignNode : public PyrParseNode { + struct PyrSlotNode* varName; + struct PyrParseNode *expr; + bool drop; // allow drop +} ; + +extern PyrParseNodeClass *pyrAssignNodeClass; + +struct PyrSetterNode : public PyrParseNode { + struct PyrSlotNode* selector; + struct PyrParseNode *expr1; + struct PyrParseNode *expr2; + int flags; // is a var def ? +} ; + +extern PyrParseNodeClass *pyrSetterNodeClass; + +struct PyrMultiAssignNode : public PyrParseNode { + struct PyrMultiAssignVarListNode *varList; + struct PyrParseNode *expr; + bool drop; // allow drop +} ; + +extern PyrParseNodeClass *pyrMultiAssignNodeClass; + +struct PyrMultiAssignVarListNode : public PyrParseNode { + struct PyrSlotNode *varNames; + struct PyrSlotNode *rest; +} ; + +extern PyrParseNodeClass *pyrMultiAssignVarListNodeClass; + +struct PyrBlockNode : public PyrParseNode { + struct PyrArgListNode *arglist; + struct PyrVarListNode *varlist; + struct PyrParseNode *body; + bool isTopLevel; + int beginCharNo; +} ; + + +extern PyrParseNodeClass *pyrBlockNodeClass; + +struct PyrArgListNode : public PyrParseNode { + struct PyrVarDefNode *varDefs; + struct PyrSlotNode *rest; +} ; + +extern PyrParseNodeClass *pyrArgListNodeClass; + +struct PyrDynListNode : public PyrParseNode { + struct PyrParseNode *classname; + struct PyrParseNode *elems; +} ; + +extern PyrParseNodeClass *pyrDynListNodeClass; + +struct PyrDynDictNode : public PyrParseNode { + struct PyrParseNode *elems; +} ; + +extern PyrParseNodeClass *pyrDynDictNodeClass; + +struct PyrLitListNode : public PyrParseNode { + struct PyrParseNode *classname; + struct PyrParseNode *elems; +} ; + +extern PyrParseNodeClass *pyrLitListNodeClass; + +extern PyrParseNode* gRootParseNode; +extern int gParserResult; + +enum { rwPrivate=0, rwReadOnly=1, rwWriteOnly=2, rwReadWrite=3 }; + +enum { varInst, varClass, varTemp, varPseudo }; + +enum { + /* structural units */ + pn_ClassNode, + pn_ClassExtNode, + pn_MethodNode, + pn_BlockNode, + pn_SlotNode, + + /* variable declarations */ + pn_VarListNode, + pn_VarDefNode, + pn_DynDictNode, + pn_DynListNode, + pn_LitListNode, + + pn_StaticVarListNode, + pn_InstVarListNode, + pn_PoolVarListNode, + pn_ArgListNode, + pn_SlotDefNode, + + /* selectors */ + pn_LiteralNode, + + /* code */ + pn_PushLitNode, + pn_PushNameNode, + pn_PushKeyArgNode, + pn_CallNode, + pn_BinopCallNode, + pn_DropNode, + pn_AssignNode, + pn_MultiAssignNode, + pn_MultiAssignVarListNode, + pn_SetterNode, + + pn_ReturnNode, + pn_BlockReturnNode, + + pn_NumTypes +}; + +extern char *parseNodeFormat[pn_NumTypes]; +extern PyrParseNodeClass* parseNodeClasses[pn_NumTypes]; + + +void initParseNodes(); + +PyrParseNodeClass* newParseNodeClass(int type, PyrCompileNodeFunc compileFunc, + PyrDumpNodeFunc dumpFunc); + +PyrSlotNode* newPyrSlotNode(PyrSlot *slot); +PyrClassNode* newPyrClassNode(PyrSlotNode* className, PyrSlotNode* superClassName, + PyrVarListNode* varlists, PyrMethodNode* methods, PyrSlotNode* indexType); +PyrClassExtNode* newPyrClassExtNode(PyrSlotNode* className, PyrMethodNode* methods); +PyrMethodNode* newPyrMethodNode(PyrSlotNode* methodName, PyrSlotNode* primitiveName, + PyrArgListNode* arglist, PyrVarListNode *varlist, PyrParseNode* body, int isClassMethod); +PyrArgListNode* newPyrArgListNode(PyrVarDefNode* varDefs, PyrSlotNode* rest); +PyrVarListNode* newPyrVarListNode(PyrVarDefNode* vardefs, int flags); +PyrVarDefNode* newPyrVarDefNode(PyrSlotNode* varName, PyrLiteralNode* defVal, int flags); +PyrCallNode* newPyrCallNode(PyrSlotNode* selector, PyrParseNode* arglist, + PyrParseNode* keyarglist, PyrParseNode* blocklist); +PyrBinopCallNode* newPyrBinopCallNode(PyrSlotNode* selector, + PyrParseNode* arg1, PyrParseNode* arg2, PyrParseNode* arg3); +PyrDropNode* newPyrDropNode(PyrParseNode* expr1, PyrParseNode* expr2); +PyrPushKeyArgNode* newPyrPushKeyArgNode(PyrSlotNode* selector, PyrParseNode* expr); +PyrPushLitNode* newPyrPushLitNode(PyrSlotNode* literalSlot, PyrParseNode* literalObj); +PyrLiteralNode* newPyrLiteralNode(PyrSlotNode* literalSlot, PyrParseNode* literalObj); +PyrReturnNode* newPyrReturnNode(PyrParseNode* expr); +PyrBlockReturnNode* newPyrBlockReturnNode(); +PyrAssignNode* newPyrAssignNode(PyrSlotNode* varName, PyrParseNode* expr, int flags); +PyrSetterNode* newPyrSetterNode(PyrSlotNode* varName, + PyrParseNode* expr1, PyrParseNode* expr2); +PyrMultiAssignNode* newPyrMultiAssignNode(PyrMultiAssignVarListNode* varList, + PyrParseNode* expr, int flags); +PyrPushNameNode* newPyrPushNameNode(PyrSlotNode *slotNode); +PyrDynDictNode* newPyrDynDictNode(PyrParseNode *elems); +PyrDynListNode* newPyrDynListNode(PyrParseNode *classname, PyrParseNode *elems); +PyrLitListNode* newPyrLitListNode(PyrParseNode *classname, PyrParseNode *elems); +PyrMultiAssignVarListNode* newPyrMultiAssignVarListNode(PyrSlotNode* varNames, + PyrSlotNode* rest); +PyrBlockNode* newPyrBlockNode(PyrArgListNode *arglist, PyrVarListNode *varlist, PyrParseNode *body, bool isTopLevel); + +void compilePyrSlotNode(PyrSlotNode* node, void *result); +void compilePyrClassNode(PyrClassNode* node, void *result); +void compilePyrClassExtNode(PyrClassExtNode* node, void *result); +void compilePyrMethodNode(PyrMethodNode* node, void *result); +void compilePyrArgListNode(PyrArgListNode* node, void *result); +void compilePyrVarListNode(PyrVarListNode* node, void *result); +void compilePyrVarDefNode(PyrVarDefNode* node, void *result); +void compilePyrCallNode(PyrCallNode* node, void *result); +void compilePyrBinopCallNode(PyrBinopCallNode* node, void *result); +void compilePyrPushLitNode(PyrPushLitNode* node, void *result); +void compilePyrLiteralNode(PyrLiteralNode* node, void *result); +void compilePyrReturnNode(PyrReturnNode* node, void *result); +void compilePyrBlockReturnNode(PyrBlockReturnNode* node, void *result); +void compilePyrAssignNode(PyrAssignNode* node, void *result); +void compilePyrSetterNode(PyrSetterNode* node, void* result); +void compilePyrMultiAssignNode(PyrMultiAssignNode* node, void *result); +void compilePyrMultiAssignVarListNode(PyrMultiAssignVarListNode* node, void *result); +void compilePyrDynDictNode(PyrDynDictNode* node, void *result); +void compilePyrDynListNode(PyrDynListNode* node, void *result); +void compilePyrLitListNode(PyrLitListNode* node, void *result); +void compilePyrBlockNode(PyrBlockNode* node, void *result); +void compilePyrPushNameNode(PyrPushNameNode* node, void *result); +void compilePyrDropNode(PyrDropNode* node, void *result); +void compilePyrPushKeyArgNode(PyrPushKeyArgNode* node, void *result); + +void dumpPyrSlotNode(PyrSlotNode* node, int level); +void dumpPyrClassNode(PyrClassNode* node, int level); +void dumpPyrClassExtNode(PyrClassExtNode* node, int level); +void dumpPyrMethodNode(PyrMethodNode* node, int level); +void dumpPyrArgListNode(PyrArgListNode* node, int level); +void dumpPyrVarListNode(PyrVarListNode* node, int level); +void dumpPyrVarDefNode(PyrVarDefNode* node, int level); +void dumpPyrCallNode(PyrCallNode* node, int level); +void dumpPyrBinopCallNode(PyrBinopCallNode* node, int level); +void dumpPyrPushLitNode(PyrPushLitNode* node, int level); +void dumpPyrLiteralNode(PyrLiteralNode* node, int level); +void dumpPyrReturnNode(PyrReturnNode* node, int level); +void dumpPyrBlockReturnNode(PyrBlockReturnNode* node, int level); +void dumpPyrAssignNode(PyrAssignNode* node, int level); +void dumpPyrSetterNode(PyrSetterNode* node, int level); +void dumpPyrMultiAssignNode(PyrMultiAssignNode* node, int level); +void dumpPyrMultiAssignVarListNode(PyrMultiAssignVarListNode* node, int level); +void dumpPyrDynDictNode(PyrDynDictNode* node, int level); +void dumpPyrDynListNode(PyrDynListNode* node, int level); +void dumpPyrLitListNode(PyrLitListNode* node, int level); +void dumpPyrBlockNode(PyrBlockNode* node, int level); +void dumpPyrPushNameNode(PyrPushNameNode* node, int level); +void dumpPyrPushKeyArgNode(PyrPushKeyArgNode* node, int level); +void dumpPyrDropNode(PyrDropNode* node, int level); + +PyrClass* getNodeSuperclass(PyrClassNode *node); +void countNodeMethods(PyrClassNode* node, int *numClassMethods, int *numInstMethods); +void compileExtNodeMethods(PyrClassExtNode* node); +void countVarDefs(PyrClassNode* node); +bool compareVarDefs(PyrClassNode* node, PyrClass* classobj); +void recompileSubclasses(PyrClass* classobj); +void compileNodeMethods(PyrClassNode* node); +void fillClassPrototypes(PyrClassNode *node, PyrClass *classobj, PyrClass *superclassobj); + +int nodeListLength(PyrParseNode *node); +bool isSuperObjNode(PyrParseNode *node); +bool isThisObjNode(PyrParseNode *node); +int conjureSelectorIndex(PyrParseNode *node, PyrBlock* func, + bool isSuper, PyrSymbol *selector, int *selType); +int conjureLiteralSlotIndex(PyrParseNode *node, PyrBlock* func, PyrSlot *slot); +bool findVarName(PyrBlock* func, PyrClass **classobj, PyrSymbol *name, + int *varType, int *level, int *index, PyrBlock** tempfunc); +void countClassVarDefs(PyrClassNode* node, int *numClassMethods, int *numInstMethods); +void compileNodeList(PyrParseNode *node); +void dumpNodeList(PyrParseNode *node); +int compareCallArgs(PyrMethodNode* node, PyrCallNode *cnode, int *varIndex); + +bool findSpecialClassName(PyrSymbol *className, int *index); +int getIndexType(PyrClassNode *classnode); + +void compileIfMsg(PyrCallNode* node); +void compileWhileMsg(PyrCallNode* node); +void compileLoopMsg(PyrCallNode* node); +void compileAndMsg(PyrParseNode* arg1, PyrParseNode* arg2); +void compileOrMsg(PyrParseNode* arg1, PyrParseNode* arg2); + +void compilePushInt(int value); +void compileAssignVar(PyrParseNode *node, PyrSymbol* varName, bool drop); +void compilePushVar(PyrParseNode *node, PyrSymbol *varName); +bool isAnInlineableBlock(PyrParseNode *node); +bool isWhileTrue(PyrParseNode *node); +void installByteCodes(PyrBlock *block); + +ByteCodes compileSubExpression(PyrPushLitNode* litnode); +ByteCodes compileSubExpressionWithGoto(PyrPushLitNode* litnode, int branchLen); +//ByteCodes compileDefaultValue(int litIndex, int realExprLen); + +void initParser(); +void finiParser(); +void initParserPool(); +void freeParserPool(); + +void initSpecialSelectors(); +void initSpecialClasses(); + +void nodePostErrorLine(PyrParseNode* node); + +PyrParseNode* linkNextNode(PyrParseNode* a, PyrParseNode* b); +PyrParseNode* linkAfterHead(PyrParseNode* a, PyrParseNode* b); + +extern int compileErrors; + +extern long zzval; +extern PyrSymbol *ps_newlist; +extern PyrSymbol *gSpecialUnarySelectors[opNumUnarySelectors]; +extern PyrSymbol *gSpecialBinarySelectors[opNumBinarySelectors]; +extern PyrSymbol *gSpecialSelectors[opmNumSpecialSelectors]; +extern PyrSymbol* gSpecialClasses[op_NumSpecialClasses]; + +extern PyrClass *gCurrentClass; +extern PyrClass *gCurrentMetaClass; +extern PyrClass *gCompilingClass; +extern PyrMethod *gCompilingMethod; +extern PyrBlock *gCompilingBlock; + +/* + compiling + "inlining" of special arithmetic opcodes. + inlining of IF, WHILE, AND, OR +*/ + +#endif diff --git a/sc4pd/headers/lang/PyrPrimitive.h b/sc4pd/headers/lang/PyrPrimitive.h new file mode 100755 index 0000000..4afe653 --- /dev/null +++ b/sc4pd/headers/lang/PyrPrimitive.h @@ -0,0 +1,42 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +Functions for defining language primitives. + +*/ + +#ifndef _PYRPRIMITIVE_H_ +#define _PYRPRIMITIVE_H_ + +#include "PyrSlot.h" + +typedef int (*PrimitiveHandler)(struct VMGlobals *g, int numArgsPushed); +typedef int (*PrimitiveWithKeysHandler)(struct VMGlobals *g, int numArgsPushed, int numKeyArgsPushed); + +int nextPrimitiveIndex(); +int definePrimitive(int base, int index, char *name, PrimitiveHandler handler, int numArgs, int varArgs); +int definePrimitiveWithKeys(int base, int index, char *name, + PrimitiveHandler handler, PrimitiveWithKeysHandler keyhandler, + int numArgs, int varArgs); +int getPrimitiveNumArgs(int index); +PyrSymbol* getPrimitiveName(int index); + +#endif diff --git a/sc4pd/headers/lang/PyrPrimitiveProto.h b/sc4pd/headers/lang/PyrPrimitiveProto.h new file mode 100755 index 0000000..43464a4 --- /dev/null +++ b/sc4pd/headers/lang/PyrPrimitiveProto.h @@ -0,0 +1,81 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _PYRPRIMITIVEPROTO_H_ +#define _PYRPRIMITIVEPROTO_H_ + +#include "PyrPrimitive.h" + +int basicNew(VMGlobals *g, int numArgsPushed); +int basicNewClear(VMGlobals *g, int numArgsPushed); +int basicSwap(VMGlobals *g, int numArgsPushed); +int instVarAt(VMGlobals *g, int numArgsPushed); +int instVarPut(VMGlobals *g, int numArgsPushed); +int instVarSize(VMGlobals *g, int numArgsPushed); +int objectHash(VMGlobals *g, int numArgsPushed); +int objectClass(VMGlobals *g, int numArgsPushed); +int blockValue(VMGlobals *g, int numArgsPushed); +int blockValueWithKeys(VMGlobals *g, int allArgsPushed, int numKeyArgsPushed); +int blockValueArray(VMGlobals *g, int numArgsPushed); +int blockSpawn(VMGlobals *g, int numArgsPushed); + +int objectIsKindOf(VMGlobals *g, int numArgsPushed); +int objectIsMemberOf(VMGlobals *g, int numArgsPushed); +int objectDump(VMGlobals *g, int numArgsPushed); +int haltInterpreter(VMGlobals *g, int numArgsPushed); +int objectIdentical(VMGlobals *g, int numArgsPushed); +int objectNotIdentical(VMGlobals *g, int numArgsPushed); +int objectPerform(VMGlobals *g, int numArgsPushed); +int objectPerformList(VMGlobals *g, int numArgsPushed); +int objectPerformSelList(VMGlobals *g, int numArgsPushed); +int undefinedPrimitive(VMGlobals *g, int numArgsPushed); + +int prObjectString(VMGlobals *g, int numArgsPushed); +int prClassString(VMGlobals *g, int numArgsPushed); +int prSymbolString(VMGlobals *g, int numArgsPushed); +int prSymbolClass(VMGlobals *g, int numArgsPushed); +int prPostString(VMGlobals *g, int numArgsPushed); +int prPostLine(VMGlobals *g, int numArgsPushed); +int prFlushPostBuf(VMGlobals *g, int numArgsPushed); + +int prPrimitiveError(VMGlobals *g, int numArgsPushed); +int prPrimitiveErrorString(VMGlobals *g, int numArgsPushed); +int prDumpStack(VMGlobals *g, int numArgsPushed); +int prDebugger(VMGlobals *g, int numArgsPushed); +int prPrimName(VMGlobals *g, int numArgsPushed); +int prObjectShallowCopy(VMGlobals *g, int numArgsPushed); +int prObjectCopyRange(VMGlobals *g, int numArgsPushed); +int prObjectPointsTo(VMGlobals *g, int numArgsPushed); +int prObjectRespondsTo(VMGlobals *g, int numArgsPushed); + +int prCompileString(VMGlobals *g, int numArgsPushed); +int prDumpBackTrace(VMGlobals *g, int numArgsPushed); +int prDumpByteCodes(VMGlobals *g, int numArgsPushed); +int prAllClasses(VMGlobals *g, int numArgsPushed); +int prPostClassTree(VMGlobals *g, int numArgsPushed); + +void initPrimitiveTable(); +void growPrimitiveTable(int newsize); + +void initPrimitives(); +void doPrimitive(VMGlobals* g, struct PyrMethod* meth, int numArgsPushed); +void doPrimitiveWithKeys(VMGlobals* g, struct PyrMethod* meth, int allArgsPushed, int numKeysPushed); + +#endif diff --git a/sc4pd/headers/lang/PyrSched.h b/sc4pd/headers/lang/PyrSched.h new file mode 100755 index 0000000..5102582 --- /dev/null +++ b/sc4pd/headers/lang/PyrSched.h @@ -0,0 +1,58 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _PYRSCHED_H_ +#define _PYRSCHED_H_ + +#include "VMGlobals.h" +#include + +extern pthread_mutex_t gLangMutex; + +void schedInit(); +void schedCleanup(); + +void schedRun(); +void schedStop(); +void schedClear(); + +double elapsedTime(); +int64 OSCTime(); + +int64 ElapsedTimeToOSC(double elapsed); +double OSCToElapsedTime(int64 oscTime); + +void syncOSCOffsetWithTimeOfDay(); +void doubleToTimespec(double secs, struct timespec *spec); + + +bool addheap(VMGlobals *g, PyrObject *heap, double schedtime, PyrSlot *task); +bool lookheap(PyrObject *heap, double *schedtime, PyrSlot *task) ; +bool getheap(PyrObject *heap, double *schedtime, PyrSlot *task) ; +void offsetheap(VMGlobals *g, PyrObject *heap, double offset) ; +void dumpheap(PyrObject *heap); + +const double kSecondsToOSC = 4294967296.; // pow(2,32)/1 +const double kMicrosToOSC = 4294.967296; // pow(2,32)/1e6 +const double kNanosToOSC = 4.294967296; // pow(2,32)/1e9 +const double kOSCtoSecs = 2.328306436538696e-10; // 1/pow(2,32) +const double kOSCtoNanos = 0.2328306436538696; // 1e9/pow(2,32) + +#endif \ No newline at end of file diff --git a/sc4pd/headers/lang/PyrSignal.h b/sc4pd/headers/lang/PyrSignal.h new file mode 100755 index 0000000..ee57b38 --- /dev/null +++ b/sc4pd/headers/lang/PyrSignal.h @@ -0,0 +1,417 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#pragma once on + +#include "PyrObject.h" +#include "GC.h" + +#define UNROLL 1 + +enum { + kSignalRate = 0, // index of rate slot + kSignalNextNode +}; + +#define FSINESIZE 8192. +#define SINESIZE 8192 +#define SINEMASK 8191 +#define VERY_BIG_FLOAT (1.e10) +extern float *sineCycle; +extern float *invSineCycle; +extern float *pmSineCycle; +extern double phaseToSineIndex; +extern double sineIndexToPhase; + +//#define FRACTABLESIZE 4096 +//#define FRACMASK 0x3FFC +//extern float *gFracTable; + + +PyrObject* newPyrSignal(VMGlobals *g, long size); + +#if 0 +#define UNROLL8_CODE(size,var,stmt) \ + endptr = var + size; \ + switch (size & 7) { \ + while (var < endptr) { \ + stmt; \ + case 7 : stmt; \ + case 6 : stmt; \ + case 5 : stmt; \ + case 4 : stmt; \ + case 3 : stmt; \ + case 2 : stmt; \ + case 1 : stmt; \ + case 0 : ; \ + } \ + } +#else +#define UNROLL8_CODE(size,var,stmt) \ + { int tempi, tempend; \ + tempend = size>>3; \ + for (tempi=0; tempi>2; \ + for (tempi=0; tempi>2; \ + for (tempi=0; tempislots) - 1; \ + b = (float*)(inb->slots) - 1; \ + size = sc_min(ina->size, inb->size); \ + outc = newPyrSignal(g, size); \ + c = (float*)(outc->slots) - 1; \ + endptr = c + size; \ + switch (size & 3) { \ + while (c < endptr) { \ + *++c = *++a OP *++b; \ + case 3 : *++c = *++a OP *++b; \ + case 2 : *++c = *++a OP *++b; \ + case 1 : *++c = *++a OP *++b; \ + case 0 : ; \ + } \ + } \ + return outc; \ + + +#define BINOP_LOOP2(STMT1) \ + float *a, *b, *c, *endptr; \ + PyrObject *outc; \ + long size; \ + a = (float*)(ina->slots) - 1; \ + b = (float*)(inb->slots) - 1; \ + size = sc_min(ina->size, inb->size); \ + outc = newPyrSignal(g, size); \ + c = (float*)(outc->slots) - 1; \ + endptr = c + size; \ + switch (size & 3) { \ + while (c < endptr) { \ + STMT1; \ + case 3 :STMT1; \ + case 2 :STMT1; \ + case 1 :STMT1; \ + case 0 : ; \ + } \ + } \ + return outc; \ + +#endif + +/* + compound formulas : + amclip out = B<=0 ? 0 : A*B; // two quadrant amplitude modulation + ring1 out = A*(B+1) = A*B + A; // amplitude modulation of a by b. + ring2 out = A*B + A + B; // ring modulation plus both original signals + ring3 out = A*A*B; // ring modulation variant + ring4 out = A*A*B - A*B*B; // ring modulation variant + difsqr out = A*A - B*B; // difference of squares + sumsqr out = A*A + B*B; // sum of squares + sqrdif out = (A - B)^2 // square of the difference = a^2 + b^2 - 2ab + sqrsum out = (A + B)^2 // square of the sum = a^2 + b^2 + 2ab +*/ + +void signal_init_globs(); +PyrObject* signal_fill(PyrObject *outSignal, float inValue); +PyrObject* signal_scale(PyrObject *outSignal, float inValue); +PyrObject* signal_offset(PyrObject *outSignal, float inValue); +PyrObject* signal_scale_offset(PyrObject *outSignal, float mul, float add); +PyrObject* signal_mix(PyrObject* ina, PyrObject* inb, float start, float end, float slopeFactor); +PyrObject* signal_add_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_sub_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_mul_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_mul_ds_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_add_ds_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_sub_ds_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_ring1_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_ring2_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_ring3_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_ring4_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_thresh_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_amclip_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_div_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_difsqr_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_sumsqr_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_sqrsum_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_sqrdif_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_add_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_sub_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_mul_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_ring1_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_ring2_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_ring3_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_ring4_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_thresh_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_amclip_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_div_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_difsqr_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_sumsqr_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_sqrsum_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_sqrdif_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_ring1_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_ring2_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_ring3_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_ring4_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_thresh_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_amclip_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_sub_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_div_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_difsqr_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_sumsqr_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_sqrsum_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_sqrdif_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_min_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_max_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_min_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_max_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_invert(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_recip(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_squared(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_cubed(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_abs(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_sign(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_negative(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_positive(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_strictly_positive(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_nyqring(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_clip_f(VMGlobals *g, PyrObject *inPyrSignal, float lo, float hi); +PyrObject* signal_clip_f_ds(PyrObject *inPyrSignal, float lo, float hi); +PyrObject* signal_clip_x(VMGlobals *g, PyrObject *ina, PyrObject *inb, PyrObject *inc); +PyrObject* signal_wrap_f(VMGlobals *g, PyrObject *inPyrSignal, float lo, float hi); +PyrObject* signal_wrap_x(VMGlobals *g, PyrObject *ina, PyrObject *inb, PyrObject *inc); +PyrObject* signal_fold_f(VMGlobals *g, PyrObject *inPyrSignal, float lo, float hi); +PyrObject* signal_fold_x(VMGlobals *g, PyrObject *ina, PyrObject *inb, PyrObject *inc); +PyrObject* signal_log(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_log2(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_log10(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_sin(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_cos(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_tan(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_sinh(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_cosh(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_tanh(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_asin(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_acos(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_atan(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_exp(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_sqrt(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_distort(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_distortneg(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_softclip(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_softclipneg(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_fsin(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_poly3(VMGlobals *g, PyrObject *inPyrSignal, float a, float b, float c); +PyrObject* signal_poly3r(VMGlobals *g, PyrObject *inPyrSignal, + float a1, float a2, float b1, float b2, float c1, float c2, float slopeFactor); +PyrObject* signal_integrate(VMGlobals *g, PyrObject *inPyrSignal, float *ioSum); +PyrObject* signal_leakdc(VMGlobals *g, PyrObject *inPyrSignal, float *ioDC, float leakFactor); +PyrObject* signal_ampflw1(VMGlobals *g, PyrObject *inPyrSignal, float *ioAmp, float leak1); +PyrObject* signal_ampflw2(VMGlobals *g, PyrObject *inPyrSignal, float *ioAmp, float leak1); +PyrObject* signal_differentiate(VMGlobals *g, PyrObject *inPyrSignal, float *ioPrev); +PyrObject* signal_rotate(VMGlobals *g, PyrObject* ina, int rot); +PyrObject* signal_reverse_ds(PyrObject* ina); +PyrObject* signal_cat(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_insert(VMGlobals *g, PyrObject* ina, PyrObject* inb, long index); +PyrObject* signal_overdub(VMGlobals *g, PyrObject* ina, PyrObject* inb, long index); +PyrObject* signal_overwrite(VMGlobals *g, PyrObject* ina, PyrObject* inb, long index); +PyrObject* signal_cat3(VMGlobals *g, PyrObject* ina, PyrObject* inb, PyrObject* inc); +PyrObject* signal_linen(VMGlobals *g, PyrObject* ina, long atk, long dcy, float amp); +PyrObject* signal_linen2(VMGlobals *g, PyrObject* ina, long atk, long dcy, float amp, float midamp); +PyrObject* signal_writesplice(VMGlobals *g, PyrObject* outc, PyrObject* ina, PyrObject* inb, + long indexc, long indexa, long indexb, long fadelen, float midamp); +PyrObject* signal_splice(VMGlobals *g, PyrObject* ina, PyrObject* inb, + long indexa, long indexb, long fadelen, float midamp); + +PyrObject* signal_invert_ds(PyrObject *inPyrSignal); +PyrObject* signal_recip_ds(PyrObject *inPyrSignal); +PyrObject* signal_squared_ds(PyrObject *inPyrSignal); +PyrObject* signal_cubed_ds(PyrObject *inPyrSignal); +PyrObject* signal_abs_ds(PyrObject *inPyrSignal); +PyrObject* signal_sign_ds(PyrObject *inPyrSignal); +PyrObject* signal_negative_ds(PyrObject *inPyrSignal); +PyrObject* signal_positive_ds(PyrObject *inPyrSignal); +PyrObject* signal_strictly_positive_ds(PyrObject *inPyrSignal); +PyrObject* signal_nyqring_ds(PyrObject *inPyrSignal); + +PyrObject* signal_clipneg_ds(PyrObject *inPyrSignal); +PyrObject* signal_distort_ds(PyrObject *inPyrSignal); +PyrObject* signal_distortneg_ds(PyrObject *inPyrSignal); +PyrObject* signal_softclip_ds(PyrObject *inPyrSignal); +PyrObject* signal_softclipneg_ds(PyrObject *inPyrSignal); +PyrObject* signal_fsin_ds(PyrObject *inPyrSignal); + +PyrObject* signal_log_ds(PyrObject *inPyrSignal); +PyrObject* signal_log2_ds(PyrObject *inPyrSignal); +PyrObject* signal_log10_ds(PyrObject *inPyrSignal); +PyrObject* signal_sin_ds(PyrObject *inPyrSignal); +PyrObject* signal_cos_ds(PyrObject *inPyrSignal); +PyrObject* signal_tan_ds(PyrObject *inPyrSignal); +PyrObject* signal_sinh_ds(PyrObject *inPyrSignal); +PyrObject* signal_cosh_ds(PyrObject *inPyrSignal); +PyrObject* signal_tanh_ds(PyrObject *inPyrSignal); +PyrObject* signal_asin_ds(PyrObject *inPyrSignal); +PyrObject* signal_acos_ds(PyrObject *inPyrSignal); +PyrObject* signal_atan_ds(PyrObject *inPyrSignal); +PyrObject* signal_exp_ds(PyrObject *inPyrSignal); +PyrObject* signal_sqrt_ds(PyrObject *inPyrSignal); + +float signal_findpeak(PyrObject *inPyrSignal); +PyrObject* signal_normalize(PyrObject *inPyrSignal); +PyrObject* signal_normalize_transfer_fn(PyrObject *inPyrSignal); +float signal_integral(PyrObject *inPyrSignal); +PyrObject* signal_combself(VMGlobals *g, PyrObject* ina, long rot); +PyrObject* signal_bilinen(VMGlobals *g, PyrObject* ina, long atk, long dcy, float amp, float midamp); +PyrObject* signal_lace2(VMGlobals *g, PyrObject* ina, PyrObject* inb); +void signal_unlace2(VMGlobals *g, PyrObject* ina, PyrObject** outb, PyrObject** outc); +void signal_convolve(VMGlobals *g, PyrObject* ina, PyrObject* ir, PyrObject* previn, long *ppos); +PyrObject* signal_thumbnail(VMGlobals *g, PyrObject* ina, long startpos, long length, int binsize); + +PyrObject* signal_scaleneg_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_scaleneg_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_scaleneg_fx(VMGlobals *g, float ina, PyrObject* inb); + +PyrObject* signal_clip2_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_clip2_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_clip2_fx(VMGlobals *g, float ina, PyrObject* inb); + +PyrObject* signal_fold2_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_fold2_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_fold2_fx(VMGlobals *g, float ina, PyrObject* inb); + +PyrObject* signal_wrap2_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_wrap2_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_wrap2_fx(VMGlobals *g, float ina, PyrObject* inb); + +PyrObject* signal_excess_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_excess_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_excess_fx(VMGlobals *g, float ina, PyrObject* inb); + +PyrObject* signal_absdif_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_absdif_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_absdif_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); + +bool signal_equal_xf(VMGlobals *g, PyrObject* ina, float inb); +bool signal_equal_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); + +void signal_get_bounds(PyrObject* ina, float *ominval, float *omaxval); + +void signal_smooth_ds(PyrObject* inPyrSignal); +void signal_hanning_ds(PyrObject* inPyrSignal); +void signal_welch_ds(PyrObject* inPyrSignal); +void signal_parzen_ds(PyrObject* inPyrSignal); + +PyrObject* signal_normalize_range(PyrObject* ina, long start, long end); +PyrObject* signal_zero_range(PyrObject* ina, long start, long end); +PyrObject* signal_invert_range(PyrObject* ina, long start, long end); +PyrObject* signal_reverse_range(PyrObject* ina, long start, long end); +PyrObject* signal_fade_in(PyrObject* ina, long start, long end); +PyrObject* signal_fade_out(PyrObject* ina, long start, long end); +PyrObject* signal_abs_range(PyrObject* ina, long start, long end); +PyrObject* signal_squared_range(PyrObject* ina, long start, long end); +PyrObject* signal_cubed_range(PyrObject* ina, long start, long end); +PyrObject* signal_distort_range(PyrObject* ina, long start, long end); + +PyrObject* signal_fade_range(PyrObject* ina, long start, long end, float lvl0, float lvl1); diff --git a/sc4pd/headers/lang/PyrSignalPrim.h b/sc4pd/headers/lang/PyrSignalPrim.h new file mode 100755 index 0000000..bea68ca --- /dev/null +++ b/sc4pd/headers/lang/PyrSignalPrim.h @@ -0,0 +1,56 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _PYRSIGNALPRIM_H_ +#define _PYRSIGNALPRIM_H_ + +extern PyrSymbol *s_wavetable; +extern struct PyrClass *class_wavetable; + +void initSignalPrimitives(); + +int prSignalCat(VMGlobals *g, int numArgsPushed); +int prSignalFill(VMGlobals *g, int numArgsPushed); +int prSignalRamp(VMGlobals *g, int numArgsPushed); +int prSignalScale(VMGlobals *g, int numArgsPushed); +int prSignalOffset(VMGlobals *g, int numArgsPushed); +int prSignalString(VMGlobals *g, int numArgsPushed); + +int prSignalPeak(VMGlobals *g, int numArgsPushed); +int prSignalNormalize(VMGlobals *g, int numArgsPushed); +int prSignalNormalizeTransferFn(VMGlobals *g, int numArgsPushed); +int prSignalIntegral(VMGlobals *g, int numArgsPushed); + +int prSignalOverDub(VMGlobals *g, int numArgsPushed); +int prSignalOverWrite(VMGlobals *g, int numArgsPushed); +int prSignalFade(VMGlobals *g, int numArgsPushed); +int prSignalAddHarmonic(VMGlobals *g, int numArgsPushed); +int prSignalAsWavetable(VMGlobals *g, int numArgsPushed); +int prWavetableAsSignal(VMGlobals *g, int numArgsPushed); + +int prSignalInvert(VMGlobals *g, int numArgsPushed); +int prSignalReverse(VMGlobals *g, int numArgsPushed); +int prSignalRotate(VMGlobals *g, int numArgsPushed); + +void signalAsWavetable(float *signal, float *wavetable, int size); +void wavetableAsSignal(float *wavetable, float *signal, int size); + +#endif diff --git a/sc4pd/headers/lang/PyrSlot.h b/sc4pd/headers/lang/PyrSlot.h new file mode 100755 index 0000000..78bcd12 --- /dev/null +++ b/sc4pd/headers/lang/PyrSlot.h @@ -0,0 +1,286 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +PyrSlot is a value holder for SC variables. +A PyrSlot is an 8-byte value which is either a double precision float or a +32-bit tag plus a 32-bit value. + +*/ + +#ifndef _PYRSLOT_H_ +#define _PYRSLOT_H_ + +#include "SC_Endian.h" +#include "PyrSymbol.h" + +/* + Pyrite slots are the size of an 8 byte double. If the upper bits + indicate that the double is a 'Not-A-Number' then the upper 32 + bits are used as a tag to indicate one of a number of other types + whose data is in the lower 32 bits. +*/ + +/* some DSPs like the TIC32 do not support 8 byte doubles */ +/* on such CPUs, set DOUBLESLOTS to zero */ + +#define DOUBLESLOTS 1 + +/* use the high order bits of an IEEE double NaN as a tag */ +enum { + tagObj = 0x7FF90001, + tagHFrame = 0x7FF90002, + tagSFrame = 0x7FF90003, + tagInt = 0x7FF90004, + tagSym = 0x7FF90005, + tagChar = 0x7FF90006, + tagNil = 0x7FF90007, // nil, false, and true are indicated by the tag alone. + tagFalse = 0x7FF90008, // the lower 32 bits are zero. + tagTrue = 0x7FF90009, + tagInf = 0x7FF9000A, + tagPtr = 0x7FF9000B, + /* anything else is a double */ + tagUnused = 0x7FF9000E + + +#if !DOUBLESLOTS + ,tagFloat = 0x7FF9000F /* used only to initialized 4 byte float tags, never compared with */ +#endif +}; + +struct RGBColor8 { + unsigned char c[4]; +}; + +typedef union pyrslot { + double f; + struct { +#if BYTE_ORDER == BIG_ENDIAN + int tag; +#endif // BIG_ENDIAN + union { + int c; /* char */ + int i; + float f; + void *ptr; + struct RGBColor8 r; + struct PyrObject *o; + PyrSymbol *s; + struct PyrMethod *om; + struct PyrBlock *oblk; + struct PyrClass *oc; + struct PyrFrame *of; + struct PyrList *ol; + struct PyrString *os; + struct PyrInt8Array *ob; + struct PyrDoubleArray *od; + struct PyrSymbolArray *osym; + struct PyrParseNode *opn; + struct PyrProcess *op; + struct PyrThread *ot; + struct PyrInterpreter *oi; + struct PyrPlug *plug; + } u; +#if BYTE_ORDER == LITTLE_ENDIAN + // need to swap on intel + int tag; +#endif // LITTLE_ENDIAN + } s; +} PyrSlot; + +/* + these are some defines to make accessing the structure less verbose. + obviously it polutes the namespace of identifiers beginning with 'u'. +*/ +#define utag s.tag +//int +#define ui s.u.i +//PyrObject +#define uo s.u.o +//PyrSymbol +#define us s.u.s +//RGBColor8 +#define ur s.u.r +#define uc s.u.c +#define uoc s.u.oc +#define uof s.u.of +#define uol s.u.ol +#define uod s.u.od +#define uob s.u.ob +#define uop s.u.op +#define uoi s.u.oi +#define uod s.u.od +//string +#define uos s.u.os +#define uot s.u.ot +//method +#define uom s.u.om +//symbol array +#define uosym s.u.osym +#define uoblk s.u.oblk +#define uopn s.u.opn +#define uptr s.u.ptr +#define uplug s.u.plug + +#if DOUBLESLOTS +#define uf f +#else +#define uf s.u.f +#endif + +#define ucopy f + +/* + Note that on the PowerPC, the fastest way to copy a slot is to + copy the double field, not the struct. +*/ + +/* some macros for setting values of slots */ +inline void SetInt(PyrSlot* slot, int val) { (slot)->utag = tagInt; (slot)->ui = (val); } +inline void SetObject(PyrSlot* slot, void* val) { (slot)->utag = tagObj; (slot)->uo = (PyrObject*)(val); } +inline void SetSymbol(PyrSlot* slot, PyrSymbol *val) { (slot)->utag = tagSym; (slot)->us = (val); } +inline void SetChar(PyrSlot* slot, char val) { (slot)->utag = tagChar; (slot)->uc = (val); } +inline void SetPtr(PyrSlot* slot, void* val) { (slot)->utag = tagPtr; (slot)->uptr = (void*)(val); } +inline void SetObjectOrNil(PyrSlot* slot, PyrObject* val) +{ + if (val) { + (slot)->utag = tagObj; + (slot)->uo = (val); + } else { + (slot)->utag = tagNil; + (slot)->ui = 0; + } +} + +inline void SetTrue(PyrSlot* slot) { (slot)->utag = tagTrue; (slot)->ui = 0; } +inline void SetFalse(PyrSlot* slot) { (slot)->utag = tagFalse; (slot)->ui = 0; } +inline void SetBool(PyrSlot* slot, bool test) { (slot)->utag = ((test) ? tagTrue : tagFalse); (slot)->ui = 0; } +inline void SetNil(PyrSlot* slot) { (slot)->utag = tagNil; (slot)->ui = 0; } +inline void SetInf(PyrSlot* slot) { (slot)->utag = tagInf; (slot)->ui = 0; } + +#if DOUBLESLOTS +inline void SetFloat(PyrSlot* slot, double val) { (slot)->uf = (val); } +#else +inline void SetFloat(PyrSlot* slot, double val) { (slot)->utag = s_float; (slot)->uf = (val); } +#endif + +inline bool IsObj(PyrSlot* slot) { return ((slot)->utag == tagObj); } +inline bool NotObj(PyrSlot* slot) { return ((slot)->utag != tagObj); } + +inline bool IsNil(PyrSlot* slot) { return ((slot)->utag == tagNil); } +inline bool NotNil(PyrSlot* slot) { return ((slot)->utag != tagNil); } + +inline bool IsFalse(PyrSlot* slot) { return ((slot)->utag == tagFalse); } +inline bool IsTrue(PyrSlot* slot) { return ((slot)->utag == tagTrue); } + +inline bool SlotEq(PyrSlot* a, PyrSlot* b) { return ((a)->ui == (b)->ui && (a)->utag == (b)->utag); } + +inline bool IsSym(PyrSlot* slot) { return ((slot)->utag == tagSym); } +inline bool NotSym(PyrSlot* slot) { return ((slot)->utag != tagSym); } + +inline bool IsInt(PyrSlot* slot) { return ((slot)->utag == tagInt); } +inline bool NotInt(PyrSlot* slot) { return ((slot)->utag != tagInt); } + +inline bool IsFloatTag(int tag) { return ((tag & 0xFFFFFFF0) != 0x7FF90000); } +inline bool IsFloat(PyrSlot* slot) { return (((slot)->utag & 0xFFFFFFF0) != 0x7FF90000); } +inline bool NotFloat(PyrSlot* slot) { return (((slot)->utag & 0xFFFFFFF0) == 0x7FF90000); } + +inline bool IsInf(PyrSlot* slot) { return ((slot)->utag == tagInf); } +inline bool IsPtr(PyrSlot* slot) { return ((slot)->utag == tagPtr); } + +inline bool IsFrame(PyrSlot* slot) { return ((slot)->utag == tagHFrame || (slot)->utag == tagSFrame); } + + +void dumpPyrSlot(PyrSlot* slot); +void slotString(PyrSlot *slot, char *str); +void slotOneWord(PyrSlot *slot, char *str); +bool postString(PyrSlot *slot, char *str); +char *slotSymString(PyrSlot* slot); +int asCompileString(PyrSlot *slot, char *str); + +int slotIntVal(PyrSlot* slot, int *value); +int slotFloatVal(PyrSlot* slot, float *value); +int slotDoubleVal(PyrSlot *slot, double *value); +int slotStrVal(PyrSlot *slot, char *str, int maxlen); +int slotPStrVal(PyrSlot *slot, unsigned char *str); +int slotSymbolVal(PyrSlot *slot, PyrSymbol **symbol); + +extern PyrSlot o_nil, o_true, o_false, o_inf; +extern PyrSlot o_pi, o_twopi; +extern PyrSlot o_fhalf, o_fnegone, o_fzero, o_fone, o_ftwo; +extern PyrSlot o_negtwo, o_negone, o_zero, o_one, o_two; +extern PyrSlot o_emptyarray, o_onenilarray, o_argnamethis; + +extern PyrSymbol *s_object; // "Object" +extern PyrSymbol *s_this; // "this" +extern PyrSymbol *s_super; // "super" + +inline int slotFloatVal(PyrSlot *slot, float *value) +{ + if (IsFloat(slot)) { + *value = slot->uf; + return errNone; + } else if (IsInt(slot)) { + *value = slot->ui; + return errNone; + } + return errWrongType; +} + +inline int slotIntVal(PyrSlot *slot, int *value) +{ + if (IsInt(slot)) { + *value = slot->ui; + return errNone; + } else if (IsFloat(slot)) { + *value = (int)slot->uf; + return errNone; + } + return errWrongType; +} + +inline int slotDoubleVal(PyrSlot *slot, double *value) +{ + if (IsFloat(slot)) { + *value = slot->uf; + return errNone; + } else if (IsInt(slot)) { + *value = slot->ui; + return errNone; + } + return errWrongType; +} + +inline int slotSymbolVal(PyrSlot *slot, PyrSymbol **symbol) +{ + if (!IsSym(slot)) return errWrongType; + *symbol = slot->us; + return errNone; +} + +inline void slotCopy(PyrSlot *dst, PyrSlot *src, int num) +{ + double *dstp = (double*)dst - 1; + double *srcp = (double*)src - 1; + for (int i=0;i +#include + +template +class SC_IOStream +{ +protected: + T s; +public: + SC_IOStream() : s(0) {} + SC_IOStream(T inStream) : s(inStream) {} + + void SetStream(T inStream) { s = inStream; } + T GetStream() { return s; } + + // core routines + void readData(char *data, int size); + uint8 readUInt8(); + + void writeData(char *data, int size); + void writeUInt8(uint8 inInt); + + // built using core routines + void writeInt8(int8 inInt) + { + writeUInt8((uint8)inInt); + } + + void writeInt16_be(int16 inInt) + { + writeUInt8((uint8)(inInt >> 8)); + writeUInt8(inInt); + } + + void writeInt16_le(int16 inInt) + { + writeUInt8((uint8)inInt); + writeUInt8((uint8)(inInt >> 8)); + } + + void writeInt32_be(int32 inInt) + { + writeUInt8((uint8)(inInt >> 24)); + writeUInt8((uint8)(inInt >> 16)); + writeUInt8((uint8)(inInt >> 8)); + writeUInt8((uint8)inInt); + } + + void writeInt32_le(int32 inInt) + { + writeUInt8((uint8)inInt); + writeUInt8((uint8)(inInt >> 8)); + writeUInt8((uint8)(inInt >> 16)); + writeUInt8((uint8)(inInt >> 24)); + } + +#if BYTE_ORDER == BIG_ENDIAN + void writeFloat_be(float inFloat) +#else + void writeFloat_le(float inFloat) +#endif + { + union { + float f; + uint8 c[4]; + } u; + u.f = inFloat; + writeUInt8(u.c[0]); + writeUInt8(u.c[1]); + writeUInt8(u.c[2]); + writeUInt8(u.c[3]); + } + +#if BYTE_ORDER == BIG_ENDIAN + void writeFloat_le(float inFloat) +#else + void writeFloat_be(float inFloat) +#endif + { + union { + float f; + uint8 c[4]; + } u; + u.f = inFloat; + writeUInt8(u.c[3]); + writeUInt8(u.c[2]); + writeUInt8(u.c[1]); + writeUInt8(u.c[0]); + } + + +#if BYTE_ORDER == BIG_ENDIAN + void writeDouble_be(double inDouble) +#else + void writeDouble_le(double inDouble) +#endif + { + union { + double f; + uint8 c[8]; + } u; + u.f = inDouble; + writeUInt8(u.c[0]); + writeUInt8(u.c[1]); + writeUInt8(u.c[2]); + writeUInt8(u.c[3]); + writeUInt8(u.c[4]); + writeUInt8(u.c[5]); + writeUInt8(u.c[6]); + writeUInt8(u.c[7]); + } + +#if BYTE_ORDER == BIG_ENDIAN + void writeDouble_le(double inDouble) +#else + void writeDouble_be(double inDouble) +#endif + { + union { + double f; + uint8 c[8]; + } u; + u.f = inDouble; + writeUInt8(u.c[7]); + writeUInt8(u.c[6]); + writeUInt8(u.c[5]); + writeUInt8(u.c[4]); + writeUInt8(u.c[3]); + writeUInt8(u.c[2]); + writeUInt8(u.c[1]); + writeUInt8(u.c[0]); + } + + + int8 readInt8() + { + return (int8)readUInt8(); + } + + int16 readInt16_be() + { + uint8 a = readUInt8(); + uint8 b = readUInt8(); + return (int16)((a << 8) | b); + } + + int16 readInt16_le() + { + uint8 a = readUInt8(); + uint8 b = readUInt8(); + return (int16)((b << 8) | a); + } + + int32 readInt32_be() + { + uint8 a = readUInt8(); + uint8 b = readUInt8(); + uint8 c = readUInt8(); + uint8 d = readUInt8(); + return (int32)((a << 24) | (b << 16) | (c << 8) | d); + } + + int32 readInt32_le() + { + uint8 a = readUInt8(); + uint8 b = readUInt8(); + uint8 c = readUInt8(); + uint8 d = readUInt8(); + return (int32)((d << 24) | (c << 16) | (b << 8) | a); + } + +#if BYTE_ORDER == BIG_ENDIAN + float readFloat_be() +#else + float readFloat_le() +#endif + { + union { + float f; + uint8 c[4]; + } u; + u.c[0] = readUInt8(); + u.c[1] = readUInt8(); + u.c[2] = readUInt8(); + u.c[3] = readUInt8(); + return u.f; + } + +#if BYTE_ORDER == BIG_ENDIAN + float readFloat_le() +#else + float readFloat_be() +#endif + { + union { + float f; + uint8 c[4]; + } u; + u.c[3] = readUInt8(); + u.c[2] = readUInt8(); + u.c[1] = readUInt8(); + u.c[0] = readUInt8(); + return u.f; + } + + +#if BYTE_ORDER == BIG_ENDIAN + double readDouble_be() +#else + double readDouble_le() +#endif + { + union { + double f; + uint8 c[8]; + } u; + u.c[0] = readUInt8(); + u.c[1] = readUInt8(); + u.c[2] = readUInt8(); + u.c[3] = readUInt8(); + u.c[4] = readUInt8(); + u.c[5] = readUInt8(); + u.c[6] = readUInt8(); + u.c[7] = readUInt8(); + return u.f; + } + +#if BYTE_ORDER == BIG_ENDIAN + double readDouble_le() +#else + double readDouble_be() +#endif + { + union { + double f; + uint8 c[8]; + } u; + u.c[7] = readUInt8(); + u.c[6] = readUInt8(); + u.c[5] = readUInt8(); + u.c[4] = readUInt8(); + u.c[3] = readUInt8(); + u.c[2] = readUInt8(); + u.c[1] = readUInt8(); + u.c[0] = readUInt8(); + return u.f; + } + + void readSymbol(char *outString) + { + int length = readUInt8(); + readData(outString, length); + outString[length] = 0; + } + + void writeSymbol(char *inString) + { + int32 length = strlen(inString); + writeUInt8((uint8)length); + writeData(inString, length); + } +}; + + +// core routines +inline void SC_IOStream::readData(char *data, int size) +{ + fread(data, 1, size, s); +} + +inline uint8 SC_IOStream::readUInt8() +{ + return (uint8)fgetc(s); +} + +inline void SC_IOStream::writeData(char *data, int size) +{ + fwrite(data, 1, size, s); +} + +inline void SC_IOStream::writeUInt8(uint8 inInt) +{ + fputc(inInt, s); +} + +// core routines +inline void SC_IOStream::readData(char *data, int size) +{ + memcpy(data, s, size); + s += size; +} +inline uint8 SC_IOStream::readUInt8() +{ + return (uint8)*s++; +} + +inline void SC_IOStream::writeData(char *data, int size) +{ + memcpy(s, data, size); + s += size; +} + +inline void SC_IOStream::writeUInt8(uint8 inInt) +{ + *s++ = (inInt & 255); +} + + +#endif + diff --git a/sc4pd/headers/lang/SCBase.h b/sc4pd/headers/lang/SCBase.h new file mode 100755 index 0000000..10fe0ed --- /dev/null +++ b/sc4pd/headers/lang/SCBase.h @@ -0,0 +1,68 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +Contains the most common definitions. + +*/ + +#ifndef _SCBASE_ +#define _SCBASE_ + +#include +#include + +#include "SC_BoundsMacros.h" +#include "SC_Types.h" +#include "PyrErrors.h" +#include "AllocPools.h" + +void postfl(const char *fmt, ...); +void post(const char *fmt, ...); +void error(const char *fmt, ...); +void postText(const char *text, long length); +void postChar(char c); +void flushPostBuf(); +void setPostFile(FILE *file); // If file is not NULL, causes all posted text to also be written to the file. + +void debugf(char *fmt, ...); +void pprintf(unsigned char *str, char *fmt, ...); + +#pragma export on + +extern "C" { +void schedInit(); +void init_OSC(int port); +bool pyr_init_mem_pools(int runtime_space, int runtime_grow); + +void schedRun(); +void schedStop(); +bool compileLibrary(); +void runLibrary(struct PyrSymbol* selector); +struct VMGlobals* scGlobals(); +void runInterpreter(struct VMGlobals *g, struct PyrSymbol *selector, int numArgsPushed); + +struct PyrSymbol* getsym(const char *inName); +struct PyrSymbol* findsym(const char *name); +} + +#pragma export off + +#endif diff --git a/sc4pd/headers/lang/SC_ComPort.h b/sc4pd/headers/lang/SC_ComPort.h new file mode 100755 index 0000000..bdbeabc --- /dev/null +++ b/sc4pd/headers/lang/SC_ComPort.h @@ -0,0 +1,118 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SC_ComPort_ +#define _SC_ComPort_ + +#include +#include +#include "SC_Msg.h" +#include "SC_Sem.h" + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class SC_CmdPort +{ +protected: + pthread_t mThread; + + void Start(); + virtual ReplyFunc GetReplyFunc()=0; +public: + SC_CmdPort(); + + virtual void* Run()=0; +}; + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class SC_ComPort : public SC_CmdPort +{ +protected: + int mPortNum; + int mSocket; + struct sockaddr_in mBindSockAddr; + +public: + SC_ComPort(int inPortNum); + virtual ~SC_ComPort(); + + int Socket() { return mSocket; } + + int PortNum() const { return mPortNum; } +}; + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class SC_UdpInPort : public SC_ComPort +{ +protected: + struct sockaddr_in mReplySockAddr; + virtual ReplyFunc GetReplyFunc(); + +public: + SC_UdpInPort(int inPortNum); + ~SC_UdpInPort(); + + int PortNum() const { return mPortNum; } + + void* Run(); +}; + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class SC_TcpInPort : public SC_ComPort +{ + SC_Semaphore mConnectionAvailable; + int mBacklog; + +protected: + virtual ReplyFunc GetReplyFunc(); + +public: + SC_TcpInPort(int inPortNum, int inMaxConnections, int inBacklog); + + virtual void* Run(); + + void ConnectionTerminated(); +}; + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class SC_TcpConnectionPort : public SC_ComPort +{ + SC_TcpInPort *mParent; + +protected: + virtual ReplyFunc GetReplyFunc(); + +public: + SC_TcpConnectionPort(SC_TcpInPort *inParent, int inSocket); + virtual ~SC_TcpConnectionPort(); + + virtual void* Run(); +}; + +const int kTextBufSize = 8192; + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#endif + diff --git a/sc4pd/headers/lang/SC_LanguageClient.h b/sc4pd/headers/lang/SC_LanguageClient.h new file mode 100644 index 0000000..b7a499c --- /dev/null +++ b/sc4pd/headers/lang/SC_LanguageClient.h @@ -0,0 +1,164 @@ +// emacs: -*- c++ -*- +// file: SC_LanguageClient.h +// copyright: 2003 stefan kersten +// cvs: $Id: SC_LanguageClient.h,v 1.1.1.1 2004-07-14 16:21:17 timblech Exp $ + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA + +#ifndef SC_LANGUAGECLIENT_H_INCLUDED +#define SC_LANGUAGECLIENT_H_INCLUDED + +#include "SC_StringBuffer.h" +#include +#include +#include + +// ===================================================================== +// SC_LanguageClient - abstract sclang client. +// ===================================================================== + +struct PyrSymbol; +struct VMGlobals; + +extern long compiledOK; +extern pthread_mutex_t gLangMutex; +extern VMGlobals* gMainVMGlobals; + +class SC_LanguageClient +{ +public: + struct Options + { + Options() + : mMemSpace(2*1024*1024), + mMemGrow(256*1024), + mPort(57120), + mRuntimeDir(0) + { } + + int mMemSpace; // memory space in bytes + int mMemGrow; // memory growth in bytes + int mPort; // network port number + char* mRuntimeDir; // runtime directory + }; + +public: + // create singleton instance + SC_LanguageClient(const char* name); + virtual ~SC_LanguageClient(); + + // return the singleton instance + static SC_LanguageClient* instance() { return gInstance; } + + // initialize language runtime + void initRuntime(const Options& opt=Options()); + + // return application name + const char* getName() const { return mName; } + + // library startup/shutdown + bool readLibraryConfig(const char* filePath, const char* fileName=0); + bool readDefaultLibraryConfig(); + bool isLibraryCompiled() { return compiledOK; } + void compileLibrary(); + void shutdownLibrary(); + void recompileLibrary(); + + // interpreter access + void lock() { pthread_mutex_lock(&gLangMutex); } + bool trylock() { return pthread_mutex_trylock(&gLangMutex) == 0; } + void unlock() { pthread_mutex_unlock(&gLangMutex); } + + VMGlobals* getVMGlobals() { return gMainVMGlobals; } + + void setCmdLine(const char* buf, size_t size); + void setCmdLine(const char* str); + void setCmdLine(const SC_StringBuffer& strBuf); + void setCmdLinef(const char* fmt, ...); + void runLibrary(PyrSymbol* pyrSymbol); + void runLibrary(const char* methodName); + void interpretCmdLine() { runLibrary(s_interpretCmdLine); } + void interpretPrintCmdLine() { runLibrary(s_interpretPrintCmdLine); } + void executeFile(const char* fileName); + void runMain() { runLibrary(s_run); } + void stopMain() { runLibrary(s_stop); } + + // post file access + FILE* getPostFile() { return mPostFile; } + void setPostFile(FILE* file) { mPostFile = file; } + + // post buffer output (subclass responsibility) + // these routines should be thread-save. + virtual void post(const char *fmt, va_list ap, bool error) = 0; + virtual void post(char c) = 0; + virtual void post(const char* str, size_t len) = 0; + virtual void flush() = 0; + + // common symbols + // only valid after the library has been compiled. + static PyrSymbol* s_interpretCmdLine; + static PyrSymbol* s_interpretPrintCmdLine; + static PyrSymbol* s_run; + static PyrSymbol* s_stop; + + // command line argument handling utilities + static void snprintMemArg(char* dst, size_t size, int arg); + static bool parseMemArg(const char* arg, int* res); + static bool parsePortArg(const char* arg, int* res); + +protected: + // AppClock driver + // to be called from client mainloop. + void tick(); + + // language notifications, subclasses can override + + // called after language runtime has been initialized + virtual void onInitRuntime(); + // called after the library has been compiled + virtual void onLibraryStartup(); + // called before the library is shut down + virtual void onLibraryShutdown(); + // called after the interpreter has been started + virtual void onInterpStartup(); + +private: + friend void closeAllGUIScreens(); + friend void initGUIPrimitives(); + friend void initGUI(); + +private: + char* mName; + FILE* mPostFile; + SC_StringBuffer mScratch; + bool mRunning; + static SC_LanguageClient* gInstance; +}; + +// ===================================================================== +// library functions +// ===================================================================== + +extern void setPostFile(FILE* file); +extern "C" int vpost(const char *fmt, va_list vargs); +extern void post(const char *fmt, ...); +extern void postfl(const char *fmt, ...); +extern void postText(const char *text, long length); +extern void postChar(char c); +extern void error(const char *fmt, ...); +extern void flushPostBuf(); + +#endif // SC_LANGUAGECLIENT_H_INCLUDED diff --git a/sc4pd/headers/lang/SC_LibraryConfig.h b/sc4pd/headers/lang/SC_LibraryConfig.h new file mode 100644 index 0000000..5f7df3b --- /dev/null +++ b/sc4pd/headers/lang/SC_LibraryConfig.h @@ -0,0 +1,108 @@ +// emacs: -*- c++ -*- +// file: SC_LibraryConfig.h +// cvs: $Id: SC_LibraryConfig.h,v 1.1.1.1 2004-07-14 16:21:24 timblech Exp $ + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA + +#ifndef SC_LIBRARYCONFIG_H_INCLUDED +#define SC_LIBRARYCONFIG_H_INCLUDED + +#include +#include + +// ===================================================================== +// SC_LibraryConfigFile +// simple library configuration file parser +// ===================================================================== + +class SC_LibraryConfig; + +class SC_LibraryConfigFile +{ +public: + typedef void (*ErrorFunc)(const char* fmt, ...); + +public: + SC_LibraryConfigFile(ErrorFunc errorFunc=0); + + bool open(const char* filePath); + bool read(const char* fileName, SC_LibraryConfig* libConf); + void close(); + +protected: + enum State + { + kBegin, + kAction, + kPath, + kEscape, + kEnvVar, + kEnvVarName, + kEnd + }; + + enum + { + kMaxIncludeDepth = 10 + }; + + bool read(int depth, const char* fileName, SC_LibraryConfig* libConf); + bool parseLine(int depth, const char* fileName, int lineNumber, const char* line, SC_LibraryConfig* libConf); + static void defaultErrorFunc(const char* fmt, ...); + +private: + ErrorFunc mErrorFunc; + FILE* mFile; +}; + +// ===================================================================== +// SC_LibraryConfig +// library configuration management +// Copyright 2003 Maurizio Umberto Puxeddu +// ===================================================================== + +class SC_LibraryConfig +{ +public: + SC_LibraryConfig(void); + virtual ~SC_LibraryConfig(); + + char **includedDirectories(void); + char **excludedDirectories(void); + + void postExcludedDirectories(void); + bool forEachIncludedDirectory(bool (*func)(char *, int)); + + bool pathIsExcluded(const char *path); + + void addIncludedDirectory(char *name); + void addExcludedDirectory(char *name); + + // convenience functions to access the global library config + static bool readLibraryConfig(SC_LibraryConfigFile& file, const char* fileName); + static void freeLibraryConfig(); + +private: + int m_nIncludedDirectories; + char **m_includedDirectories; + int m_nExcludedDirectories; + char **m_excludedDirectories; +}; + +extern SC_LibraryConfig* gLibraryConfig; +extern char *unixStandardizePath(const char *path, char *newpath); + +#endif // SC_LIBRARYCONFIG_H_INCLUDED diff --git a/sc4pd/headers/lang/SC_List.h b/sc4pd/headers/lang/SC_List.h new file mode 100755 index 0000000..1713521 --- /dev/null +++ b/sc4pd/headers/lang/SC_List.h @@ -0,0 +1,229 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* + +A doubly linked list template. + +*/ + +#ifndef _SC_List_ +#define _SC_List_ + +#include +#ifndef NDEBUG +# define NDEBUG +#endif +#include + + +// A Link can be a node in a list or a list itself. + +template +class Link +{ +public: + Link() : mNext(this), mPrev(this) {} + + T* Prev() { return static_cast(mPrev); } + T* Next() { return static_cast(mNext); } + + void RemoveLeaveDangling() + { + mPrev->mNext = mNext; + mNext->mPrev = mPrev; + } + + void Remove() + { + RemoveLeaveDangling(); + mNext = mPrev = this; + } + + void InsertAfter(T *inLink) + { + mPrev = inLink; + mNext = inLink->mNext; + mNext->mPrev = this; + mPrev->mNext = this; + } + + void InsertBefore(T *inLink) + { + mNext = inLink; + mPrev = inLink->mPrev; + mNext->mPrev = this; + mPrev->mNext = this; + } + + T* Head() { return static_cast(mNext); } + T* Tail() { return static_cast(mPrev); } + + T* PopHead(); + T* PopTail(); + void PushHead(T* inBuf); + void PushTail(T* inBuf); + + bool ContainsBuf(T* inBuf); + bool IsEmpty() { return mNext == this; } + void BeEmpty() { mNext = mPrev = this; } + + void Cat(T* inLink); + + bool SanityCheck(); + void DebugDump(); + +//private: +// Codewarrior refuses to inline Next() in some places.. + Link *mNext, *mPrev; +}; + +template +void MakeListEmpty(Link *inLink, Alloc* inAlloc) +{ + Link* link = inLink->mNext; + while (link != inLink) { + Link* nextlink = link->mNext; + // SC uses placement new extensively, so here we do a 'placement delete'. + // Using DestructSelf allows me to have either virtual + // or non virtual destructors in subclasses at the discretion of the subclass. + ((T*)(link))->DestructSelf(); + inAlloc->Free(static_cast(link)); + link = nextlink; + } + inLink->mNext = inLink->mPrev = inLink; +} + +template +void Link::PushHead(T* inLink) +{ + assert(SanityCheck()); + + Link* link = static_cast*>(inLink); + link->InsertAfter(static_cast(this)); + + assert(SanityCheck()); +} + +template +T* Link::PopHead() +{ + assert(SanityCheck()); + if (IsEmpty()) return 0; + + Link* link = mNext; + + link->Remove(); + + assert(SanityCheck()); + return static_cast(link); +} + +template +void Link::PushTail(T* inLink) +{ + assert(SanityCheck()); + + Link* link = static_cast*>(inLink); + link->InsertBefore(static_cast(this)); + + assert(SanityCheck()); +} + +template +T* Link::PopTail() +{ + assert(SanityCheck()); + if (IsEmpty()) return 0; + + Link* link = mPrev; + link->Remove(); + + assert(SanityCheck()); + return static_cast(link); +} + +template +void Link::Cat(T* inLink) +{ + assert(SanityCheck()); + + Link* link = static_cast*>(inLink); + + if (link->IsEmpty()) return; + if (IsEmpty()) { + mNext = link->mNext; + mPrev = link->mPrev; + link->mNext->mPrev = this; + link->mPrev->mNext = this; + } else { + link->mNext->mPrev = mPrev; + link->mPrev->mNext = this; + mPrev->mNext = link->mNext; + mPrev = link->mPrev; + } + link->mPrev = link; + link->mNext = link; + + assert(SanityCheck()); +} + +template +bool Link::ContainsBuf(T* inLink) +{ + Link* link = static_cast*>(inLink); + Link* curLink = mNext; + while (curLink != this) { + if (curLink == link) return true; + curLink = curLink->mNext; + } + return false; +} + +template +void Link::DebugDump() +{ + Link* link = mNext; + while (link != this) { + //post("Link-> %08X next %08X prev %08X\n", + // link, link->mNext, link->mPrev); + link = link->mNext; + } +} + +template +bool Link::SanityCheck() +{ + Link* link = mNext; + while (link != this) { + if (link->mPrev->mNext != link) { + throw std::runtime_error("Link: bad link <-,->"); + } + if (link->mNext->mPrev != link) { + throw std::runtime_error("Link: bad link ->,<-"); + } + link = link->mNext; + } + return true; +} + + + +#endif diff --git a/sc4pd/headers/lang/SC_LogFile.h b/sc4pd/headers/lang/SC_LogFile.h new file mode 100755 index 0000000..d94c4e2 --- /dev/null +++ b/sc4pd/headers/lang/SC_LogFile.h @@ -0,0 +1,29 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_LogFile_ +#define _SC_LogFile_ + +#include + +extern FILE *gLogFile; + +#endif diff --git a/sc4pd/headers/lang/SC_Msg.h b/sc4pd/headers/lang/SC_Msg.h new file mode 100755 index 0000000..b187f09 --- /dev/null +++ b/sc4pd/headers/lang/SC_Msg.h @@ -0,0 +1,70 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Msg_ +#define _SC_Msg_ + +#include +#include +#include +#include "sc_msg_iter.h" + +class SC_Msg; + +enum { // Handler IDs + kUnknownAction = 0, + kRealTimeAction = 1, + kNonRealTimeAction = 2, + kEitherTimeAction = 3 +}; + +typedef void (*ReplyFunc)(struct ReplyAddress *inReplyAddr, char* inBuf, int inSize); + +struct ReplyAddress +{ + struct sockaddr_in mSockAddr; + int mSockAddrLen; + int mSocket; + ReplyFunc mReplyFunc; +}; + +inline void SendReply(ReplyAddress *inReplyAddr, char* inBuf, int inSize) +{ + (inReplyAddr->mReplyFunc)(inReplyAddr, inBuf, inSize); +} + +void DumpReplyAddress(ReplyAddress *inReplyAddress); +int32 Hash(ReplyAddress *inReplyAddress); + +struct OSC_Packet +{ + char *mData; + int32 mSize; + bool mIsBundle; + + ReplyAddress mReplyAddr; +}; + +void FreeOSCPacket(OSC_Packet *inPacket); + +#endif + + diff --git a/sc4pd/headers/lang/SC_SynthImpl.h b/sc4pd/headers/lang/SC_SynthImpl.h new file mode 100755 index 0000000..88411b3 --- /dev/null +++ b/sc4pd/headers/lang/SC_SynthImpl.h @@ -0,0 +1,42 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_SynthImpl_ +#define _SC_SynthImpl_ + +#include "SC_Synth.h" +#include "SC_SynthDef.h" +#include "HashTable.h" +#include "SC_AllocPool.h" +#include "SC_UnorderedList.h" + +extern SynthInterfaceTable gSynthInterfaceTable; +void InitSynthInterfaceTable(); + +typedef void (*SetupInterfaceFunc)(SynthInterfaceTable*); + +const int kMaxSynths = 1024; +extern StaticHashTable gSynthTable; +extern AllocPool *gSynthAllocPool; + +extern float32 gSine[8193]; + +#endif \ No newline at end of file diff --git a/sc4pd/headers/lang/SC_TerminalClient.h b/sc4pd/headers/lang/SC_TerminalClient.h new file mode 100644 index 0000000..b0375d0 --- /dev/null +++ b/sc4pd/headers/lang/SC_TerminalClient.h @@ -0,0 +1,92 @@ +// emacs: -*- c++ -*- +// file: SC_TerminalClient.h +// copyright: 2003 stefan kersten +// cvs: $Id: SC_TerminalClient.h,v 1.1.1.1 2004-07-14 16:21:27 timblech Exp $ + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA + +#ifndef SC_TERMINALCLIENT_H_INCLUDED +#define SC_TERMINALCLIENT_H_INCLUDED + +#include "SC_LanguageClient.h" +#include "SC_StringBuffer.h" + +// ===================================================================== +// SC_TerminalClient - command line sclang client. +// ===================================================================== + +class SC_TerminalClient : public SC_LanguageClient +{ +public: + enum + { + kInterpretCmdLine = 0x1b, + kInterpretPrintCmdLine = 0x0c + }; + + struct Options : public SC_LanguageClient::Options + { + Options() + : mLibraryConfigFile(0), + mDaemon(false), + mCallRun(false), + mCallStop(false), + mArgc(0), mArgv(0) + { } + + char* mLibraryConfigFile; + bool mDaemon; + bool mCallRun; + bool mCallStop; + int mArgc; + char** mArgv; + }; + + SC_TerminalClient(const char* name); + + const Options& options() const { return mOptions; } + bool shouldBeRunning() const { return mShouldBeRunning; } + + int run(int argc, char** argv); + void quit(int code); + + virtual void post(const char *fmt, va_list ap, bool error); + virtual void post(char c); + virtual void post(const char* str, size_t len); + virtual void flush(); + +protected: + bool parseOptions(int& argc, char**& argv, Options& opt); + void printUsage(); + + // fd is assumed to be non-blocking + bool readCmdLine(int fd, SC_StringBuffer& cmdLine); + void interpretCmdLine(PyrSymbol* method, SC_StringBuffer& cmdLine); + + // subclasses should override + virtual void commandLoop(); + virtual void daemonLoop(); + + static int prExit(struct VMGlobals* g, int); + virtual void onLibraryStartup(); + +private: + bool mShouldBeRunning; + int mReturnCode; + Options mOptions; +}; + +#endif // SC_TERMINALCLIENT_H_INCLUDED diff --git a/sc4pd/headers/lang/SC_UnorderedList.h b/sc4pd/headers/lang/SC_UnorderedList.h new file mode 100755 index 0000000..37ce8d9 --- /dev/null +++ b/sc4pd/headers/lang/SC_UnorderedList.h @@ -0,0 +1,60 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_UnorderedList_ +#define _SC_UnorderedList_ + +template +class SC_UnorderedList +{ + T* mList[kMaxItems]; + unsigned int mSize; +public: + SC_UnorderedList() : mSize(0) {} + + unsigned int Size() const { return mSize; } + Synth* GetAt(unsigned int inIndex) + { + if (inIndex >= mSize) return 0; + return mList[inIndex]; + } + + void Add(T *inItem) + { + if (mSize < kMaxItems) { + mList[mSize] = inItem; + SetListIndex(inItem, mSize++); + } + } + + void Remove(T *inItem) + { + --mSize; + unsigned int index = GetListIndex(inItem); + if (index < mSize) { + mList[index] = mList[mSize]; + SetListIndex(mList[index], index); + } + } +}; + +#endif + diff --git a/sc4pd/headers/lang/SFHeaders.h b/sc4pd/headers/lang/SFHeaders.h new file mode 100755 index 0000000..0504b27 --- /dev/null +++ b/sc4pd/headers/lang/SFHeaders.h @@ -0,0 +1 @@ +/* SuperCollider real time audio synthesis system Copyright (c) 2002 James McCartney. All rights reserved. http://www.audiosynth.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _SFHeaders_ #define _SFHeaders_ #include "SCBase.h" #include "ReadWriteMacros.h" enum { unsupported_sound_file = -1, AIFF_sound_file, AIFC_sound_file, RIFF_sound_file, NeXT_sound_file, IRCAM_sound_file, SD2_sound_file, raw_sound_file }; enum { snd_unsupported = -1, snd_no_snd, snd_16_linear, snd_8_mulaw, snd_8_linear, snd_32_float, snd_32_linear, snd_8_alaw, snd_8_unsigned, snd_24_linear, snd_64_double, snd_16_linear_little_endian, snd_32_linear_little_endian, snd_32_float_little_endian, snd_64_double_little_endian, snd_16_unsigned, snd_16_unsigned_little_endian, snd_24_linear_little_endian, snd_32_vax_float, snd_12_linear, snd_12_linear_little_endian, snd_12_unsigned, snd_12_unsigned_little_endian }; class SFHeaderInfo { public: SFHeaderInfo(); bool WriteHeader(FILE *inFile); void SetPath(char *inPath); double SampleRate() { return mSampleRate; } void SetSampleRate(double inSampleRate) { mSampleRate = inSampleRate; } void SetFormat(int inHeaderFormat, int inSampleFormat, int inCreator); double Freq() { return mFreq; } uint8 LoNote() { return mLoNote; } uint8 HiNote() { return mHiNote; } uint8 LoVeloc() { return mLoVeloc; } uint8 HiVeloc() { return mHiVeloc; } uint8 NumChannels() { return mNumChannels; } int32 NumFramesInFile() { return mNumFramesInFile; } int makeSoundFileHeader(SC_IOStream& rw); int32 headerFileType(); int headerSize(); int sampleFormatSize(); void newSoundFilePath(); bool ReadSoundFileHeader(FILE *fp); int32 CalcFrameSize(); bool SetTypeCreator(); char mPath[256]; double mSampleRate; double mFreq; int32 mNumFramesInFile; int32 mDataOffset; int32 mCreator; void *mExtraStuff; int16 mGain; int8 mHeaderFormat; int8 mSampleFormat; uint8 mNumChannels; uint8 mLoNote, mHiNote, mLoVeloc, mHiVeloc; private: int make_AIFF_header(SC_IOStream& rw); int make_AIFC_header(SC_IOStream& rw); int make_RIFF_header(SC_IOStream& rw); int make_Next_header(SC_IOStream& rw); int make_IRCAM_header(SC_IOStream& rw); int sampleFormat_AIFF(); int sampleFormat_AIFC(); int sampleFormat_RIFF(); int sampleFormat_Next(); int sampleFormat_Next_inv(int inFormat); void writeCompressionFormat_AIFC(SC_IOStream& rw); bool read_AIFF_Header(SC_IOStream& rw); bool read_RIFF_Header(SC_IOStream& rw); bool read_Next_Header(SC_IOStream& rw); }; extern char gDefaultSoundFolder[256]; extern char gDefaultSoundFilePath[256]; int sampleFormatSize(int inSampleFormat); #endif \ No newline at end of file diff --git a/sc4pd/headers/lang/Samp.h b/sc4pd/headers/lang/Samp.h new file mode 100755 index 0000000..7593ba8 --- /dev/null +++ b/sc4pd/headers/lang/Samp.h @@ -0,0 +1,46 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* + +Samp is a typedef for the output sample type. +Should be defined to be either float or double. + +*/ + +#ifndef _Samp_ +#define _Samp_ + +#include "SC_Types.h" + +const long kSineSize = 8192; +const long kSineMask = kSineSize - 1; +const double kSinePhaseScale = kSineSize / (2.0 * 3.1415926535897932384626433832795); + +extern float32 gSine[kSineSize+1]; +extern float32 gPMSine[kSineSize+1]; +extern float32 gInvSine[kSineSize+1]; +extern float32 gSineWavetable[2*kSineSize]; + +void SignalAsWavetable(float32* signal, float32* wavetable, long inSize); +void WavetableAsSignal(float32* wavetable, float32* signal, long inSize); + +#endif + diff --git a/sc4pd/headers/lang/SimpleStack.h b/sc4pd/headers/lang/SimpleStack.h new file mode 100755 index 0000000..3313785 --- /dev/null +++ b/sc4pd/headers/lang/SimpleStack.h @@ -0,0 +1,32 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +typedef struct { + long *stak; + short num, maxsize; +} LongStack; + +void initLongStack(LongStack *self) ; +void freeLongStack(LongStack *self); +void growLongStack(LongStack *self); +void pushls(LongStack *self, long value); +long popls(LongStack *self); +int emptyls(LongStack *self); diff --git a/sc4pd/headers/lang/VMGlobals.h b/sc4pd/headers/lang/VMGlobals.h new file mode 100755 index 0000000..9b5f2e1 --- /dev/null +++ b/sc4pd/headers/lang/VMGlobals.h @@ -0,0 +1,94 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +Each virtual machine has a copy of VMGlobals, which contains the state of the virtual machine. + +*/ + +#ifndef _VMGLOBALS_H_ +#define _VMGLOBALS_H_ + +#include "PyrSlot.h" +#include "SC_AllocPool.h" +#include "SC_RGen.h" + +const int kNumProcesses = 1; +const int kMainProcessID = 0; + +typedef void (*FifoMsgFunc)(struct VMGlobals*, struct FifoMsg*); + +struct FifoMsg { + FifoMsg() : func(0), dataPtr(0) { dataWord[0] = dataWord[1] = 0; } + void Perform(struct VMGlobals* g); + void Free(struct VMGlobals* g); + + FifoMsgFunc func; + void* dataPtr; + long dataWord[2]; +}; + +struct VMGlobals { + VMGlobals(); + + // global context + class AllocPool *allocPool; + struct PyrProcess *process; + class SymbolTable *symbolTable; + class PyrGC *gc; // garbage collector for this process + PyrSlot *classvars; + bool canCallOS; + + // thread context + struct PyrThread *thread; + struct PyrMethod *method; + struct PyrBlock *block; + struct PyrFrame *frame; + struct PyrMethod *primitiveMethod; + unsigned char *ip; // current instruction pointer + PyrSlot *sp; // current stack ptr + PyrSlot *args; + PyrSlot receiver; // the receiver + PyrSlot result; + int numpop; // number of args to pop for primitive + long returnLevels; + long processID; + long primitiveIndex; + RGen *rgen; + + // scratch context + long execMethod; +} ; + +inline void FifoMsg::Perform(struct VMGlobals* g) + { + (func)(g, this); + } + +inline void FifoMsg::Free(struct VMGlobals* g) + { + g->allocPool->Free(dataPtr); + } + +extern VMGlobals gVMGlobals[kNumProcesses]; +extern VMGlobals *gMainVMGlobals; +extern VMGlobals *gCompilingVMGlobals; +#endif + diff --git a/sc4pd/headers/lang/bullet.h b/sc4pd/headers/lang/bullet.h new file mode 100755 index 0000000..463b062 --- /dev/null +++ b/sc4pd/headers/lang/bullet.h @@ -0,0 +1,7 @@ + +// this should be an outstanding character +// it is used in printing errors + +#define BULLET "¥" +#define BULLET_CHAR '¥' + diff --git a/sc4pd/headers/lang/libraryConfig.h b/sc4pd/headers/lang/libraryConfig.h new file mode 100644 index 0000000..b1f3844 --- /dev/null +++ b/sc4pd/headers/lang/libraryConfig.h @@ -0,0 +1,31 @@ +// Copyright 2003 Maurizio Umberto Puxeddu + +#ifndef _Supercollider_libraryConfig_h_ +#define _Supercollider_libraryConfig_h_ + +class LibraryConfig { + public: + LibraryConfig(void); + virtual ~LibraryConfig(); + + char **includedDirectories(void); + char **excludedDirectories(void); + + void postExcludedDirectories(void); + bool forEachIncludedDirectory(bool (*func)(char *, int)); + + bool pathIsExcluded(const char *path); + + void addIncludedDirectory(char *name); + void addExcludedDirectory(char *name); + + private: + int m_nIncludedDirectories; + char **m_includedDirectories; + int m_nExcludedDirectories; + char **m_excludedDirectories; +}; + +extern char *unixStandardizePath(const char *path, char *newpath); + +#endif // _Supercollider_libraryConfig_h_ diff --git a/sc4pd/headers/lang/readSamples.h b/sc4pd/headers/lang/readSamples.h new file mode 100755 index 0000000..835f975 --- /dev/null +++ b/sc4pd/headers/lang/readSamples.h @@ -0,0 +1 @@ +/* SuperCollider real time audio synthesis system Copyright (c) 2002 James McCartney. All rights reserved. http://www.audiosynth.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _readSamples_ #define _readSamples_ long readSamplesInterleaved(FILE* fp, float *out, long numSamplesToRead, long format); void convertSamplesIn(float **out, char *in, long numFramesToRead, long numChannels, long sampOffset, long format); float convertSamplesOut(float **in, char *buffer, int numFramesToWrite, int numChannels, long sampOffset, int format); void convertSamplesInInterleaved(float *out, char *buffer, long numSamplesToRead, long sampOffset, long format); float convertSamplesOutInterleaved(float *in, char *buffer, long numSampsToWrite, int format); #endif \ No newline at end of file diff --git a/sc4pd/headers/plugin_interface/Hash.h b/sc4pd/headers/plugin_interface/Hash.h new file mode 100755 index 0000000..e42eaf4 --- /dev/null +++ b/sc4pd/headers/plugin_interface/Hash.h @@ -0,0 +1,152 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _Hash_ +#define _Hash_ + +#include "SC_Types.h" +#include "SC_Endian.h" + +// These hash functions are among the best there are in terms of both speed and quality. +// A good hash function makes a lot of difference. +// I have not used Bob Jenkins own hash function because the keys I use are relatively short. + + +// hash function for a string +inline int32 Hash(const char *inKey) +{ + // the one-at-a-time hash. + // a very good hash function. ref: a web page by Bob Jenkins. + // http://www.burtleburtle.net/bob/hash/doobs.html + int32 hash = 0; + while (*inKey) { + hash += *inKey++; + hash += hash << 10; + hash ^= hash >> 6; + } + hash += hash << 3; + hash ^= hash >> 11; + hash += hash << 15; + return hash; +} + +// hash function for a string that also returns the length +inline int32 Hash(const char *inKey, int32 *outLength) +{ + // the one-at-a-time hash. + // a very good hash function. ref: a web page by Bob Jenkins. + const char *origKey = inKey; + int32 hash = 0; + while (*inKey) { + hash += *inKey++; + hash += hash << 10; + hash ^= hash >> 6; + } + hash += hash << 3; + hash ^= hash >> 11; + hash += hash << 15; + *outLength = inKey - origKey; + return hash; +} + +// hash function for an array of char +inline int32 Hash(const char *inKey, int32 inLength) +{ + // the one-at-a-time hash. + // a very good hash function. ref: a web page by Bob Jenkins. + int32 hash = 0; + for (int i=0; i> 6; + } + hash += hash << 3; + hash ^= hash >> 11; + hash += hash << 15; + return hash; +} + +// hash function for integers +inline int32 Hash(int32 inKey) +{ + // Thomas Wang's integer hash. + // http://www.concentric.net/~Ttwang/tech/inthash.htm + // a faster hash for integers. also very good. + uint32 hash = (uint32)inKey; + hash += ~(hash << 15); + hash ^= hash >> 10; + hash += hash << 3; + hash ^= hash >> 6; + hash += ~(hash << 11); + hash ^= hash >> 16; + return (int32)hash; +} + +inline int64 Hash64(int64 inKey) +{ + // Thomas Wang's 64 bit integer hash. + uint64 hash = (uint64)inKey; + hash += ~(hash << 32); + hash ^= (hash >> 22); + hash += ~(hash << 13); + hash ^= (hash >> 8); + hash += (hash << 3); + hash ^= (hash >> 15); + hash += ~(hash << 27); + hash ^= (hash >> 31); + return (int64)hash; +} + +inline int32 Hash(const int32 *inKey, int32 inLength) +{ + // one-at-a-time hashing of a string of int32's. + // uses Thomas Wang's integer hash for the combining step. + int32 hash = 0; + for (int i=0; i=0?(a) : -(a)) +#define sc_max(a,b) (((a) > (b)) ? (a) : (b)) +#define sc_min(a,b) (((a) < (b)) ? (a) : (b)) +#define sc_clip(x, lo, hi) ((x) > (hi) ? (hi) : ((x) < (lo) ? (lo) : (x))) + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_BufGen.h b/sc4pd/headers/plugin_interface/SC_BufGen.h new file mode 100644 index 0000000..9a275c1 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_BufGen.h @@ -0,0 +1,40 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _BufGen_ +#define _BufGen_ + +#include "SC_Types.h" + +typedef void (*BufGenFunc)(struct World *world, struct SndBuf *buf, struct sc_msg_iter *msg); + +struct BufGen +{ + int32 mBufGenName[kSCNameLen]; + int32 mHash; + + BufGenFunc mBufGenFunc; +}; + +extern "C" { +bool BufGen_Create(char *inName, BufGenFunc inFunc); +} + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_Constants.h b/sc4pd/headers/plugin_interface/SC_Constants.h new file mode 100755 index 0000000..b827cad --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_Constants.h @@ -0,0 +1,46 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SC_Constants_ +#define _SC_Constants_ + +#include + +#ifndef __FP__ +const double pi = acos(-1.); +#endif +const double pi2 = pi * .5; +const double pi32 = pi * 1.5; +const double twopi = pi * 2.; +const double rtwopi = 1. / twopi; +const double log001 = log(0.001); +const double log01 = log(0.01); +const double log1 = log(0.1); +const double rlog2 = 1./log(2.); +const double sqrt2 = sqrt(2.); +const double rsqrt2 = 1. / sqrt2; + +// used to truncate precision +const float truncFloat = (float)(3. * pow(2,22)); +const double truncDouble = 3. * pow(2,51); + +const float kBadValue = 1e20f; // used in the secant table for values very close to 1/0 + +#endif \ No newline at end of file diff --git a/sc4pd/headers/plugin_interface/SC_DemandUnit.h b/sc4pd/headers/plugin_interface/SC_DemandUnit.h new file mode 100644 index 0000000..6f273b3 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_DemandUnit.h @@ -0,0 +1,54 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SC_DemandUnit_ +#define _SC_DemandUnit_ + +#include "SC_Unit.h" +#include "SC_Wire.h" + +// demand rate unit support. + +inline bool IsDemandInput(Unit* unit, int index) +{ + Unit* fromUnit = unit->mInput[index]->mFromUnit; + return fromUnit && fromUnit->mCalcRate == calc_DemandRate; +} + +inline float DemandInput(Unit* unit, int index) +{ + Unit* fromUnit = unit->mInput[index]->mFromUnit; + if (fromUnit && fromUnit->mCalcRate == calc_DemandRate) + (fromUnit->mCalcFunc)(fromUnit, 1); + return IN0(index); +} + +inline void ResetInput(Unit* unit, int index) +{ + Unit* fromUnit = unit->mInput[index]->mFromUnit; + if (fromUnit && fromUnit->mCalcRate == calc_DemandRate) + (fromUnit->mCalcFunc)(fromUnit, 0); +} + +#define ISDEMANDINPUT(index) IsDemandInput(unit, (index)) +#define DEMANDINPUT(index) DemandInput(unit, (index)) +#define RESETINPUT(index) ResetInput(unit, (index)) + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_Dimension.h b/sc4pd/headers/plugin_interface/SC_Dimension.h new file mode 100644 index 0000000..923b283 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_Dimension.h @@ -0,0 +1,31 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SC_Dimension_ +#define _SC_Dimension_ + +struct SC_Dimension +{ + long mWidth, mHeight, mNumPixels; + float mXSlopeFactor, mYSlopeFactor; +}; +typedef struct SC_Dimension SC_Dimension; + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_FifoMsg.h b/sc4pd/headers/plugin_interface/SC_FifoMsg.h new file mode 100644 index 0000000..7d83e0a --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_FifoMsg.h @@ -0,0 +1,59 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _FifoMsg_ +#define _FifoMsg_ + +typedef void (*FifoMsgFunc)(struct FifoMsg*); + +struct FifoMsg +{ + FifoMsg() : mPerformFunc(0), mFreeFunc(0), mData(0), mWorld(0) {} + + void Set(struct World *inWorld, FifoMsgFunc inPerform, FifoMsgFunc inFree, void* inData); + void Perform(); + void Free(); + + FifoMsgFunc mPerformFunc; + FifoMsgFunc mFreeFunc; + void* mData; + struct World *mWorld; +}; + +inline void FifoMsg::Set(World *inWorld, FifoMsgFunc inPerform, FifoMsgFunc inFree, void* inData) +{ + mWorld = inWorld; + mPerformFunc = inPerform; + mFreeFunc = inFree; + mData = inData; +} + +inline void FifoMsg::Perform() +{ + if (mPerformFunc) (mPerformFunc)(this); +} + +inline void FifoMsg::Free() +{ + if (mFreeFunc) (mFreeFunc)(this); +} + +#endif + diff --git a/sc4pd/headers/plugin_interface/SC_Graph.h b/sc4pd/headers/plugin_interface/SC_Graph.h new file mode 100644 index 0000000..68d3d59 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_Graph.h @@ -0,0 +1,53 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SC_Graph_ +#define _SC_Graph_ + +#include "SC_Node.h" +#include "SC_Rate.h" +#include "SC_Dimension.h" + +struct Graph +{ + Node mNode; + + uint32 mNumWires; + struct Wire *mWire; + + uint32 mNumControls; + float *mControls; + float **mMapControls; + + uint32 mNumUnits; + struct Unit **mUnits; + + int mNumCalcUnits; + struct Unit **mCalcUnits; // excludes i-rate units. + + int mSampleOffset; + struct RGen* mRGen; + + struct Unit *mLocalAudioBusUnit; + struct Unit *mLocalControlBusUnit; +}; +typedef struct Graph Graph; + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_InlineBinaryOp.h b/sc4pd/headers/plugin_interface/SC_InlineBinaryOp.h new file mode 100755 index 0000000..2d9668b --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_InlineBinaryOp.h @@ -0,0 +1,574 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _BinaryOpUGen_ +#define _BinaryOpUGen_ + +#include "SC_BoundsMacros.h" +#include + +inline float sc_mod(float in, float hi) +{ + // avoid the divide if possible + const float lo = (float)0.; + if (in >= hi) { + in -= hi; + if (in < hi) return in; + } else if (in < lo) { + in += hi; + if (in >= lo) return in; + } else return in; + + if (hi == lo) return lo; + return in - hi*floor(in/hi); +} + +inline double sc_mod(double in, double hi) +{ + // avoid the divide if possible + const double lo = (double)0.; + if (in >= hi) { + in -= hi; + if (in < hi) return in; + } else if (in < lo) { + in += hi; + if (in >= lo) return in; + } else return in; + + if (hi == lo) return lo; + return in - hi*floor(in/hi); +} + +inline float sc_wrap(float in, float lo, float hi) +{ + float range; + // avoid the divide if possible + if (in >= hi) { + range = hi - lo; + in -= range; + if (in < hi) return in; + } else if (in < lo) { + range = hi - lo; + in += range; + if (in >= lo) return in; + } else return in; + + if (hi == lo) return lo; + return in - range * floor((in - lo)/range); +} + +inline double sc_wrap(double in, double lo, double hi) +{ + double range; + // avoid the divide if possible + if (in >= hi) { + range = hi - lo; + in -= range; + if (in < hi) return in; + } else if (in < lo) { + range = hi - lo; + in += range; + if (in >= lo) return in; + } else return in; + + if (hi == lo) return lo; + return in - range * floor((in - lo)/range); +} + +inline double sc_wrap(double in, double lo, double hi, double range) +{ + // avoid the divide if possible + if (in >= hi) { + in -= range; + if (in < hi) return in; + } else if (in < lo) { + in += range; + if (in >= lo) return in; + } else return in; + + if (hi == lo) return lo; + return in - range * floor((in - lo)/range); +} + +inline double sc_wrap(float in, float lo, float hi, float range) +{ + // avoid the divide if possible + if (in >= hi) { + in -= range; + if (in < hi) return in; + } else if (in < lo) { + in += range; + if (in >= lo) return in; + } else return in; + + if (hi == lo) return lo; + return in - range * floor((in - lo)/range); +} + +inline float sc_fold(float in, float lo, float hi) +{ + float x, c, range, range2; + x = in - lo; + + // avoid the divide if possible + if (in >= hi) { + in = hi + hi - in; + if (in >= lo) return in; + } else if (in < lo) { + in = lo + lo - in; + if (in < hi) return in; + } else return in; + + if (hi == lo) return lo; + // ok do the divide + range = hi - lo; + range2 = range + range; + c = x - range2 * floor(x / range2); + if (c>=range) c = range2 - c; + return c + lo; +} + +inline double sc_fold(double in, double lo, double hi) +{ + double x, c, range, range2; + x = in - lo; + + // avoid the divide if possible + if (in >= hi) { + in = hi + hi - in; + if (in >= lo) return in; + } else if (in < lo) { + in = lo + lo - in; + if (in < hi) return in; + } else return in; + + if (hi == lo) return lo; + // ok do the divide + range = hi - lo; + range2 = range + range; + c = x - range2 * floor(x / range2); + if (c>=range) c = range2 - c; + return c + lo; +} + +inline double sc_fold(float in, float lo, float hi, float range, float range2) +{ + float x, c; + x = in - lo; + + // avoid the divide if possible + if (in >= hi) { + in = hi + hi - in; + if (in >= lo) return in; + } else if (in < lo) { + in = lo + lo - in; + if (in < hi) return in; + } else return in; + + if (hi == lo) return lo; + // ok do the divide + c = x - range2 * floor(x / range2); + if (c>=range) c = range2 - c; + return c + lo; +} + +inline double sc_fold(double in, double lo, double hi, double range, double range2) +{ + double x, c; + x = in - lo; + + // avoid the divide if possible + if (in >= hi) { + in = hi + hi - in; + if (in >= lo) return in; + } else if (in < lo) { + in = lo + lo - in; + if (in < hi) return in; + } else return in; + + if (hi == lo) return lo; + // ok do the divide + c = x - range2 * floor(x / range2); + if (c>=range) c = range2 - c; + return c + lo; +} + +inline float sc_pow(float a, float b) +{ + return a >= 0.f ? pow(a, b) : -pow(-a, b); +} + +inline double sc_pow(double a, double b) +{ + return a >= 0.f ? pow(a, b) : -pow(-a, b); +} + +template +inline float sc_thresh(T a, T b) +{ + return a < b ? (T)0 : a; +} + +inline float sc_clip2(float a, float b) +{ + return sc_clip(a, -b, b); +} + +inline float sc_wrap2(float a, float b) +{ + return sc_wrap(a, -b, b); +} + +inline float sc_fold2(float a, float b) +{ + return sc_fold(a, -b, b); +} + +inline float sc_excess(float a, float b) +{ + return a - sc_clip(a, -b, b); +} + +inline float sc_round(float x, float quant) +{ + return quant==0. ? x : floor(x/quant + .5f) * quant; +} + +inline double sc_round(double x, double quant) +{ + return quant==0. ? x : floor(x/quant + .5) * quant; +} + +inline float sc_roundUp(float x, float quant) +{ + return quant==0. ? x : ceil(x/quant) * quant; +} + +inline double sc_roundUp(double x, double quant) +{ + return quant==0. ? x : ceil(x/quant) * quant; +} + +inline float sc_trunc(float x, float quant) +{ + return quant==0. ? x : floor(x/quant) * quant; +} + +inline double sc_trunc(double x, double quant) +{ + return quant==0. ? x : floor(x/quant) * quant; +} + +inline float sc_atan2(float a, float b) +{ + return atan2(a, b); +} + + +inline float sc_scaleneg(float a, float b) +{ + b = 0.5f * b + 0.5f; + return (fabs(a) - a) * b + a; +} + +inline float sc_amclip(float a, float b) +{ + return a * 0.5f * (b + fabs(b)); +} + +inline double sc_amclip(double a, double b) +{ + return a * 0.5 * (b + fabs(b)); +} + +const float kFSQRT2M1 = sqrt(2.) - 1.; +const double kDSQRT2M1 = sqrt(2.) - 1.; + +inline float sc_hypotx(float x, float y) +{ + float minxy; + + x = fabs(x); + y = fabs(y); + + minxy = sc_min(x,y); + + return x + y - kFSQRT2M1 * minxy; +} + +inline double sc_hypotx(double x, double y) +{ + double minxy; + + x = fabs(x); + y = fabs(y); + + minxy = sc_min(x,y); + + return x + y - kDSQRT2M1 * minxy; +} + +#pragma mark - + + +inline int sc_div(int a, int b) +{ + int c; + if (b) { + if (a<0) c = (a+1)/b - 1; + else c = a/b; + } else c = a; + return c; +} + +/* +inline int sc_mod(int a, int b) +{ + long c; + c = a % b; + if (c<0) c += b; + return c; +} +*/ + +inline int sc_mod(int in, int hi) +{ + // avoid the divide if possible + const int lo = 0; + if (in >= hi) { + in -= hi; + if (in < hi) return in; + } else if (in < lo) { + in += hi; + if (in >= lo) return in; + } else return in; + + if (hi == lo) return lo; + + int c; + c = in % hi; + if (c<0) c += hi; + return c; +} + +inline int sc_wrap(int in, int lo, int hi) +{ + return sc_mod(in - lo, hi - lo + 1) + lo; +} + +inline int sc_clip2(int a, int b) +{ + return sc_clip(a, -b, b); +} + +inline int sc_wrap2(int a, int b) +{ + return sc_wrap(a, -b, b); +} + +inline int sc_fold(int in, int lo, int hi) +{ + int b = hi - lo; + int b2 = b+b-2; + int c = sc_mod(in - lo, b2); + if (c>=b) c = b2-c; + return c + lo; +} + +inline int sc_fold2(int a, int b) +{ + return sc_fold(a, -b, b); +} + +inline int sc_excess(int a, int b) +{ + return a - sc_clip(a, -b, b); +} + +inline int sc_gcd(int u, int v) +{ + int t; + u = sc_abs(u); + v = sc_abs(v); + if (u <= 1 || v <= 1) return 1; + while (u>0) { + if (u> b; +} + +inline int sc_unsignedRightShift(int a, int b) +{ + return (uint32)a >> b; +} + +inline int sc_round(int x, int quant) +{ + return quant==0 ? x : sc_div(x + quant/2, quant) * quant; +} + + +inline int sc_roundUp(int x, int quant) +{ + return quant==0 ? x : sc_div(x + quant - 1, quant) * quant; +} + +inline int sc_trunc(int x, int quant) +{ + return quant==0 ? x : sc_div(x, quant) * quant; +} + +#pragma mark - + +#if 0 + +inline long sc_div(long a, long b) +{ + int c; + if (b) { + if (a<0) c = (a+1)/b - 1; + else c = a/b; + } else c = a; + return c; +} + + +inline long sc_clip2(long a, long b) +{ + return sc_clip(a, -b, b); +} + +inline long sc_wrap(long in, long lo, long hi) +{ + return sc_mod(in - lo, hi - lo + 1) + lo; +} + +inline long sc_wrap2(long a, long b) +{ + return sc_wrap(a, -b, b); +} + +inline long sc_fold(long in, long lo, long hi) +{ + long b = hi - lo; + long b2 = b+b-2; + long c = sc_mod(in - lo, b2); + if (c>=b) c = b2-c; + return c + lo; +} + +inline long sc_fold2(long a, long b) +{ + return sc_fold(a, -b, b); +} + +inline long sc_thresh(long a, long b) +{ + return a < b ? 0 : a; +} + +inline long sc_bitAnd(long a, long b) +{ + return a & b; +} + +inline long sc_bitOr(long a, long b) +{ + return a | b; +} + +inline long sc_leftShift(long a, long b) +{ + return a << b; +} + +inline long sc_rightShift(long a, long b) +{ + return a >> b; +} + +inline long sc_unsignedRightShift(long a, long b) +{ + return (unsigned long)a >> b; +} + +inline long sc_gcd(long u, long v) +{ + long t; + u = sc_abs(u); + v = sc_abs(v); + if (u <= 1 || v <= 1) return 1; + while (u>0) { + if (u= 0.f || x <= 0.f)); +} + +/////////////////////////////////////////////////////////////////////////////////////// + +// versions provided for float32 and float64 +// did not supply template because do not want to instantiate for integers. +// all constants explicitly cast to prevent PowerPC frsp instruction generation. + +/////////////////////////////////////////////////////////////////////////////////////// + +// this is a function for preventing pathological math operations in ugens. +// can be used at the end of a block to fix any recirculating filter values. +inline float32 zapgremlins(float32 x) +{ + float32 absx = fabs(x); + // very small numbers fail the first test, eliminating denormalized numbers + // (zero also fails the first test, but that is OK since it returns zero.) + // very large numbers fail the second test, eliminating infinities + // Not-a-Numbers fail both tests and are eliminated. + return (absx > (float32)1e-15 && absx < (float32)1e15) ? x : (float32)0.; +} + +inline float32 sc_log2(float32 x) +{ + return log(fabs(x)) * rlog2; +} + +inline float32 sc_log10(float32 x) +{ + return log10(fabs(x)); +} + +inline float32 sc_midicps(float32 note) +{ + return (float32)440. * pow((float32)2., (note - (float32)69.) * (float32)0.083333333333); +} + +inline float32 sc_cpsmidi(float32 freq) +{ + return sc_log2(freq * (float32)0.0022727272727) * (float32)12. + (float32)69.; +} + +inline float32 sc_midiratio(float32 midi) +{ + return pow((float32)2. , midi * (float32)0.083333333333); +} + +inline float32 sc_ratiomidi(float32 ratio) +{ + return (float32)12. * sc_log2(ratio); +} + +inline float32 sc_octcps(float32 note) +{ + return (float32)440. * pow((float32)2., note - (float32)4.75); +} + +inline float32 sc_cpsoct(float32 freq) +{ + return sc_log2(freq * (float32)0.0022727272727) + (float32)4.75; +} + +inline float32 sc_ampdb(float32 amp) +{ + return log10(amp) * (float32)20.; +} + +inline float32 sc_dbamp(float32 db) +{ + return pow((float32)10., db * (float32).05); +} + +inline float32 sc_squared(float32 x) +{ + return x * x; +} + +inline float32 sc_cubed(float32 x) +{ + return x * x * x; +} + +inline float32 sc_sqrt(float32 x) +{ + return x < (float32)0. ? -sqrt(-x) : sqrt(x); +} + + +inline float32 sc_hanwindow(float32 x) +{ + if (x < (float32)0. || x > (float32)1.) return (float32)0.; + return (float32)0.5 - (float32)0.5 * cos(x * twopi); +} + +inline float32 sc_welwindow(float32 x) +{ + if (x < (float32)0. || x > (float32)1.) return (float32)0.; + return sin(x * pi); +} + +inline float32 sc_triwindow(float32 x) +{ + if (x < (float32)0. || x > (float32)1.) return (float32)0.; + if (x < (float32)0.5) return (float32)2. * x; + else return (float32)-2. * x + (float32)2.; +} + +inline float32 sc_bitriwindow(float32 x) +{ + float32 ax = (float32)1. - fabs(x); + if (ax <= (float32)0.) return (float32)0.; + return ax; +} + +inline float32 sc_rectwindow(float32 x) +{ + if (x < (float32)0. || x > (float32)1.) return (float32)0.; + return (float32)1.; +} + +inline float32 sc_scurve(float32 x) +{ + if (x <= (float32)0.) return (float32)0.; + if (x >= (float32)1.) return (float32)1.; + return x * x * ((float32)3. - (float32)2. * x); +} + +inline float32 sc_scurve0(float32 x) +{ + // assumes that x is in range + return x * x * ((float32)3. - (float32)2. * x); +} + +inline float32 sc_ramp(float32 x) +{ + if (x <= (float32)0.) return (float32)0.; + if (x >= (float32)1.) return (float32)1.; + return x; +} + +inline float32 sc_distort(float32 x) +{ + return x / ((float32)1. + fabs(x)); +} + +inline float32 sc_softclip(float32 x) +{ + float32 absx = fabs(x); + if (absx <= (float32)0.5) return x; + else return (absx - (float32)0.25) / x; +} + +// Taylor expansion out to x**9/9! factored into multiply-adds +// from Phil Burk. +inline float32 taylorsin(float32 x) +{ + // valid range from -pi/2 to +3pi/2 + x = pi2 - fabs(pi2 - x); + float32 x2 = x * x; + return x*(x2*(x2*(x2*(x2*(1.0/362880.0) + - (1.0/5040.0)) + + (1.0/120.0)) + - (1.0/6.0)) + + 1.0); +} + +inline float32 sc_trunc(float32 x) +{ + // truncFloat is a number which causes a loss of precision of + // the fractional part. + // NOTE: this will only work if the FPU is set to round downward. + // That is NOT the default rounding mode. SC sets it to this mode. + float32 tmp1 = x + truncFloat; + float32 tmp2 = tmp1 - truncFloat; + return tmp2; +} + +inline float32 sc_frac(float32 x) +{ + return x - sc_trunc(x); +} + +inline float32 sc_lg3interp(float32 x1, float32 a, float32 b, float32 c, float32 d) +{ + // cubic lagrange interpolator + float32 x0 = x1 + 1.f; + float32 x2 = x1 - 1.f; + float32 x3 = x1 - 2.f; + + float32 x03 = x0 * x3 * 0.5f; + float32 x12 = x1 * x2 * 0.16666666666666667f; + + return x12 * (d * x0 - a * x3) + x03 * (b * x2 - c * x1); +} + +inline float32 sc_CalcFeedback(float32 delaytime, float32 decaytime) +{ + if (delaytime == 0.f) { + return 0.f; + } else if (decaytime > 0.f) { + return exp(log001 * delaytime / decaytime); + } else if (decaytime < 0.f) { + return -exp(log001 * delaytime / -decaytime); + } else { + return 0.f; + } +} + +inline float32 sc_wrap1(float32 x) +{ + if (x >= (float32) 1.) return x + (float32)-2.; + if (x < (float32)-1.) return x + (float32) 2.; + return x; +} + +inline float32 sc_fold1(float32 x) +{ + if (x >= (float32) 1.) return (float32) 2. - x; + if (x < (float32)-1.) return (float32)-2. - x; + return x; +} + + +/////////////////////////////////////////////////////////////////////////////////////// + +inline float64 zapgremlins(float64 x) +{ + float64 absx = fabs(x); + // very small numbers fail the first test, eliminating denormalized numbers + // (zero also fails the first test, but that is OK since it returns zero.) + // very large numbers fail the second test, eliminating infinities + // Not-a-Numbers fail both tests and are eliminated. + return (absx > (float64)1e-15 && absx < (float64)1e15) ? x : (float64)0.; +} + +inline float64 sc_log2(float64 x) +{ + return log(fabs(x)) * rlog2; +} + +inline float64 sc_log10(float64 x) +{ + return log10(fabs(x)); +} + +inline float64 sc_midicps(float64 note) +{ + return (float64)440. * pow((float64)2., (note - (float64)69.) * (float64)0.083333333333); +} + +inline float64 sc_cpsmidi(float64 freq) +{ + return sc_log2(freq * (float64)0.0022727272727) * (float64)12. + (float64)69.; +} + +inline float64 sc_midiratio(float64 midi) +{ + return pow((float64)2. , midi * (float64)0.083333333333); +} + +inline float64 sc_ratiomidi(float64 ratio) +{ + return (float64)12. * sc_log2(ratio); +} + +inline float64 sc_octcps(float64 note) +{ + return (float64)440. * pow((float64)2., note - (float64)4.75); +} + +inline float64 sc_cpsoct(float64 freq) +{ + return sc_log2(freq * (float64)0.0022727272727) + (float64)4.75; +} + +inline float64 sc_ampdb(float64 amp) +{ + return log10(amp) * (float64)20.; +} + +inline float64 sc_dbamp(float64 db) +{ + return pow((float64)10., db * (float64).05); +} + +inline float64 sc_squared(float64 x) +{ + return x * x; +} + +inline float64 sc_cubed(float64 x) +{ + return x * x * x; +} + +inline float64 sc_sqrt(float64 x) +{ + return x < (float64)0. ? -sqrt(-x) : sqrt(x); +} + +inline float64 sc_hanwindow(float64 x) +{ + if (x < (float64)0. || x > (float64)1.) return (float64)0.; + return (float64)0.5 - (float64)0.5 * cos(x * twopi); +} + +inline float64 sc_welwindow(float64 x) +{ + if (x < (float64)0. || x > (float64)1.) return (float64)0.; + return sin(x * pi); +} + +inline float64 sc_triwindow(float64 x) +{ + if (x < (float64)0. || x > (float64)1.) return (float64)0.; + if (x < (float64)0.5) return (float64)2. * x; + else return (float64)-2. * x + (float64)2.; +} + +inline float64 sc_bitriwindow(float64 x) +{ + float64 ax = fabs(x); + if (ax > (float64)1.) return (float64)0.; + return (float64)1. - ax; +} + +inline float64 sc_rectwindow(float64 x) +{ + if (x < (float64)0. || x > (float64)1.) return (float64)0.; + return (float64)1.; +} + +inline float64 sc_scurve(float64 x) +{ + if (x <= (float64)0.) return (float64)0.; + if (x >= (float64)1.) return (float64)1.; + return x * x * ((float64)3. - (float64)2. * x); +} + +inline float64 sc_scurve0(float64 x) +{ + // assumes that x is in range + return x * x * ((float64)3. - (float64)2. * x); +} + +inline float64 sc_ramp(float64 x) +{ + if (x <= (float64)0.) return (float64)0.; + if (x >= (float64)1.) return (float64)1.; + return x; +} + +inline float64 sc_distort(float64 x) +{ + return x / ((float64)1. + fabs(x)); +} + +inline float64 sc_softclip(float64 x) +{ + float64 absx = fabs(x); + if (absx <= (float64)0.5) return x; + else return (absx - (float64)0.25) / x; +} + +// Taylor expansion out to x**9/9! factored into multiply-adds +// from Phil Burk. +inline float64 taylorsin(float64 x) +{ + x = pi2 - fabs(pi2 - x); + float64 x2 = x * x; + return x*(x2*(x2*(x2*(x2*(1.0/362880.0) + - (1.0/5040.0)) + + (1.0/120.0)) + - (1.0/6.0)) + + 1.0); +} + +inline float64 sc_trunc(float64 x) +{ + // truncDouble is a number which causes a loss of precision of + // the fractional part. + // NOTE: this will only work if the FPU is set to round downward. + // That is NOT the default rounding mode. SC sets it to this mode. + float64 tmp1 = x + truncDouble; + float64 tmp2 = tmp1 - truncDouble; + return tmp2; +} + +inline float64 sc_frac(float64 x) +{ + return x - sc_trunc(x); +} + +inline float64 sc_wrap1(float64 x) +{ + if (x >= (float64) 1.) return x + (float64)-2.; + if (x < (float64)-1.) return x + (float64) 2.; + return x; +} + +inline float64 sc_fold1(float64 x) +{ + if (x >= (float64) 1.) return (float64) 2. - x; + if (x < (float64)-1.) return (float64)-2. - x; + return x; +} + +inline int32 sc_grayCode(int32 x) +{ + return x ^ (x >> 1); +} + + + +/////////////////////////////////////////////////////////////////////////////////////// + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_InterfaceTable.h b/sc4pd/headers/plugin_interface/SC_InterfaceTable.h new file mode 100644 index 0000000..20cb864 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_InterfaceTable.h @@ -0,0 +1,175 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SC_SynthInterfaceTable_ +#define _SC_SynthInterfaceTable_ + +#include "SC_Types.h" +#include "SC_SndBuf.h" +#include "SC_Unit.h" +#include "SC_BufGen.h" +#include "SC_FifoMsg.h" +#include + +struct World; + +typedef bool (*AsyncStageFn)(World *inWorld, void* cmdData); +typedef void (*AsyncFreeFn)(World *inWorld, void* cmdData); + +struct InterfaceTable +{ + unsigned int mSineSize; + float32 *mSineWavetable; + float32 *mSine; + float32 *mCosecant; + + // call printf for debugging. should not use in finished code. + int (*fPrint)(const char *fmt, ...); + + // get a seed for a random number generator + int32 (*fRanSeed)(); + + // define a unit def + bool (*fDefineUnit)(char *inUnitClassName, size_t inAllocSize, + UnitCtorFunc inCtor, UnitDtorFunc inDtor, uint32 inFlags); + + // define a command /cmd + bool (*fDefinePlugInCmd)(char *inCmdName, PlugInCmdFunc inFunc, void* inUserData); + + // define a command for a unit generator /u_cmd + bool (*fDefineUnitCmd)(char *inUnitClassName, char *inCmdName, UnitCmdFunc inFunc); + + // define a buf gen + bool (*fDefineBufGen)(char *inName, BufGenFunc inFunc); + + // clear all of the unit's outputs. + void (*fClearUnitOutputs)(Unit *inUnit, int inNumSamples); + + // non real time memory allocation + void* (*fNRTAlloc)(size_t inSize); + void* (*fNRTRealloc)(void *inPtr, size_t inSize); + void (*fNRTFree)(void *inPtr); + + // real time memory allocation + void* (*fRTAlloc)(World *inWorld, size_t inSize); + void* (*fRTRealloc)(World *inWorld, void *inPtr, size_t inSize); + void (*fRTFree)(World *inWorld, void *inPtr); + + // call to set a Node to run or not. + void (*fNodeRun)(struct Node* node, int run); + + // call to stop a Graph after the next buffer. + void (*fNodeEnd)(struct Node* graph); + + // send a trigger from a Node to clients + void (*fSendTrigger)(struct Node* inNode, int triggerID, float value); + + // sending messages between real time and non real time levels. + bool (*fSendMsgFromRT)(World *inWorld, struct FifoMsg& inMsg); + bool (*fSendMsgToRT)(World *inWorld, struct FifoMsg& inMsg); + + // libsndfile support + int (*fSndFileFormatInfoFromStrings)(SF_INFO *info, + const char *headerFormatString, const char *sampleFormatString); + + // get nodes by id + struct Node* (*fGetNode)(World *inWorld, int inID); + struct Graph* (*fGetGraph)(World *inWorld, int inID); + + void (*fNRTLock)(World *inWorld); + void (*fNRTUnlock)(World *inWorld); + + bool mAltivecAvailable; + + void (*fGroup_DeleteAll)(struct Group* group); + void (*fDoneAction)(int doneAction, struct Unit *unit); + + int (*fDoAsynchronousCommand) + ( + World *inWorld, + void* replyAddr, + const char* cmdName, + void *cmdData, + AsyncStageFn stage2, // stage2 is non real time + AsyncStageFn stage3, // stage3 is real time - completion msg performed if stage3 returns true + AsyncStageFn stage4, // stage4 is non real time - sends done if stage4 returns true + AsyncFreeFn cleanup, + int completionMsgSize, + void* completionMsgData + ); + + + // fBufAlloc should only be called within a BufGenFunc + int (*fBufAlloc)(SndBuf *inBuf, int inChannels, int inFrames, double inSampleRate); +}; +typedef struct InterfaceTable InterfaceTable; + +#define Print (*ft->fPrint) +#define RanSeed (*ft->fRanSeed) +#define NodeEnd (*ft->fNodeEnd) +#define NodeRun (*ft->fNodeRun) +#define DefineUnit (*ft->fDefineUnit) +#define DefinePlugInCmd (*ft->fDefinePlugInCmd) +#define DefineUnitCmd (*ft->fDefineUnitCmd) +#define DefineBufGen (*ft->fDefineBufGen) +#define ClearUnitOutputs (*ft->fClearUnitOutputs) +#define SendTrigger (*ft->fSendTrigger) +#define SendMsgFromRT (*ft->fSendMsgFromRT) +#define SendMsgToRT (*ft->fSendMsgToRT) +#define DoneAction (*ft->fDoneAction) + +#define NRTAlloc (*ft->fNRTAlloc) +#define NRTRealloc (*ft->fNRTRealloc) +#define NRTFree (*ft->fNRTFree) + +#define RTAlloc (*ft->fRTAlloc) +#define RTRealloc (*ft->fRTRealloc) +#define RTFree (*ft->fRTFree) + +#define SC_GetNode (*ft->fGetNode) +#define SC_GetGraph (*ft->fGetGraph) + +#define NRTLock (*ft->fNRTLock) +#define NRTUnlock (*ft->fNRTUnlock) + +#define BufAlloc (*ft->fBufAlloc) + +#define GroupDeleteAll (*ft->fGroup_DeleteAll) + +#define SndFileFormatInfoFromStrings (*ft->fSndFileFormatInfoFromStrings) + +#define DoAsynchronousCommand (*ft->fDoAsynchronousCommand) + +#define DefineSimpleUnit(name) \ + (*ft->fDefineUnit)(#name, sizeof(name), (UnitCtorFunc)&name##_Ctor, 0, 0); + +#define DefineDtorUnit(name) \ + (*ft->fDefineUnit)(#name, sizeof(name), (UnitCtorFunc)&name##_Ctor, \ + (UnitDtorFunc)&name##_Dtor, 0); + +#define DefineSimpleCantAliasUnit(name) \ + (*ft->fDefineUnit)(#name, sizeof(name), (UnitCtorFunc)&name##_Ctor, 0, kUnitDef_CantAliasInputsToOutputs); + +#define DefineDtorCantAliasUnit(name) \ + (*ft->fDefineUnit)(#name, sizeof(name), (UnitCtorFunc)&name##_Ctor, \ + (UnitDtorFunc)&name##_Dtor, kUnitDef_CantAliasInputsToOutputs); + + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_Node.h b/sc4pd/headers/plugin_interface/SC_Node.h new file mode 100644 index 0000000..36dd412 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_Node.h @@ -0,0 +1,48 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Node_ +#define _SC_Node_ + +#include "SC_Types.h" + +typedef void (*NodeCalcFunc)(struct Node *inNode); + +struct Node +{ + int32 mID; + int32 mHash; + + struct World *mWorld; + struct NodeDef *mDef; + NodeCalcFunc mCalcFunc; + + struct Node *mPrev, *mNext; + struct Group *mParent; + + int32 mIsGroup; +}; +typedef struct Node Node; + +enum { kNode_Go, kNode_End, kNode_On, kNode_Off, kNode_Move, kNode_Info }; + +#endif + diff --git a/sc4pd/headers/plugin_interface/SC_PlugIn.h b/sc4pd/headers/plugin_interface/SC_PlugIn.h new file mode 100644 index 0000000..4f01fd3 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_PlugIn.h @@ -0,0 +1,53 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#include "SC_World.h" +#include "SC_Graph.h" +#include "SC_Unit.h" +#include "SC_Wire.h" +#include "SC_InterfaceTable.h" +#include "Unroll.h" +#include "SC_InlineUnaryOp.h" +#include "SC_InlineBinaryOp.h" +#include "SC_BoundsMacros.h" +#include "SC_RGen.h" +#include "SC_DemandUnit.h" +#include "clz.h" +#include "sc_msg_iter.h" +#include "SC_Altivec.h" +#include + +#ifdef SC_WIN32 + +// temporarily override __attribute__ for (unused), later we'll remove it +#ifndef __GCC__ +#define __attribute__(x) +#endif + +// workaround for IN/OUT conflict with Win32 headers. see SC_Unit.h for details +#define IN SC_IN +#define OUT SC_OUT + +#ifdef _MSC_VER +#include +#endif //_MSC_VER + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_RGen.h b/sc4pd/headers/plugin_interface/SC_RGen.h new file mode 100755 index 0000000..c82142b --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_RGen.h @@ -0,0 +1,288 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +//----------------------------------------------------------------------------// +// Ran088: L'Ecuyer's 1996 three-component Tausworthe generator "taus88" +//----------------------------------------------------------------------------// +// +// Returns an integer random number uniformly distributed within [0,4294967295] +// +// The period length is approximately 2^88 (which is 3*10^26). +// This generator is very fast and passes all standard statistical tests. +// +// Reference: +// (1) P. L'Ecuyer, Maximally equidistributed combined Tausworthe generators, +// Mathematics of Computation, 65, 203-213 (1996), see Figure 4. +// (2) recommended in: +// P. L'Ecuyer, Random number generation, chapter 4 of the +// Handbook on Simulation, Ed. Jerry Banks, Wiley, 1997. +// +//----------------------------------------------------------------------------// + +//----------------------------------------------------------------------------// +// I chose this random number generator for the following reasons: +// fast. +// easier and faster to seed than other high quality rng's such as Mersenne Twister. +// the internal state is only 12 bytes. +// the period is long enough for music/audio. +// possible to code in altivec in future if needed. +// - James McCartney +//----------------------------------------------------------------------------// + +#ifndef _SC_RGen_ +#define _SC_RGen_ + +#include "SC_Endian.h" +#include "SC_Types.h" +#include "SC_BoundsMacros.h" +#include "Hash.h" +#include + +struct RGen +{ + void init(uint32 seed); + + uint32 trand(); + + int32 irand(int32 scale); + int32 irand2(int32 scale); + int32 ilinrand(int32 scale); + int32 ibilinrand(int32 scale); + + float fcoin(); + float frand(); + float frand2(); + float frand0(); + float frand8(); + double drand(); + double drand2(double scale); + double linrand(double scale); + double bilinrand(double scale); + double exprandrng(double lo, double hi); + double exprand(double scale); + double biexprand(double scale); + double sum3rand(double scale); + + uint32 s1, s2, s3; // random generator state +}; + +inline void RGen::init(uint32 seed) +{ + // humans tend to use small seeds - mess up the bits + seed = (uint32)Hash((int)seed); + + // initialize seeds using the given seed value taking care of + // the requirements. The constants below are arbitrary otherwise + s1 = 1243598713U ^ seed; if (s1 < 2) s1 = 1243598713U; + s2 = 3093459404U ^ seed; if (s2 < 8) s2 = 3093459404U; + s3 = 1821928721U ^ seed; if (s3 < 16) s3 = 1821928721U; +} + +inline uint32 trand( uint32& s1, uint32& s2, uint32& s3 ) +{ + // This function is provided for speed in inner loops where the + // state variables are loaded into registers. + // Thus updating the instance variables can + // be postponed until the end of the loop. + s1 = ((s1 & -2) << 12) ^ (((s1 << 13) ^ s1) >> 19); + s2 = ((s2 & -8) << 4) ^ (((s2 << 2) ^ s2) >> 25); + s3 = ((s3 & -16) << 17) ^ (((s3 << 3) ^ s3) >> 11); + return s1 ^ s2 ^ s3; +} + +inline uint32 RGen::trand() +{ + // generate a random 32 bit number + s1 = ((s1 & -2) << 12) ^ (((s1 << 13) ^ s1) >> 19); + s2 = ((s2 & -8) << 4) ^ (((s2 << 2) ^ s2) >> 25); + s3 = ((s3 & -16) << 17) ^ (((s3 << 3) ^ s3) >> 11); + return s1 ^ s2 ^ s3; +} + +inline double RGen::drand() +{ + // return a double from 0.0 to 0.999... +#if BYTE_ORDER == BIG_ENDIAN + union { struct { uint32 hi, lo; } i; double f; } du; +#else + union { struct { uint32 lo, hi; } i; double f; } du; +#endif + du.i.hi = 0x41300000; + du.i.lo = trand(); + return du.f - 1048576.; +} + +inline float RGen::frand() +{ + // return a float from 0.0 to 0.999... + union { uint32 i; float f; } u; // union for floating point conversion of result + u.i = 0x3F800000 | (trand() >> 9); + return u.f - 1.f; +} + +inline float RGen::frand0() +{ + // return a float from +1.0 to +1.999... + union { uint32 i; float f; } u; // union for floating point conversion of result + u.i = 0x3F800000 | (trand() >> 9); + return u.f; +} + +inline float RGen::frand2() +{ + // return a float from -1.0 to +0.999... + union { uint32 i; float f; } u; // union for floating point conversion of result + u.i = 0x40000000 | (trand() >> 9); + return u.f - 3.f; +} + +inline float RGen::frand8() +{ + // return a float from -0.125 to +0.124999... + union { uint32 i; float f; } u; // union for floating point conversion of result + u.i = 0x3E800000 | (trand() >> 9); + return u.f - 0.375f; +} + +inline float RGen::fcoin() +{ + // only return one of the two values -1.0 or +1.0 + union { uint32 i; float f; } u; // union for floating point conversion of result + u.i = 0x3E000000 | (0x80000000 & trand()); + return u.f; +} + +inline int32 RGen::irand(int32 scale) +{ + // return an int from 0 to scale - 1 + return (int32)floor(scale * drand()); +} + +inline int32 RGen::irand2(int32 scale) +{ + // return a int from -scale to +scale + return (int32)floor((2. * scale + 1.) * drand() - scale); +} + +inline int32 RGen::ilinrand(int32 scale) +{ + int32 a = irand(scale); + int32 b = irand(scale); + return sc_min(a,b); +} + +inline double RGen::linrand(double scale) +{ + double a = drand(); + double b = drand(); + return sc_min(a,b) * scale; +} + +inline int32 RGen::ibilinrand(int32 scale) +{ + int32 a = irand(scale); + int32 b = irand(scale); + return a - b; +} + +inline double RGen::bilinrand(double scale) +{ + double a = drand(); + double b = drand(); + return (a - b) * scale; +} + +inline double RGen::exprandrng(double lo, double hi) +{ + return lo * exp(log(hi / lo) * drand()); +} + +inline double RGen::exprand(double scale) +{ + double z; + while ((z = drand()) == 0.0) {} + return -log(z) * scale; +} + +inline double RGen::biexprand(double scale) +{ + double z; + while ((z = drand2(1.)) == 0.0 || z == -1.0) {} + if (z > 0.0) z = log(z); + else z = -log(-z); + return z * scale; +} + +inline double RGen::sum3rand(double scale) +{ + // larry polansky's poor man's gaussian generator + return (drand() + drand() + drand() - 1.5) * 0.666666667 * scale; +} + +inline double drand( uint32& s1, uint32& s2, uint32& s3 ) +{ + union { struct { uint32 hi, lo; } i; double f; } u; + u.i.hi = 0x41300000; + u.i.lo = trand(s1,s2,s3); + return u.f - 1048576.; +} + +inline float frand( uint32& s1, uint32& s2, uint32& s3 ) +{ + // return a float from 0.0 to 0.999... + union { uint32 i; float f; } u; + u.i = 0x3F800000 | (trand(s1,s2,s3) >> 9); + return u.f - 1.f; +} + +inline float frand0( uint32& s1, uint32& s2, uint32& s3 ) +{ + // return a float from +1.0 to +1.999... + union { uint32 i; float f; } u; + u.i = 0x3F800000 | (trand(s1,s2,s3) >> 9); + return u.f; +} + +inline float frand2( uint32& s1, uint32& s2, uint32& s3 ) +{ + // return a float from -1.0 to +0.999... + union { uint32 i; float f; } u; + u.i = 0x40000000 | (trand(s1,s2,s3) >> 9); + return u.f - 3.f; +} + +inline float frand8( uint32& s1, uint32& s2, uint32& s3 ) +{ + // return a float from -0.125 to +0.124999... + union { uint32 i; float f; } u; + u.i = 0x3E800000 | (trand(s1,s2,s3) >> 9); + return u.f - 0.375f; +} + +inline float fcoin( uint32& s1, uint32& s2, uint32& s3 ) +{ + // only return one of the two values -1.0 or +1.0 + union { uint32 i; float f; } u; + u.i = 0x3F800000 | (0x80000000 & trand(s1,s2,s3)); + return u.f; +} + +#endif + diff --git a/sc4pd/headers/plugin_interface/SC_Rate.h b/sc4pd/headers/plugin_interface/SC_Rate.h new file mode 100644 index 0000000..63c160d --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_Rate.h @@ -0,0 +1,42 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _Rate_ +#define _Rate_ + +enum { calc_ScalarRate, calc_BufRate, calc_FullRate, calc_DemandRate }; + +struct Rate +{ + double mSampleRate; // samples per second + double mSampleDur; // seconds per sample + double mBufDuration; // seconds per buffer + double mBufRate; // buffers per second + double mSlopeFactor; // 1. / NumSamples + double mRadiansPerSample; // 2pi / SampleRate + int mBufLength; // length of the buffer + // second order filter loops are often unrolled by 3 + int mFilterLoops, mFilterRemain; + double mFilterSlope; +}; +typedef struct Rate Rate; + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_SndBuf.h b/sc4pd/headers/plugin_interface/SC_SndBuf.h new file mode 100644 index 0000000..affd2b9 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_SndBuf.h @@ -0,0 +1,109 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SndBuf_ +#define _SndBuf_ + +#include +#include + +struct SndBuf +{ + double samplerate; + double sampledur; // = 1/ samplerate + float *data; + int channels; + int samples; + int frames; + int mask; // for delay lines + int mask1; // for interpolating oscillators. + int coord; // used by fft ugens + SNDFILE *sndfile; // used by disk i/o +}; +typedef struct SndBuf SndBuf; + +struct SndBufUpdates +{ + int reads; + int writes; +}; +typedef struct SndBufUpdates SndBufUpdates; + +enum { coord_None, coord_Complex, coord_Polar }; + + +inline float PhaseFrac(unsigned long inPhase) + { + union { unsigned long itemp; float ftemp; } u; + u.itemp = 0x3F800000 | (0x007FFF80 & ((inPhase)<<7)); + return u.ftemp - 1.f; + } + +inline float PhaseFrac1(unsigned long inPhase) + { + union { unsigned long itemp; float ftemp; } u; + u.itemp = 0x3F800000 | (0x007FFF80 & ((inPhase)<<7)); + return u.ftemp; + } + +inline float lookup(float *table, int32 phase, int32 mask) +{ + return table[(phase >> 16) & mask]; +} + + +#define xlobits 14 +#define xlobits1 13 + +inline float lookupi(float *table, uint32 phase, uint32 mask) +{ + float frac = PhaseFrac(phase); + float *tbl = table + ((phase >> 16) & mask); + float a = tbl[0]; + float b = tbl[1]; + return a + frac * (b - a); +} + +inline float lookupi2(float *table, uint32 phase, uint32 mask) +{ + float frac = PhaseFrac1(phase); + float *tbl = table + ((phase >> 16) & mask); + float a = tbl[0]; + float b = tbl[1]; + return a + frac * b; +} + +inline float lookupi1(float* table0, float* table1, uint32 pphase, int32 lomask) +{ + float pfrac = PhaseFrac1(pphase); + uint32 index = ((pphase >> xlobits1) & lomask); + float val1 = *(float*)((char*)table0 + index); + float val2 = *(float*)((char*)table1 + index); + return val1 + val2 * pfrac; +} + + +inline float lininterp(float x, float a, float b) +{ + return a + x * (b - a); +} + + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_Types.h b/sc4pd/headers/plugin_interface/SC_Types.h new file mode 100755 index 0000000..d635b07 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_Types.h @@ -0,0 +1,67 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SC_Types_ +#define _SC_Types_ + +#include + +typedef int SCErr; + +#ifdef SC_WIN32 +typedef __int64 int64; +typedef unsigned __int64 uint64; +#else +typedef long long int64; +typedef unsigned long long uint64; +#endif + +typedef int int32; +typedef unsigned int uint32; +#ifdef SC_DARWIN +typedef unsigned int ulong; +#endif + +typedef short int16; +typedef unsigned short uint16; + +typedef signed char int8; +typedef unsigned char uint8; + +typedef float float32; +typedef double float64; + +typedef union { + uint32 u; + int32 i; + float32 f; +} elem32; + +typedef union { + uint64 u; + int64 i; + float64 f; +} elem64; + +const unsigned int kSCNameLen = 8; +const unsigned int kSCNameByteLen = kSCNameLen * sizeof(int32); + +#endif + diff --git a/sc4pd/headers/plugin_interface/SC_Unit.h b/sc4pd/headers/plugin_interface/SC_Unit.h new file mode 100644 index 0000000..2ded017 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_Unit.h @@ -0,0 +1,101 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Unit_ +#define _SC_Unit_ + +#include "SC_Types.h" + +typedef void (*UnitCtorFunc)(struct Unit* inUnit); +typedef void (*UnitDtorFunc)(struct Unit* inUnit); + +typedef void (*UnitCalcFunc)(struct Unit *inThing, int inNumSamples); + +struct Unit +{ + struct World *mWorld; + struct UnitDef *mUnitDef; + struct Graph *mParent; + uint16 mNumInputs, mNumOutputs; + int16 mCalcRate; + int16 mSpecialIndex; // used by unary and binary ops + int16 mParentIndex; + int16 mDone; + + struct Wire **mInput, **mOutput; + struct Rate *mRate; + struct SC_Dimension *mDimension; + float **mInBuf, **mOutBuf; + + UnitCalcFunc mCalcFunc; + int mBufLength; +}; +typedef struct Unit Unit; + +enum { + kUnitDef_CantAliasInputsToOutputs = 1 +}; + +// easy macros, the unit variable must be named 'unit'. +#ifndef SC_WIN32 + +// These return float* pointers to input and output buffers. +#define IN(index) (unit->mInBuf[index]) +#define OUT(index) (unit->mOutBuf[index]) + +// These return a float value. Used for control rate inputs and outputs. +#define IN0(index) (IN(index)[0]) +#define OUT0(index) (OUT(index)[0]) + +#else + +// Win32 headers (included by C std library headers) define IN and OUT macros +// for their own purposes. To avoid problems we don't define IN and OUT here +// but define SC_IN and SC_OUT instead. Source files that use IN and OUT need +// to include definitions of IN, and OUT referencing SC_IN and SC_OUT after +// all headers have been included. +#define SC_IN(index) (unit->mInBuf[index]) +#define SC_OUT(index) (unit->mOutBuf[index]) +#define IN0(index) (SC_IN(index)[0]) +#define OUT0(index) (SC_OUT(index)[0]) + +#endif + +// get the rate of the input. +#define INRATE(index) (unit->mInput[index]->mCalcRate) + +// set the calculation function +#define SETCALC(func) (unit->mCalcFunc = (UnitCalcFunc)&func) + +// calculate a slope for control rate interpolation to audio rate. +#define CALCSLOPE(next,prev) ((next - prev) * unit->mRate->mSlopeFactor) + +// get useful values +#define SAMPLERATE (unit->mRate->mSampleRate) +#define SAMPLEDUR (unit->mRate->mSampleDur) +#define BUFLENGTH (unit->mBufLength) +#define BUFRATE (unit->mRate->mBufRate) +#define BUFDUR (unit->mRate->mBufDuration) + +typedef void (*UnitCmdFunc)(struct Unit *unit, struct sc_msg_iter *args); +typedef void (*PlugInCmdFunc)(World *inWorld, void* inUserData, struct sc_msg_iter *args, void *replyAddr); + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_Wire.h b/sc4pd/headers/plugin_interface/SC_Wire.h new file mode 100644 index 0000000..f2680ac --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_Wire.h @@ -0,0 +1,36 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Wire_ +#define _SC_Wire_ + +#include "SC_Types.h" + +struct Wire +{ + struct Unit *mFromUnit; + int32 mCalcRate; + float32 *mBuffer; + float32 mScalarValue; +}; +typedef struct Wire Wire; + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_World.h b/sc4pd/headers/plugin_interface/SC_World.h new file mode 100644 index 0000000..8586432 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_World.h @@ -0,0 +1,105 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_World_ +#define _SC_World_ + +#include "SC_Types.h" +#include "SC_Rate.h" +#include "SC_SndBuf.h" +#include "SC_RGen.h" +#include "SC_Lock.h" + +struct World +{ + // a pointer to private implementation, not available to plug-ins. + struct HiddenWorld *hw; + + // a pointer to the table of function pointers that implement the plug-ins' + // interface to the server. + struct InterfaceTable *ft; + + // data accessible to plug-ins : + double mSampleRate; + int mBufLength; + int mBufCounter; + + uint32 mNumAudioBusChannels; + uint32 mNumControlBusChannels; + uint32 mNumInputs; + uint32 mNumOutputs; + + // vector of samples for all audio busses + float *mAudioBus; + + // vector of samples for all control busses + float *mControlBus; + + // these tell if a buss has been written to during a control period + // if the value is equal to mBufCounter then the buss has been touched + // this control period. + int32 *mAudioBusTouched; + int32 *mControlBusTouched; + + uint32 mNumSndBufs; + SndBuf *mSndBufs; + SndBuf *mSndBufsNonRealTimeMirror; + SndBufUpdates *mSndBufUpdates; + + struct Group *mTopGroup; + + Rate mFullRate, mBufRate; + + uint32 mNumRGens; + RGen *mRGen; + + uint32 mNumUnits, mNumGraphs, mNumGroups; + int mSampleOffset; // offset in the buffer of current event time. + + SC_Lock* mNRTLock; + + uint32 mNumSharedControls; + float *mSharedControls; + + bool mRealTime; + bool mRunning; + int mDumpOSC; +}; + +extern "C" { + int scprintf(const char *fmt, ...); +} + +inline SndBuf* World_GetBuf(struct World *inWorld, uint32 index) +{ + if (index > inWorld->mNumSndBufs) index = 0; + return inWorld->mSndBufs + index; +} + +inline SndBuf* World_GetNRTBuf(struct World *inWorld, uint32 index) +{ + if (index > inWorld->mNumSndBufs) index = 0; + return inWorld->mSndBufsNonRealTimeMirror + index; +} + +typedef void (*LoadPlugInFunc)(struct InterfaceTable *); + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_WorldOptions.h b/sc4pd/headers/plugin_interface/SC_WorldOptions.h new file mode 100644 index 0000000..b04850f --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_WorldOptions.h @@ -0,0 +1,91 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_WorldOptions_ +#define _SC_WorldOptions_ + +#include +#include "SC_Types.h" + +typedef int (*PrintFunc)(const char *format, va_list ap); + +struct WorldOptions +{ + const char* mPassword; + uint32 mNumBuffers; + uint32 mMaxLogins; + uint32 mMaxNodes; + uint32 mMaxGraphDefs; + uint32 mMaxWireBufs; + uint32 mNumAudioBusChannels; + uint32 mNumInputBusChannels; + uint32 mNumOutputBusChannels; + uint32 mNumControlBusChannels; + uint32 mBufLength; + uint32 mRealTimeMemorySize; + + int mNumSharedControls; + float *mSharedControls; + + bool mRealTime; + + const char *mNonRealTimeCmdFilename; + const char *mNonRealTimeInputFilename; + const char *mNonRealTimeOutputFilename; + const char *mNonRealTimeOutputHeaderFormat; + const char *mNonRealTimeOutputSampleFormat; + + uint32 mPreferredSampleRate; + uint32 mNumRGens; + + uint32 mPreferredHardwareBufferFrameSize; + + uint32 mLoadGraphDefs; + +#ifdef SC_DARWIN + const char *mInputStreamsEnabled; + const char *mOutputStreamsEnabled; +#endif +}; + +const WorldOptions kDefaultWorldOptions = +{ + 0,1024,64,1024,1024,64,128,8,8,4096,64,8192, 0,0, 1, 0,0,0,0,0, 0, 64, 0, 1 +#ifdef SC_DARWIN + ,0,0 +#endif +}; + +#include "SC_Reply.h" + +extern "C" { + void SetPrintFunc(PrintFunc func); + struct World* World_New(WorldOptions *inOptions); + void World_OpenUDP(struct World *inWorld, int inPort); + void World_OpenTCP(struct World *inWorld, int inPort, int inMaxConnections, int inBacklog); + void World_WaitForQuit(struct World *inWorld); + bool World_SendPacket(struct World *inWorld, int inSize, char *inData, ReplyFunc inFunc); + int World_CopySndBuf(World *world, uint32 index, struct SndBuf *outBuf, bool onlyIfChanged, bool &didChange); + int scprintf(const char *fmt, ...); +} + +#endif + diff --git a/sc4pd/headers/plugin_interface/Unroll.h b/sc4pd/headers/plugin_interface/Unroll.h new file mode 100644 index 0000000..12ae864 --- /dev/null +++ b/sc4pd/headers/plugin_interface/Unroll.h @@ -0,0 +1,249 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* + +These macros allow one to write code which can be compiled optimally depending on +what loop constructs the compiler can best generate code. + +*/ + +#ifndef _Unroll_ +#define _Unroll_ + +#if 1 + +// loop type +#define FOR_IS_FASTER 1 +#define WHILE_IS_FASTER 0 +// indexing type +#define PREINCREMENT_IS_FASTER 1 +#define POSTINCREMENT_IS_FASTER 0 + +#else + +// loop type +#define FOR_IS_FASTER 1 +#define WHILE_IS_FASTER 0 +// indexing type +#define PREINCREMENT_IS_FASTER 0 +#define POSTINCREMENT_IS_FASTER 1 + +#endif + + +// LOOPING MACROS : + +#if FOR_IS_FASTER + +#define LOOP(length, stmt) for (int xxi=0; xxi<(length); ++xxi) { stmt; } + +#elif WHILE_IS_FASTER + +#define LOOP(length, stmt) \ + { int xxn = (length); \ + while (--xxn) { \ + stmt; \ + } \ + } + +#endif + + + +// above macros are not friendly to the debugger +#if FOR_IS_FASTER + +#define LooP(length) for (int xxi=0; xxi<(length); ++xxi) + +#elif WHILE_IS_FASTER + +#define LooP(length) for (int xxi=(length); --xxi;) + +#endif + + +// LOOP INDEXING : + +/* +meanings of the indexing macros: + ZXP = dereference and pre or post increment + ZX = dereference + PZ = preincrement (if applicable) + ZP = postincrement (if applicable) + ZOFF = offset from the pointer of the first element of the array + (preincrement requires a ZOFF of 1 which is pre-subtracted from the + base pointer. For other indexing types ZOFF is zero) +*/ + +#if PREINCREMENT_IS_FASTER +#define ZXP(z) (*++(z)) +#define ZX(z) (*(z)) +#define PZ(z) (++(z)) +#define ZP(z) (z) +#define ZOFF (1) +#elif POSTINCREMENT_IS_FASTER +#define ZXP(z) (*(z)++) +#define ZX(z) (*(z)) +#define PZ(z) (z) +#define ZP(z) ((z)++) +#define ZOFF (0) +#endif + +// ACCESSING INLETS AND OUTLETS : + +// unit inputs +#define ZIN(i) (IN(i) - ZOFF) // get buffer pointer offset for iteration +#define ZIN0(i) (IN(i)[0]) // get first sample + +// unit outputs +#define ZOUT(i) (OUT(i) - ZOFF) // get buffer pointer offset for iteration +#define ZOUT0(i) (OUT(i)[0]) // get first sample + +#include "SC_BoundsMacros.h" + +#ifndef NDEBUG +# define NDEBUG +#endif +#include + +inline void Clear(int numSamples, float *out) +{ + //assert((((long)(out+ZOFF) & 7) == 0)); // pointer must be 8 byte aligned + + if ((numSamples & 1) == 0) { + // copying doubles is faster on powerpc. + double *outd = (double*)out - ZOFF; + LOOP(numSamples >> 1, ZXP(outd) = 0.; ); + } else { + out -= ZOFF; + LOOP(numSamples, ZXP(out) = 0.f; ); + } +} + +inline void Copy(int numSamples, float *out, float *in) +{ + // pointers must be 8 byte aligned + //assert((((long)(out+ZOFF) & 7) == 0) && (((long)(in+ZOFF) & 7) == 0)); + if (in == out) return; + if ((numSamples & 1) == 0) { + // copying doubles is faster on powerpc. + double *outd = (double*)out - ZOFF; + double *ind = (double*)in - ZOFF; + LOOP(numSamples >> 1, ZXP(outd) = ZXP(ind); ); + } else { + in -= ZOFF; + out -= ZOFF; + LOOP(numSamples, ZXP(out) = ZXP(in); ); + } +} + +inline void Fill(int numSamples, float *out, float level) +{ + out -= ZOFF; + LOOP(numSamples, ZXP(out) = level; ); +} + +inline void Fill(int numSamples, float *out, float level, float slope) +{ + out -= ZOFF; + LOOP(numSamples, ZXP(out) = level; level += slope; ); +} + +inline void Accum(int numSamples, float *out, float *in) +{ + in -= ZOFF; + out -= ZOFF; + LOOP(numSamples, ZXP(out) += ZXP(in); ); +} + +inline void Scale(int numSamples, float *out, float level) +{ + out -= ZOFF; + LOOP(numSamples, ZXP(out) *= level;); +} + +inline float Scale(int numSamples, float *out, float level, float slope) +{ + out -= ZOFF; + LOOP(numSamples, ZXP(out) *= level; level += slope;); + return level; +} + +inline float Scale(int numSamples, float *out, float *in, float level, float slope) +{ + in -= ZOFF; + out -= ZOFF; + LOOP(numSamples, ZXP(out) = ZXP(in) * level; level += slope;); + return level; +} + +inline float ScaleMix(int numSamples, float *out, float *in, float level, float slope) +{ + in -= ZOFF; + out -= ZOFF; + LOOP(numSamples, ZXP(out) += ZXP(in) * level; level += slope;); + return level; +} + +inline void Scale(int numSamples, float *out, float *in, float level) +{ + in -= ZOFF; + out -= ZOFF; + LOOP(numSamples, ZXP(out) = ZXP(in) * level; ); +} + +// in these the pointers are assumed to already have been pre-offset. +inline void ZCopy(int numSamples, float *out, float *in) +{ + // pointers must be 8 byte aligned + //assert((((long)(out+ZOFF) & 7) == 0) && (((long)(in+ZOFF) & 7) == 0)); + if (in == out) return; + if ((numSamples & 1) == 0) { + // copying doubles is faster on powerpc. + double *outd = (double*)(out + ZOFF) - ZOFF; + double *ind = (double*)(in + ZOFF) - ZOFF; + LOOP(numSamples >> 1, ZXP(outd) = ZXP(ind); ); + } else { + LOOP(numSamples, ZXP(out) = ZXP(in); ); + } +} + +inline void ZClear(int numSamples, float *out) +{ + // pointers must be 8 byte aligned + //assert((((long)(out+ZOFF) & 7) == 0) && (((long)(in+ZOFF) & 7) == 0)); + if ((numSamples & 1) == 0) { + // copying doubles is faster on powerpc. + double *outd = (double*)(out + ZOFF) - ZOFF; + LOOP(numSamples >> 1, ZXP(outd) = 0.; ); + } else { + LOOP(numSamples, ZXP(out) = 0.f; ); + } +} + +inline void ZAccum(int numSamples, float *out, float *in) +{ + LOOP(numSamples, ZXP(out) += ZXP(in); ); +} + + + +#endif diff --git a/sc4pd/headers/plugin_interface/clz.h b/sc4pd/headers/plugin_interface/clz.h new file mode 100755 index 0000000..f205c02 --- /dev/null +++ b/sc4pd/headers/plugin_interface/clz.h @@ -0,0 +1,195 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +count leading zeroes function and those that can be derived from it + +*/ + + +#ifndef _CLZ_ +#define _CLZ_ + +#include "SC_Types.h" + +#ifdef __MWERKS__ + +#define __PPC__ 1 +#define __X86__ 0 + +// powerpc native count leading zeroes instruction: +#define CLZ(x) ((int)__cntlzw((unsigned int)x)) + +#elif defined(SC_WIN32) && !defined(__GCC__) + +static int32 CLZ( int32 arg ) +{ + __asm{ + bsr eax, arg + jnz non_zero + mov arg, 32 + jmp end +non_zero: + xor eax, 31 + mov arg, eax +end: + } + return arg; +} + +#elif defined(__ppc__) || defined(__powerpc__) || defined(__PPC__) + +static __inline__ int32 CLZ(int32 arg) { + __asm__ volatile("cntlzw %0, %1" : "=r" (arg) : "r" (arg)); + return arg; +} + +#elif defined(__i386__) || defined(__x86_64__) +static __inline__ int32 CLZ(int32 arg) { + if (arg) { + __asm__ volatile("bsrl %0, %0\nxorl $31, %0\n" + : "=r" (arg) : "0" (arg)); + } else { + arg = 32; + } + return arg; +} + +#else +# error "clz.h: Unsupported architecture" +#endif + +// count trailing zeroes +inline int32 CTZ(int32 x) +{ + return 32 - CLZ(~x & (x-1)); +} + +// count leading ones +inline int32 CLO(int32 x) +{ + return CLZ(~x); +} + +// count trailing ones +inline int32 CTO(int32 x) +{ + return 32 - CLZ(x & (~x-1)); +} + +// number of bits required to represent x. +inline int32 NUMBITS(int32 x) +{ + return 32 - CLZ(x); +} + +// log2 of the next power of two greater than or equal to x. +inline int32 LOG2CEIL(int32 x) +{ + return 32 - CLZ(x - 1); +} + +// next power of two greater than or equal to x +inline int32 NEXTPOWEROFTWO(int32 x) +{ + return 1L << LOG2CEIL(x); +} + +// is x a power of two +inline bool ISPOWEROFTWO(int32 x) +{ + return (x & (x-1)) == 0; +} + +// input a series of counting integers, outputs a series of gray codes . +inline int32 GRAYCODE(int32 x) +{ + return x & (x>>1); +} + +// find least significant bit +inline int32 LSBit(int32 x) +{ + return x & -x; +} + +// find least significant bit position +inline int32 LSBitPos(int32 x) +{ + return CTZ(x & -x); +} + +// find most significant bit position +inline int32 MSBitPos(int32 x) +{ + return 31 - CLZ(x); +} + +// find most significant bit +inline int32 MSBit(int32 x) +{ + return 1L << MSBitPos(x); +} + +// count number of one bits +inline uint32 ONES(uint32 x) +{ + uint32 t; + x = x - ((x >> 1) & 0x55555555); + t = ((x >> 2) & 0x33333333); + x = (x & 0x33333333) + t; + x = (x + (x >> 4)) & 0x0F0F0F0F; + x = x + (x << 8); + x = x + (x << 16); + return x >> 24; +} + +// count number of zero bits +inline uint32 ZEROES(uint32 x) +{ + return ONES(~x); +} + + +// reverse bits in a word +inline uint32 BitReverse(uint32 x) +{ + x = ((x & 0xAAAAAAAA) >> 1) | ((x & 0x55555555) << 1); + x = ((x & 0xCCCCCCCC) >> 2) | ((x & 0x33333333) << 2); + x = ((x & 0xF0F0F0F0) >> 4) | ((x & 0x0F0F0F0F) << 4); + x = ((x & 0xFF00FF00) >> 8) | ((x & 0x00FF00FF) << 8); + return (x >> 16) | (x << 16); +} + +// barrel shifts +inline uint32 RotateRight (uint32 x, uint32 s) +{ + s = s & 31; + return (x << (32-s)) | (x >> s); +} + +inline uint32 RotateLeft (uint32 x, uint32 s) +{ + s = s & 31; + return (x >> (32-s)) | (x << s); +} + +#endif + diff --git a/sc4pd/headers/plugin_interface/sc_msg_iter.h b/sc4pd/headers/plugin_interface/sc_msg_iter.h new file mode 100644 index 0000000..240a30f --- /dev/null +++ b/sc4pd/headers/plugin_interface/sc_msg_iter.h @@ -0,0 +1,264 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _sc_msg_iter_ +#define _sc_msg_iter_ + +#include "SC_Endian.h" +#include "SC_Types.h" +#include + +// return the ptr to the byte after the OSC string. +inline char* OSCstrskip(char *str) +{ +// while (str[3]) { str += 4; } +// return str + 4; + do { str += 4; } while (str[-1]); + return str; +} + +// returns the number of bytes (including padding) for an OSC string. +inline int OSCstrlen(char *strin) +{ + return OSCstrskip(strin) - strin; +} + +// returns a float, converting an int if necessary +inline float32 OSCfloat(char* inData) +{ + elem32* elem = (elem32*)inData; + elem->u = ntohl(elem->u); + return elem->f; +} + +inline int32 OSCint(char* inData) +{ + return (int32)ntohl(*(uint32*)inData); +} + +inline int64 OSCtime(char* inData) +{ + return ((int64)ntohl(*(uint32*)inData) << 32) + (ntohl(*(uint32*)(inData + 4))); +} + +inline float64 OSCdouble(char* inData) +{ + elem64 slot; + slot.i = ((int64)ntohl(*(uint32*)inData) << 32) + (ntohl(*(uint32*)(inData + 4))); + return slot.f; +} + +struct sc_msg_iter +{ + char *data, *rdpos, *endpos, *tags; + int size, count; + + sc_msg_iter(); + sc_msg_iter(int inSize, char* inData); + void init(int inSize, char* inData); + int32 geti(int32 defaultValue = 0); + float32 getf(float32 defaultValue = 0.f); + float64 getd(float64 defaultValue = 0.f); + char *gets(char* defaultValue = 0); + int32 *gets4(char* defaultValue = 0); + size_t getbsize(); + void getb(char* outData, size_t inSize); + void skipb(); + int remain() { return endpos - rdpos; } + + char nextTag(char defaultTag = 'f') { return tags ? tags[count] : defaultTag; } +}; + +inline sc_msg_iter::sc_msg_iter() +{ +} + +inline sc_msg_iter::sc_msg_iter(int inSize, char* inData) +{ + init(inSize, inData); +} + +inline void sc_msg_iter::init(int inSize, char* inData) +{ + data = inData; + size = inSize; + endpos = data + size; + count = 0; + if (data[0] == ',') { + tags = data+1; + rdpos = OSCstrskip(data); + } else { + tags = 0; + rdpos = data; + } +} + +inline int32 sc_msg_iter::geti(int32 defaultValue) +{ + int value; + if (remain() <= 0) return defaultValue; + if (tags) { + if (tags[count] == 'i') { + value = OSCint(rdpos); + rdpos += sizeof(int32); + } else if (tags[count] == 'f') { + value = (int32)OSCfloat(rdpos); + rdpos += sizeof(float32); +/* } else if (tags[count] == 's') { + value = atoi(rdpos); + rdpos = OSCstrskip(rdpos); +*/ + } else { + value = defaultValue; + } + } else { + value = (int)OSCint(rdpos); + rdpos += sizeof(int32); + } + count ++; + return value; +} + +inline float32 sc_msg_iter::getf(float32 defaultValue) +{ + float32 value; + if (remain() <= 0) return defaultValue; + if (tags) { + if (tags[count] == 'f') { + value = OSCfloat(rdpos); + rdpos += sizeof(float32); + } else if (tags[count] == 'd') { + value = (float64)OSCdouble(rdpos); + rdpos += sizeof(float64); + } else if (tags[count] == 'i') { + value = (float32)OSCint(rdpos); + rdpos += sizeof(int32); +/* } else if (tags[count] == 's') { + value = atof(rdpos); + rdpos = OSCstrskip(rdpos); +*/ + } else { + value = defaultValue; + } + } else { + value = OSCfloat(rdpos); + rdpos += sizeof(float32); + } + count ++; + return value; +} + +inline float64 sc_msg_iter::getd(float64 defaultValue) +{ + float64 value; + if (remain() <= 0) return defaultValue; + if (tags) { + if (tags[count] == 'f') { + value = (float64)OSCfloat(rdpos); + rdpos += sizeof(float32); + } else if (tags[count] == 'd') { + value = OSCdouble(rdpos); + rdpos += sizeof(float64); + } else if (tags[count] == 'i') { + value = (float64)OSCint(rdpos); + rdpos += sizeof(int32); +/* } else if (tags[count] == 's') { + value = atof(rdpos); + rdpos = OSCstrskip(rdpos); +*/ + } else { + value = defaultValue; + } + } else { + value = OSCdouble(rdpos); + rdpos += sizeof(float64); + } + count ++; + return value; +} + + +inline char* sc_msg_iter::gets(char* defaultValue) +{ + char* value; + if (remain() <= 0) return 0; + if (tags) { + if (tags[count] == 's') { + value = rdpos; + rdpos = OSCstrskip(rdpos); + } else { + value = defaultValue; + } + } else { + value = rdpos; + rdpos = OSCstrskip(rdpos); + } + count ++; + return value; +} + +inline int32* sc_msg_iter::gets4(char* defaultValue) +{ + int32* value; + if (remain() <= 0) return 0; + if (tags) { + if (tags[count] == 's') { + value = (int32*)rdpos; + rdpos = OSCstrskip(rdpos); + } else { + value = (int32*)defaultValue; + } + } else { + value = (int32*)rdpos; + rdpos = OSCstrskip(rdpos); + } + count ++; + return value; +} + +inline size_t sc_msg_iter::getbsize() +{ + if (remain() <= 0) return 0; + if (tags && tags[count] != 'b') return 0; + return (size_t)OSCint(rdpos); +} + +inline void sc_msg_iter::getb(char* outArray, size_t size) +{ + size_t len = OSCint(rdpos); + if (size < len) return; + rdpos += sizeof(int32); + size_t len4 = (len + 3) & -4; + memcpy(outArray, rdpos, size); + rdpos += len4; + count ++; +} + +inline void sc_msg_iter::skipb() +{ + size_t len = OSCint(rdpos); + rdpos += sizeof(int32); + size_t len4 = (len + 3) & -4; + rdpos += len4; + count ++; +} + +#endif diff --git a/sc4pd/headers/server/HashTable.h b/sc4pd/headers/server/HashTable.h new file mode 100755 index 0000000..85da92c --- /dev/null +++ b/sc4pd/headers/server/HashTable.h @@ -0,0 +1,356 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _HashTable_ +#define _HashTable_ + +#include "SC_Types.h" +#include "SC_BoundsMacros.h" +#include "SC_Str4.h" +#include "Hash.h" +#include +#include +#include + +template +class HashTable +{ + Allocator *mPool; + int32 mNumItems, mMaxItems, mTableSize, mHashMask; + T** mItems; + bool mCanResize; + +public: + + HashTable(Allocator *inPool, int32 inMaxItems, bool inCanResize = true) + : mPool(inPool) + { + mNumItems = 0; + mMaxItems = inMaxItems; + mTableSize = mMaxItems << 1; + mItems = AllocTable(mTableSize); + mHashMask = mTableSize - 1; + mCanResize = inCanResize; + } + + ~HashTable() { + mPool->Free(mItems); + } + + int32 TableSize() const { return mTableSize; } + int32 MaxItems() const { return mMaxItems; } + int32 NumItems() const { return mNumItems; } + + T** AllocTable(int inTableSize) + { + size_t size = inTableSize * sizeof(T*); + T** items = static_cast(mPool->Alloc(size)); + for (int i=0; i> 1; + mHashMask = mTableSize - 1; + mNumItems = 0; + for (int i=0; iFree(oldItems); + //printf("mMaxItems %d mTableSize %d newSize %d\n", mMaxItems, mTableSize, newSize); + } + + bool Add(T* inItem) + { + //printf("mNumItems %d\n", mNumItems); + //printf("mMaxItems %d\n", mMaxItems); + //printf("mCanResize %d\n", mCanResize); + if (mNumItems >= mMaxItems) { + if (!mCanResize) return false; + Resize(); + } + + //printf("GetHash(inItem) %d\n", GetHash(inItem)); + //printf("GetKey(inItem) %s\n", GetKey(inItem)); + int32 index = IndexFor(GetHash(inItem), (int32*)GetKey(inItem)); + //printf("index %d\n", index); + + T *item = mItems[index]; + if (item) return item == inItem; + + mItems[index] = inItem; + mNumItems++; + return true; + } + + bool Remove(T* inItem) + { + int32 index = IndexFor(GetHash(inItem), (int32*)GetKey(inItem)); + if (mItems[index] != inItem) return false; + mItems[index] = 0; + + FixCollisionsFrom(index); + mNumItems--; + return true; + } + + bool RemoveKey(int32* inKey) + { + T* item = Get(inKey); + if (!item) return false; + return Remove(item); + } + + int32 IndexFor(int32 inHashID, int32* inKey) const + { + int index = inHashID & mHashMask; + for(;;) { + T *item = mItems[index]; + if (!item) return index; + if (GetHash(item) == inHashID && str4eq(inKey, GetKey(item))) return index; + index = (index + 1) & mHashMask; + } + } + + T* Get(int32* inKey) const + { + return Get(Hash(inKey), inKey); + } + + T* Get(int32 inHashID, int32* inKey) const + { + //printf("Get hash %d %s\n", inHashID, inKey); + int32 index = IndexFor(inHashID, inKey); + //printf("index %d\n", index); + return mItems[index]; + } + + bool Includes(T* inItem) const + { + return Get(GetHash(inItem), GetKey(inItem)) == inItem; + } + + T* AtIndex(int32 inIndex) const + { + return mItems[inIndex]; + } + +private: + void FixCollisionsFrom(int32 inIndex) + { + int oldIndex = inIndex; + for (;;) { + oldIndex = (oldIndex + 1) & mHashMask; + T *oldItem = mItems[oldIndex]; + if (!oldItem) break; + int newIndex = IndexFor(GetHash(oldItem), (int32*)GetKey(oldItem)); + if (oldIndex != newIndex) { + mItems[oldIndex] = mItems[newIndex]; + mItems[newIndex] = oldItem; + } + } + } +}; + + +template +class IntHashTable +{ + Allocator *mPool; + int32 mNumItems, mMaxItems, mTableSize, mHashMask; + T** mItems; + bool mCanResize; + +public: + + IntHashTable(Allocator *inPool, int32 inMaxItems, bool inCanResize = true) + : mPool(inPool) + { + mNumItems = 0; + mMaxItems = inMaxItems; + mTableSize = mMaxItems << 1; + mItems = AllocTable(mTableSize); + mHashMask = mTableSize - 1; + mCanResize = inCanResize; + } + + ~IntHashTable() { + mPool->Free(mItems); + } + + int32 TableSize() const { return mTableSize; } + int32 MaxItems() const { return mMaxItems; } + int32 NumItems() const { return mNumItems; } + + T** AllocTable(int inTableSize) + { + size_t size = inTableSize * sizeof(T*); + T** items = static_cast(mPool->Alloc(size)); + for (int i=0; i> 1; + mHashMask = mTableSize - 1; + mPool->Free(oldItems); + //printf("mMaxItems %d mTableSize %d newSize %d\n", mMaxItems, mTableSize, newSize); + } + + bool Add(T* inItem) + { + //printf("mNumItems %d\n", mNumItems); + //printf("mMaxItems %d\n", mMaxItems); + //printf("mCanResize %d\n", mCanResize); + if (mNumItems >= mMaxItems) { + if (!mCanResize) return false; + Resize(); + } + + //printf("GetHash(inItem) %d\n", GetHash(inItem)); + //printf("GetKey(inItem) %d\n", GetKey(inItem)); + int32 index = IndexFor(GetHash(inItem), GetKey(inItem)); + //printf("index %d\n", index); + + T *item = mItems[index]; + if (item) return item == inItem; + + mItems[index] = inItem; + mNumItems++; + return true; + } + + bool Remove(T* inItem) + { + int32 index = IndexFor(GetHash(inItem), GetKey(inItem)); + //printf("rmv index %d hash %d key %d\n", index, GetHash(inItem), GetKey(inItem)); + if (mItems[index] != inItem) return false; + mItems[index] = 0; + + FixCollisionsFrom(index); + mNumItems--; + return true; + } + + bool RemoveKey(int32 inKey) + { + T* item = Get(inKey); + if (!item) return false; + return Remove(item); + } + + int32 IndexFor(int32 inHashID, int32 inKey) const + { + int index = inHashID & mHashMask; + for(;;) { + T *item = mItems[index]; + if (!item) return index; + if (GetHash(item) == inHashID && inKey == GetKey(item)) return index; + index = (index + 1) & mHashMask; + } + } + + T* Get(int32 inKey) const + { + //printf("Get key %d\n", inKey); + return Get(Hash(inKey), inKey); + } + + T* Get(int32 inHashID, int32 inKey) const + { + int32 index = IndexFor(inHashID, inKey); + //printf("Get index %d hash %d key %d\n", index, inHashID, inKey); + return mItems[index]; + } + + bool Includes(T* inItem) const + { + return Get(GetHash(inItem), GetKey(inItem)) == inItem; + } + + T* AtIndex(int32 inIndex) const + { + return mItems[inIndex]; + } + + void Dump() + { + for (int i=0; i +#endif + +template +class IntFifo +{ +public: + IntFifo() + : mMask(N - 1), mReadHead(0), mWriteHead(0) + {} + + void MakeEmpty() { mReadHead = mWriteHead; } + bool IsEmpty() { return mReadHead == mWriteHead; } + bool HasData() { return mReadHead != mWriteHead; } + + bool Put(int data) + { + long next = NextPos(mWriteHead); + if (next == mReadHead) return false; // fifo is full + mItems[next] = data; +#ifdef SC_DARWIN + // we don't really need a compare and swap, but this happens to call + // the PowerPC memory barrier instruction lwsync. + CompareAndSwap(mWriteHead, next, &mWriteHead); +#elif defined SC_WIN32 + InterlockedExchange(reinterpret_cast(&mWriteHead),next); +#else + mWriteHead = next; +#endif + return true; + } + + int32 Get() + { + //assert(HasData()); + long next = NextPos(mReadHead); + out = mItems[next].Perform(); +#ifdef SC_DARWIN + // we don't really need a compare and swap, but this happens to call + // the PowerPC memory barrier instruction lwsync. + CompareAndSwap(mReadHead, next, &mReadHead); +#elif defined SC_WIN32 + InterlockedExchange(reinterpret_cast(&mReadHead),next); +#else + mReadHead = next; +#endif + } + +private: + int NextPos(int inPos) { return (inPos + 1) & mMask; } + + long mMask; +#ifdef SC_DARWIN + UInt32 mReadHead, mWriteHead; +#else + volatile int mReadHead, mWriteHead; +#endif + int32 mItems[N]; +}; + +#endif + + diff --git a/sc4pd/headers/server/MsgFifo.h b/sc4pd/headers/server/MsgFifo.h new file mode 100755 index 0000000..cdc8578 --- /dev/null +++ b/sc4pd/headers/server/MsgFifo.h @@ -0,0 +1,169 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _MsgFifo_ +#define _MsgFifo_ + +#ifdef SC_DARWIN +# include +#endif + +///////////////////////////////////////////////////////////////////// + +template +class MsgFifo +{ +public: + MsgFifo() + : mReadHead(0), mWriteHead(0), mFreeHead(0) + {} + + void MakeEmpty() { mFreeHead = mReadHead = mWriteHead; } + bool IsEmpty() { return mReadHead == mWriteHead; } + bool HasData() { return mReadHead != mWriteHead; } + bool NeedsFree() { return mFreeHead != mReadHead; } + + bool Write(MsgType& data) + { + unsigned int next = NextPos(mWriteHead); + if (next == mFreeHead) return false; // fifo is full + mItems[next] = data; +#ifdef SC_DARWIN + // we don't really need a compare and swap, but this happens to call + // the PowerPC memory barrier instruction lwsync. + CompareAndSwap(mWriteHead, next, &mWriteHead); +#elif defined SC_WIN32 + InterlockedExchange(reinterpret_cast(&mWriteHead),next); +#else + mWriteHead = next; +#endif + return true; + } + + void Perform() // get next and advance + { + while (HasData()) { + unsigned int next = NextPos(mReadHead); + mItems[next].Perform(); +#ifdef SC_DARWIN + // we don't really need a compare and swap, but this happens to call + // the PowerPC memory barrier instruction lwsync. + CompareAndSwap(mReadHead, next, &mReadHead); +#elif defined SC_WIN32 + InterlockedExchange(reinterpret_cast(&mReadHead),next); +#else + mReadHead = next; +#endif + } + } + void Free() // reclaim messages + { + while (NeedsFree()) { + unsigned int next = NextPos(mFreeHead); + mItems[next].Free(); +#ifdef SC_DARWIN + // we don't really need a compare and swap, but this happens to call + // the PowerPC memory barrier instruction lwsync. + CompareAndSwap(mFreeHead, next, &mFreeHead); +#elif defined SC_WIN32 + InterlockedExchange(reinterpret_cast(&mFreeHead),next); +#else + mFreeHead = next; +#endif + } + } + +private: + int NextPos(int inPos) { return (inPos + 1) & (N - 1); } + +#ifdef SC_DARWIN + UInt32 mReadHead, mWriteHead, mFreeHead; +#else + volatile unsigned int mReadHead, mWriteHead, mFreeHead; +#endif + MsgType mItems[N]; +}; + +///////////////////////////////////////////////////////////////////// + +template +class MsgFifoNoFree +{ +public: + MsgFifoNoFree() + : mReadHead(0), mWriteHead(0) + { + } + + void MakeEmpty() { mReadHead = mWriteHead; } + bool IsEmpty() { return mReadHead == mWriteHead; } + bool HasData() { return mReadHead != mWriteHead; } + + bool Write(MsgType& data) + { + unsigned int next = NextPos(mWriteHead); + if (next == mReadHead) return false; // fifo is full + mItems[next] = data; +#ifdef SC_DARWIN + // we don't really need a compare and swap, but this happens to call + // the PowerPC memory barrier instruction lwsync. + CompareAndSwap(mWriteHead, next, &mWriteHead); +#elif defined SC_WIN32 + InterlockedExchange(reinterpret_cast(&mWriteHead),next); +#else + mWriteHead = next; +#endif + return true; + } + + void Perform() // get next and advance + { + while (HasData()) { + unsigned int next = NextPos(mReadHead); + mItems[next].Perform(); +#ifdef SC_DARWIN + // we don't really need a compare and swap, but this happens to call + // the PowerPC memory barrier instruction lwsync. + CompareAndSwap(mReadHead, next, &mReadHead); +#elif defined SC_WIN32 + InterlockedExchange(reinterpret_cast(&mReadHead),next); +#else + mReadHead = next; +#endif + } + } + +private: + int NextPos(int inPos) { return (inPos + 1) & (N - 1); } + +#ifdef SC_DARWIN + UInt32 mReadHead, mWriteHead; +#else + volatile unsigned int mReadHead, mWriteHead; +#endif + MsgType mItems[N]; +}; + +///////////////////////////////////////////////////////////////////// + + +#endif + + diff --git a/sc4pd/headers/server/OSC_Packet.h b/sc4pd/headers/server/OSC_Packet.h new file mode 100644 index 0000000..5964e81 --- /dev/null +++ b/sc4pd/headers/server/OSC_Packet.h @@ -0,0 +1,43 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + * OSC_Packet.h + * SC3synth + * + * Created by James McCartney on Sat Aug 24 2002. + * Copyright (c) 2001 __MyCompanyName__. All rights reserved. + * + */ + +#ifndef _OSC_Packet_ +#define _OSC_Packet_ + +#include "SC_Reply.h" + +struct OSC_Packet +{ + char *mData; + int32 mSize; + bool mIsBundle; + + ReplyAddress mReplyAddr; +}; + +#endif diff --git a/sc4pd/headers/server/PriorityQueue.h b/sc4pd/headers/server/PriorityQueue.h new file mode 100755 index 0000000..eb1064f --- /dev/null +++ b/sc4pd/headers/server/PriorityQueue.h @@ -0,0 +1,123 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _PriorityQueue_ +#define _PriorityQueue_ + +#include +#include +#include + +#define SANITYCHECK 0 + +#ifdef SC_WIN32 +const int64 kMaxInt64 = 0x7FFFFFFFFFFFFFFF; +#else +const int64 kMaxInt64 = ~(1LL<<63); +#endif + +template +class PriorityQueueT +{ +public: + PriorityQueueT() { + Empty(); + } + + bool Add(Event& inEvent) + { + if (mSize >= N) return false; + long mom = mSize++; + long me = mom; + for (; mom>0;) { /* percolate up heap */ + mom = mom - 1 >> 1; + if (inEvent.mTime < mEvents[mom].mTime) { + mEvents[me] = mEvents[mom]; + me = mom; + } else break; + } + mEvents[me] = inEvent; +#if SANITYCHECK + SanityCheck(); +#endif + return true; + } + void Perform(int64 inTime) + { + while (NextTime() <= inTime) { + Event event = Remove(); + event.Perform(); + } + } + int64 NextTime() { return mEvents[0].mTime; } + bool Ready(int64 inTime) { return NextTime() <= inTime; } + void Flush() { Perform(kMaxInt64); } + void Empty() { mSize = 0; SetEmptyTime(); } + void SetEmptyTime() { mEvents[0].mTime = kMaxInt64; } + int Size() { return mSize; } + + Event Remove() + { + Event event = mEvents[0]; + if (--mSize == 0) SetEmptyTime(); + else { + Event temp = mEvents[mSize]; + long mom = 0; + long me = 1; + for (;me < mSize;) { /* demote heap */ + if (me+1 < mSize && mEvents[me].mTime > mEvents[me+1].mTime) { + me ++; + } + if (temp.mTime > mEvents[me].mTime) { + mEvents[mom] = mEvents[me]; + mom = me; + me = (me << 1) + 1; + } else break; + } + mEvents[mom] = temp; + } +#if SANITYCHECK + SanityCheck(); +#endif + return event; + } + void SanityCheck() + { + for (int i=0; i mEvents[j].mTime) throw std::runtime_error("priority queue unsorted"); + //if (k mEvents[k].mTime) throw std::runtime_error("priority queue unsorted"); + } + } + void DebugDump() + { + for (int i=0; i +#include + +inline void writeData(char *&buf, char *data, int size) +{ + memcpy(buf, data, size); + buf += size; +} + +inline void writeZero(char *&buf, int len) +{ + for (int i=0; i> 8) & 255); + *buf++ = (char)(inInt & 255); +} + +inline void writeInt16_le(char *&buf, int16 inInt) +{ + *buf++ = (char)(inInt & 255); + *buf++ = (char)((inInt >> 8) & 255); +} + +inline void writeInt32_be(char *&buf, int32 inInt) +{ + *buf++ = (char)((inInt >> 24) & 255); + *buf++ = (char)((inInt >> 16) & 255); + *buf++ = (char)((inInt >> 8) & 255); + *buf++ = (char)(inInt & 255); +} + +inline void writeInt32_le(char *&buf, int32 inInt) +{ + *buf++ = (char)(inInt & 255); + *buf++ = (char)((inInt >> 8) & 255); + *buf++ = (char)((inInt >> 16) & 255); + *buf++ = (char)((inInt >> 24) & 255); +} + +inline void writeSymbol(char *&buf, char *inString) +{ + size_t length = strlen(inString); + writeUInt8(buf, (uint8)length); + memcpy(buf, inString, length); + buf += length; +} + +inline void writeString(char *&buf, char *inString, size_t inLength) +{ + writeInt32_be(buf, inLength); + memcpy(buf, inString, inLength); + buf += inLength; +} + +inline void writeString(char *&buf, char *inString) +{ + size_t length = strlen(inString); + writeString(buf, inString, length); +} + + + +inline void writeData(FILE *file, char *data, size_t size) +{ + fwrite(data, 1, size, file); +} + +inline void writeInt8(FILE *file, int8 inInt) +{ + fputc(inInt & 255, file); +} + +inline void writeUInt8(FILE *file, uint8 inInt) +{ + fputc(inInt & 255, file); +} + +inline void writeInt16_be(FILE *file, int16 inInt) +{ + fputc((inInt >> 8) & 255, file); + fputc(inInt & 255, file); +} + +inline void writeInt16_le(FILE *file, int16 inInt) +{ + fputc(inInt & 255, file); + fputc((inInt >> 8) & 255, file); +} + +inline void writeInt32_be(FILE *file, int32 inInt) +{ + fputc((inInt >> 24) & 255, file); + fputc((inInt >> 16) & 255, file); + fputc((inInt >> 8) & 255, file); + fputc(inInt & 255, file); +} + +inline void writeInt64_be(FILE *file, int64 inInt) +{ + writeInt32_be(file, (int32)((inInt >> 32) & 0x00000000FFFFFFFF)); + writeInt32_be(file, (int32)(inInt)); +} + +inline void writeInt32_le(FILE *file, int32 inInt) +{ + fputc(inInt & 255, file); + fputc((inInt >> 8) & 255, file); + fputc((inInt >> 16) & 255, file); + fputc((inInt >> 24) & 255, file); +} + +inline void writeFloat_be(FILE *file, float inFloat) +{ + union { + float f; + int32 i; + } u; + u.f = inFloat; + writeInt32_be(file, u.i); +} + +inline void writeFloat_le(FILE *file, float inFloat) +{ + union { + float f; + int32 i; + } u; + u.f = inFloat; + writeInt32_le(file, u.i); +} + +inline void writeSymbol(FILE *file, char *inString) +{ + size_t length = strlen(inString); + writeUInt8(file, (uint8)length); + fwrite(inString, 1, length, file); +} + +inline void writeString(FILE *file, char *inString, size_t inLength) +{ + writeInt32_be(file, inLength); + fwrite(inString, 1, inLength, file); +} + +inline void writeString(FILE *file, char *inString) +{ + size_t length = strlen(inString); + writeString(file, inString, length); +} + +inline int32 readInt8(FILE *file) +{ + int32 res = fgetc(file); + + return res; +} + +inline uint32 readUInt8(FILE *file) +{ + uint32 res = (uint32)fgetc(file); + return res; +} + +inline int32 readInt16_be(FILE *file) +{ + int32 c = fgetc(file); + int32 d = fgetc(file); + + int32 res = ((c & 255) << 8) | (d & 255); + return res; +} + +inline int32 readInt16_le(FILE *file) +{ + int32 c = fgetc(file); + int32 d = fgetc(file); + + int32 res = ((d & 255) << 8) | (c & 255); + return res; +} + +inline int32 readInt32_be(FILE *file) +{ + int32 a = fgetc(file); + int32 b = fgetc(file); + int32 c = fgetc(file); + int32 d = fgetc(file); + + int32 res = ((a & 255) << 24) | ((b & 255) << 16) | ((c & 255) << 8) | (d & 255); + return res; +} + +inline int32 readInt32_le(FILE *file) +{ + int32 a = fgetc(file); + int32 b = fgetc(file); + int32 c = fgetc(file); + int32 d = fgetc(file); + + int32 res = ((d & 255) << 24) | ((c & 255) << 16) | ((b & 255) << 8) | (a & 255); + return res; +} + +inline int64 readInt64_be(FILE *file) +{ + int64 hi = readInt32_be(file); + int64 lo = readInt32_be(file); + return (hi << 32) | (lo & 0x00000000FFFFFFFF); +} + +inline float readFloat_be(FILE *file) +{ + union { + float f; + int32 i; + } u; + u.i = readInt32_be(file); + //post("readFloat %g\n", u.f); + return u.f; +} + +inline float readFloat_le(FILE *file) +{ + union { + float f; + int32 i; + } u; + u.i = readInt32_le(file); + //post("readFloat %g\n", u.f); + return u.f; +} + +inline void readString(FILE *file, char *outString, size_t inLength) +{ + fread(outString, 1, inLength, file); + outString[inLength] = 0; +} + +inline void readSymbol(FILE *file, char *outString) +{ + size_t length = (size_t)readUInt8(file); + readString(file, outString, length); +} + +inline void readData(FILE *file, char *outData, size_t inLength) +{ + fread(outData, 1, inLength, file); +} + + +inline int32 readInt8(char *&buf) +{ + int32 res = *buf++; + return res; +} + +inline uint32 readUInt8(char *&buf) +{ + uint32 res = *buf++; + return res; +} + +inline int32 readInt16_be(char *&buf) +{ + int32 c = readInt8(buf); + int32 d = readInt8(buf); + + int32 res = ((c & 255) << 8) | (d & 255); + return res; +} + +inline int32 readInt16_le(char *&buf) +{ + int32 c = readInt8(buf); + int32 d = readInt8(buf); + + int32 res = ((d & 255) << 8) | (c & 255); + return res; +} + + +inline int32 readInt32_be(char *&buf) +{ + int32 a = readInt8(buf); + int32 b = readInt8(buf); + int32 c = readInt8(buf); + int32 d = readInt8(buf); + + int32 res = ((a & 255) << 24) | ((b & 255) << 16) | ((c & 255) << 8) | (d & 255); + return res; +} + +inline int32 readInt32_le(char *&buf) +{ + int32 a = readInt8(buf); + int32 b = readInt8(buf); + int32 c = readInt8(buf); + int32 d = readInt8(buf); + + int32 res = ((d & 255) << 24) | ((c & 255) << 16) | ((b & 255) << 8) | (a & 255); + return res; +} + +inline float readFloat_be(char *&buf) +{ + union { + float f; + int32 i; + } u; + u.i = readInt32_be(buf); + //post("readFloat %g\n", u.f); + return u.f; +} + +inline float readFloat_le(char *&buf) +{ + union { + float f; + int32 i; + } u; + u.i = readInt32_le(buf); + //post("readFloat %g\n", u.f); + return u.f; +} + +inline double readDouble_be(char *&buf) +{ + //post("readDouble\n"); + union { + double f; + uint8 c[8]; + } u; + + u.c[0] = (uint8)readInt8(buf); + u.c[1] = (uint8)readInt8(buf); + u.c[2] = (uint8)readInt8(buf); + u.c[3] = (uint8)readInt8(buf); + u.c[4] = (uint8)readInt8(buf); + u.c[5] = (uint8)readInt8(buf); + u.c[6] = (uint8)readInt8(buf); + u.c[7] = (uint8)readInt8(buf); + //post("readDouble %g %08X %08X\n", u.f, u.f); + return u.f; +} + +inline double readDouble_le(char *&buf) +{ + //post("readDouble\n"); + union { + double f; + uint8 c[8]; + } u; + + u.c[7] = (uint8)readInt8(buf); + u.c[6] = (uint8)readInt8(buf); + u.c[5] = (uint8)readInt8(buf); + u.c[4] = (uint8)readInt8(buf); + u.c[3] = (uint8)readInt8(buf); + u.c[2] = (uint8)readInt8(buf); + u.c[1] = (uint8)readInt8(buf); + u.c[0] = (uint8)readInt8(buf); + + //post("readDouble %g\n", u.f); + return u.f; +} + +inline void readString(char *&buf, char *outString, size_t inLength) +{ + memcpy(outString, buf, inLength); + outString[inLength] = 0; + buf += inLength; +} + +inline void readSymbol(char *&buf, char *outString) +{ + size_t length = (size_t)readUInt8(buf); + readString(buf, outString, length); +} + +inline void readData(char *&buf, char *outData, size_t inLength) +{ + memcpy(outData, buf, inLength); + buf += inLength; +} + + +#endif \ No newline at end of file diff --git a/sc4pd/headers/server/Rendezvous.h b/sc4pd/headers/server/Rendezvous.h new file mode 100644 index 0000000..2067cd2 --- /dev/null +++ b/sc4pd/headers/server/Rendezvous.h @@ -0,0 +1,41 @@ +/* + * Rendezvous.h + * SC3synth + * + * Created by C. Ramakrishnan on Wed Dec 18 2002. + * Illposed Software + * + */ + +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _Rendezvous_ +#define _Rendezvous_ + +typedef enum { + kSCRendezvous_UDP, + kSCRendezvous_TCP +} SCRendezvousProtocol; + +void PublishPortToRendezvous(SCRendezvousProtocol protocol, short portNum); + +#endif + diff --git a/sc4pd/headers/server/SC_ComPort.h b/sc4pd/headers/server/SC_ComPort.h new file mode 100755 index 0000000..3674fd5 --- /dev/null +++ b/sc4pd/headers/server/SC_ComPort.h @@ -0,0 +1,144 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_ComPort_ +#define _SC_ComPort_ + +#if defined (__APPLE__) && defined (__GNUC__) +#define USE_RENDEZVOUS +#endif + +#include +#ifdef SC_WIN32 +# include +#else +# include +#endif +#include "OSC_Packet.h" +#include "SC_Sem.h" + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class SC_CmdPort +{ +protected: + pthread_t mThread; + struct World *mWorld; + + void Start(); + virtual ReplyFunc GetReplyFunc()=0; +public: + SC_CmdPort(struct World *inWorld); + + virtual void* Run()=0; +}; + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class SC_ComPort : public SC_CmdPort +{ +protected: + int mPortNum; + int mSocket; + struct sockaddr_in mBindSockAddr; + +#ifdef USE_RENDEZVOUS + pthread_t mRendezvousThread; +#endif + +public: + SC_ComPort(struct World *inWorld, int inPortNum); + virtual ~SC_ComPort(); + + int Socket() { return mSocket; } + + int PortNum() const { return mPortNum; } +#ifdef USE_RENDEZVOUS + // default implementation does nothing (this is correct for + // SC_TcpConnectionPort). Subclasses may override. + virtual void PublishToRendezvous() { }; +#endif +}; + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class SC_UdpInPort : public SC_ComPort +{ +protected: + struct sockaddr_in mReplySockAddr; + virtual ReplyFunc GetReplyFunc(); + +public: + SC_UdpInPort(struct World *inWorld, int inPortNum); + ~SC_UdpInPort(); + + int PortNum() const { return mPortNum; } + + void* Run(); +#ifdef USE_RENDEZVOUS + virtual void PublishToRendezvous(); +#endif + +}; + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class SC_TcpInPort : public SC_ComPort +{ + SC_Semaphore mConnectionAvailable; + int mBacklog; + +protected: + virtual ReplyFunc GetReplyFunc(); + +public: + SC_TcpInPort(struct World *inWorld, int inPortNum, int inMaxConnections, int inBacklog); + + virtual void* Run(); + + void ConnectionTerminated(); +#ifdef USE_RENDEZVOUS + virtual void PublishToRendezvous(); +#endif +}; + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class SC_TcpConnectionPort : public SC_ComPort +{ + SC_TcpInPort *mParent; + +protected: + virtual ReplyFunc GetReplyFunc(); + +public: + SC_TcpConnectionPort(struct World *inWorld, SC_TcpInPort *inParent, int inSocket); + virtual ~SC_TcpConnectionPort(); + + virtual void* Run(); +}; + +const int kPacketBufSize = 8192; // this seems to be the maximum size of a UDP packet + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#endif + diff --git a/sc4pd/headers/server/SC_Complex.h b/sc4pd/headers/server/SC_Complex.h new file mode 100644 index 0000000..d4aed20 --- /dev/null +++ b/sc4pd/headers/server/SC_Complex.h @@ -0,0 +1,142 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Complex_ +#define _SC_Complex_ + +#include "SC_Types.h" +#include "float.h" + +//////////////////////////////////////////////////////////////////////////////// + +struct Polar; + +struct Complex +{ + Complex() {} + Complex(float r, float i) : real(r), imag(i) {} + void Set(float r, float i) { real = r; imag = i; } + + Complex& operator=(Complex b) { real = b.real; imag = b.imag; return *this; } + Complex& operator=(float b) { real = b; imag = 0.; return *this; } + + Polar ToPolar(); + Polar ToPolarApx(); + + void ToPolarInPlace(); + void ToPolarApxInPlace(); + + float real, imag; +}; + +struct Polar +{ + Polar() {} + Polar(float m, float p) : mag(m), phase(p) {} + void Set(float m, float p) { mag = m; phase = p; } + + Complex ToComplex(); + Complex ToComplexApx(); + + void ToComplexInPlace(); + void ToComplexApxInPlace(); + + float mag, phase; +}; + +struct ComplexFT +{ + float dc, nyq; + Complex complex[1]; +}; + +struct PolarFT +{ + float dc, nyq; + Polar polar[1]; +}; + +void ToComplex(Polar in, Complex& out); + +inline Complex operator+(Complex a, Complex b) { return Complex(a.real + b.real, a.imag + b.imag); } +inline Complex operator+(Complex a, float b) { return Complex(a.real + b, a.imag); } +inline Complex operator+(float a, Complex b) { return Complex(a + b.real, b.imag); } + +inline Complex& operator+=(Complex& a, const Complex& b) { a.real += b.real, a.imag += b.imag; return a; } +inline Complex& operator+=(Complex& a, float b) { a.real += b; return a; } + +inline Complex operator-(Complex a, Complex b) { return Complex(a.real - b.real, a.imag - b.imag); } +inline Complex operator-(Complex a, float b) { return Complex(a.real - b, a.imag); } +inline Complex operator-(float a, Complex b) { return Complex(a - b.real, b.imag); } + +inline Complex operator-=(Complex a, Complex b) { a.real -= b.real, a.imag -= b.imag; return a; } +inline Complex operator-=(Complex a, float b) { a.real -= b; return a; } + +inline Complex operator*(Complex a, Complex b) +{ + return Complex(a.real * b.real - a.imag * b.imag, a.real * b.imag + a.imag * b.real); +} + +inline Complex operator*(Complex a, float b) +{ + return Complex(a.real * b, a.imag * b); +} + +inline Complex operator*(float a, Complex b) +{ + return Complex(b.real * a, b.imag * a); +} + +inline Complex operator*=(Complex a, Complex b) +{ + a.Set( + a.real * b.real - a.imag * b.imag, + a.real * b.imag + a.imag * b.real + ); + return a; +} + +inline Complex operator*=(Complex a, float b) +{ + a.real *= b; + a.imag *= b; + return a; +} + + +inline Polar operator*(Polar a, float b) +{ + return Polar(a.mag * b, a.phase); +} + +inline Polar operator*(float a, Polar b) +{ + return Polar(a * b.mag, b.phase); +} + +inline Polar operator*=(Polar a, float b) +{ + a.mag *= b; + return a; +} + + +#endif diff --git a/sc4pd/headers/server/SC_CoreAudio.h b/sc4pd/headers/server/SC_CoreAudio.h new file mode 100755 index 0000000..fba5184 --- /dev/null +++ b/sc4pd/headers/server/SC_CoreAudio.h @@ -0,0 +1,263 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_CoreAudio_ +#define _SC_CoreAudio_ + +#include "MsgFifo.h" +#include "SC_FifoMsg.h" +#include "OSC_Packet.h" +#include "SC_SyncCondition.h" +#include "PriorityQueue.h" +#include "SC_Lock.h" + +#define SC_AUDIO_API_COREAUDIO 1 +#define SC_AUDIO_API_JACK 2 +#define SC_AUDIO_API_PORTAUDIO 3 + +#ifdef SC_WIN32 +# define SC_AUDIO_API SC_AUDIO_API_PORTAUDIO +#endif + +#ifndef SC_AUDIO_API +# define SC_AUDIO_API SC_AUDIO_API_COREAUDIO +#endif // SC_AUDIO_API + +#if SC_AUDIO_API == SC_AUDIO_API_COREAUDIO +# include +# include +#endif + +#if SC_AUDIO_API == SC_AUDIO_API_JACK +# include +class SC_JackPortList; +#endif + +#if SC_AUDIO_API == SC_AUDIO_API_PORTAUDIO +#include "portaudio.h" +#endif + + +struct SC_ScheduledEvent +{ + SC_ScheduledEvent() : mTime(0), mPacket(0) {} + SC_ScheduledEvent(struct World *inWorld, int64 inTime, OSC_Packet *inPacket) + : mTime(inTime), mPacket(inPacket), mWorld(inWorld) {} + + int64 Time() { return mTime; } + void Perform(); + + int64 mTime; + OSC_Packet *mPacket; + struct World *mWorld; +}; + +typedef MsgFifo EngineFifo; + + +class SC_AudioDriver +{ +protected: + int64 mOSCincrement; + struct World *mWorld; + double mOSCtoSamples; + int mSampleTime; + + // Common members + uint32 mHardwareBufferSize; // bufferSize returned by kAudioDevicePropertyBufferSize + EngineFifo mFromEngine, mToEngine; + SC_SyncCondition mAudioSync; + pthread_t mThread; + bool mRunThreadFlag; + uint32 mSafetyOffset; + PriorityQueueT mScheduler; + SC_Lock *mProcessPacketLock; + int mNumSamplesPerCallback; + uint32 mPreferredHardwareBufferFrameSize; + uint32 mPreferredSampleRate; + double mBuffersPerSecond; + double mAvgCPU, mPeakCPU; + int mPeakCounter, mMaxPeakCounter; + double mOSCincrementNumerator; + + double mStartHostSecs; + double mPrevHostSecs; + double mStartSampleTime; + double mPrevSampleTime; + double mSmoothSampleRate; + double mSampleRate; + + // Driver interface methods, implemented by subclasses + virtual bool DriverSetup(int* outNumSamplesPerCallback, double* outSampleRate) = 0; + virtual bool DriverStart() = 0; + virtual bool DriverStop() = 0; + +public: + // Common methods + SC_AudioDriver(struct World *inWorld); + virtual ~SC_AudioDriver(); + + int64 mOSCbuftime; + + bool Setup(); + bool Start(); + bool Stop(); + + void ClearSched() { mScheduler.Empty(); } + + void Lock() { mProcessPacketLock->Lock(); } + void Unlock() { mProcessPacketLock->Unlock(); } + + void RunNonRealTime(float *in, float *out, int numSamples, int64 oscTime); + void* RunThread(); + + int SafetyOffset() const { return mSafetyOffset; } + int NumSamplesPerCallback() const { return mNumSamplesPerCallback; } + void SetPreferredHardwareBufferFrameSize(int inSize) + { + mPreferredHardwareBufferFrameSize = inSize; + } + void SetPreferredSampleRate(int inRate) + { + mPreferredSampleRate = inRate; + } + + bool SendMsgToEngine(FifoMsg& inMsg); + bool SendMsgFromEngine(FifoMsg& inMsg); + + void AddEvent(SC_ScheduledEvent& event) { mScheduler.Add(event); } + + double GetAvgCPU() const { return mAvgCPU; } + double GetPeakCPU() const { return mPeakCPU; } + double GetSampleRate() const { return mSampleRate; } + double GetActualSampleRate() const { return mSmoothSampleRate; } +}; + + +// the following classes should be split out into separate source files. +#if SC_AUDIO_API == SC_AUDIO_API_COREAUDIO +class SC_CoreAudioDriver : public SC_AudioDriver +{ + + AudioBufferList * mInputBufList; + AudioDeviceID mInputDevice; + AudioDeviceID mOutputDevice; + + AudioStreamBasicDescription inputStreamDesc; // info about the default device + AudioStreamBasicDescription outputStreamDesc; // info about the default device + + friend OSStatus appIOProc ( AudioDeviceID inDevice, + const AudioTimeStamp* inNow, + const AudioBufferList* inInputData, + const AudioTimeStamp* inInputTime, + AudioBufferList* outOutputData, + const AudioTimeStamp* inOutputTime, + void* defptr); + +protected: + // Driver interface methods + virtual bool DriverSetup(int* outNumSamplesPerCallback, double* outSampleRate); + virtual bool DriverStart(); + virtual bool DriverStop(); + +public: + SC_CoreAudioDriver(struct World *inWorld); + virtual ~SC_CoreAudioDriver(); + + void Run(const AudioBufferList* inInputData, AudioBufferList* outOutputData, int64 oscTime); + + bool UseInput() { return mInputDevice != kAudioDeviceUnknown; } + bool UseSeparateIO() { return UseInput() && mInputDevice != mOutputDevice; } + AudioDeviceID InputDevice() { return mInputDevice; } + AudioDeviceID OutputDevice() { return mOutputDevice; } + + void SetInputBufferList(AudioBufferList * inBufList) { mInputBufList = inBufList; } + AudioBufferList* GetInputBufferList() const { return mInputBufList; } +}; + +inline SC_AudioDriver* SC_NewAudioDriver(struct World *inWorld) +{ + return new SC_CoreAudioDriver(inWorld); +} +#endif // SC_AUDIO_API_COREAUDIO + + +#if SC_AUDIO_API == SC_AUDIO_API_JACK +class SC_JackDriver : public SC_AudioDriver +{ + jack_client_t *mClient; + SC_JackPortList *mInputList; + SC_JackPortList *mOutputList; + int64 mMaxOutputLatency; + +protected: + // Driver interface methods + virtual bool DriverSetup(int* outNumSamplesPerCallback, double* outSampleRate); + virtual bool DriverStart(); + virtual bool DriverStop(); + +public: + SC_JackDriver(struct World *inWorld); + virtual ~SC_JackDriver(); + + void Run(); + void BufferSizeChanged(int numSamples); + void SampleRateChanged(double sampleRate); + void GraphOrderChanged(); +}; + +inline SC_AudioDriver* SC_NewAudioDriver(struct World *inWorld) +{ + return new SC_JackDriver(inWorld); +} +#endif // SC_AUDIO_API_JACK + + +#if SC_AUDIO_API == SC_AUDIO_API_PORTAUDIO +class SC_PortAudioDriver : public SC_AudioDriver +{ + + int mInputChannelCount, mOutputChannelCount; + PaStream *mStream; + +protected: + // Driver interface methods + virtual bool DriverSetup(int* outNumSamplesPerCallback, double* outSampleRate); + virtual bool DriverStart(); + virtual bool DriverStop(); + +public: + SC_PortAudioDriver(struct World *inWorld); + virtual ~SC_PortAudioDriver(); + + int PortAudioCallback( const void *input, void *output, + unsigned long frameCount, const PaStreamCallbackTimeInfo* timeInfo, + PaStreamCallbackFlags statusFlags ); +}; + +inline SC_AudioDriver* SC_NewAudioDriver(struct World *inWorld) +{ + return new SC_PortAudioDriver(inWorld); +} +#endif // SC_AUDIO_API_PORTAUDIO + + +#endif diff --git a/sc4pd/headers/server/SC_Errors.h b/sc4pd/headers/server/SC_Errors.h new file mode 100755 index 0000000..3d3459a --- /dev/null +++ b/sc4pd/headers/server/SC_Errors.h @@ -0,0 +1,58 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Errors_ +#define _SC_Errors_ + +typedef int SCErr; + +const char *SC_ErrorString(SCErr err); + +enum { + kSCErr_None, + kSCErr_Failed, + kSCErr_NodeNotFound, + kSCErr_TargetNodeNotFound, + kSCErr_GroupNotFound, + kSCErr_SynthDefNotFound, + kSCErr_NoSuchCommand, + kSCErr_WrongArgType, + kSCErr_IndexOutOfRange, + kSCErr_AccessDenied, + kSCErr_NoReplyPort, + kSCErr_InvalidControlIndex, + kSCErr_AlreadyLoggedIn, + kSCErr_NotLoggedIn, + kSCErr_TooManyUsers, + kSCErr_TooManyNodes, + kSCErr_DuplicateNodeID, + kSCErr_ReservedNodeID, + kSCErr_OutOfRealTimeMemory, + + kSCErr_UnsupportedHeaderFormat, + kSCErr_UnsupportedSampleFormat, + + kSCErr_BufGenNotFound, + + kSCErr_NumErrors +}; + +#endif diff --git a/sc4pd/headers/server/SC_GraphDef.h b/sc4pd/headers/server/SC_GraphDef.h new file mode 100644 index 0000000..dca6fd2 --- /dev/null +++ b/sc4pd/headers/server/SC_GraphDef.h @@ -0,0 +1,75 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_GraphDef_ +#define _SC_GraphDef_ + +#include "SC_SynthDef.h" +#include "HashTable.h" + +struct ParamSpec +{ + int32 mName[kSCNameLen]; + int32 mIndex; + int32 mHash; +}; + +typedef HashTable ParamSpecTable; + +struct GraphDef +{ + NodeDef mNodeDef; + + uint32 mNumControls; + + uint32 mNumWires; + uint32 mNumConstants; + uint32 mNumUnitSpecs; + uint32 mNumWireBufs; + uint32 mNumCalcUnits; + + float32 *mInitialControlValues; + float32 *mConstants; + + struct UnitSpec *mUnitSpecs; + + size_t mWiresAllocSize, mUnitsAllocSize, mCalcUnitsAllocSize; + size_t mControlAllocSize, mMapControlsAllocSize; + + uint32 mNumParamSpecs; + ParamSpec *mParamSpecs; + ParamSpecTable *mParamSpecTable; + + int mRefCount; + struct GraphDef* mNext; +}; +typedef struct GraphDef GraphDef; + +GraphDef* GraphDef_Recv(World *inWorld, char *buffer, GraphDef *inList); +GraphDef* GraphDef_Load(struct World *inWorld, const char *filename, GraphDef* inList); +GraphDef* GraphDef_LoadDir(struct World *inWorld, char *dirname, GraphDef* inList); +GraphDef* GraphDef_LoadGlob(World *inWorld, const char *pattern, GraphDef *inList); +void GraphDef_DeleteMsg(struct World *inWorld, GraphDef *inDef); +void GraphDef_Dump(GraphDef *inGraphDef); +int32 GetHash(ParamSpec* inParamSpec); +int32* GetKey(ParamSpec* inParamSpec); + +#endif diff --git a/sc4pd/headers/server/SC_Group.h b/sc4pd/headers/server/SC_Group.h new file mode 100644 index 0000000..5a104a7 --- /dev/null +++ b/sc4pd/headers/server/SC_Group.h @@ -0,0 +1,34 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Group_ +#define _SC_Group_ + +#include "SC_Graph.h" + +struct Group { + Node mNode; + + Node *mHead, *mTail; +}; +typedef struct Group Group; + +#endif diff --git a/sc4pd/headers/server/SC_HiddenWorld.h b/sc4pd/headers/server/SC_HiddenWorld.h new file mode 100644 index 0000000..7776874 --- /dev/null +++ b/sc4pd/headers/server/SC_HiddenWorld.h @@ -0,0 +1,113 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_HiddenWorld_ +#define _SC_HiddenWorld_ + +#include "SC_Types.h" +#include "SC_Sem.h" +#include "SC_Rate.h" +#include "SC_SndBuf.h" +#include "SC_RGen.h" +#include "HashTable.h" +#include "SC_World.h" +#include "SC_Reply.h" +#include "MsgFifo.h" + +extern HashTable *gUnitDefLib; + + +struct TriggerMsg { + World *mWorld; + int32 mNodeID; + int32 mTriggerID; + float mValue; + + void Perform(); +}; + +struct NodeEndMsg { + World *mWorld; + int32 mNodeID; + int32 mGroupID; + int32 mPrevNodeID; + int32 mNextNodeID; + int32 mIsGroup; + int32 mHeadID; + int32 mTailID; + int32 mState; + + void Perform(); +}; + +struct DeleteGraphDefMsg { + struct GraphDef* mDef; + + void Perform(); +}; + + +typedef MsgFifoNoFree TriggersFifo; +typedef MsgFifoNoFree NodeEndsFifo; +typedef MsgFifoNoFree DeleteGraphDefsFifo; + +struct HiddenWorld +{ + + class AllocPool *mAllocPool; + IntHashTable *mNodeLib; + HashTable *mGraphDefLib; + uint32 mNumUsers, mMaxUsers; + ReplyAddress *mUsers; + + class SC_AudioDriver *mAudioDriver; + char mPassword[32]; + + uint32 mMaxWireBufs; + float *mWireBufSpace; + + TriggersFifo mTriggers; + NodeEndsFifo mNodeEnds; + DeleteGraphDefsFifo mDeleteGraphDefs; + + SC_Semaphore* mQuitProgram; + + SNDFILE *mNRTInputFile; + SNDFILE *mNRTOutputFile; + FILE *mNRTCmdFile; + + int32 mHiddenID; + int32 mRecentID; + +#ifdef SC_DARWIN + const char* mInputStreamsEnabled; + const char* mOutputStreamsEnabled; +#endif +}; + +typedef struct HiddenWorld HiddenWorld; + +inline SC_AudioDriver *AudioDriver(World *inWorld) +{ + return inWorld->hw->mAudioDriver; +} + +#endif diff --git a/sc4pd/headers/server/SC_Lib.h b/sc4pd/headers/server/SC_Lib.h new file mode 100755 index 0000000..552a231 --- /dev/null +++ b/sc4pd/headers/server/SC_Lib.h @@ -0,0 +1,62 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Lib_ +#define _SC_Lib_ + +#include "SC_Errors.h" +#include "SC_Lock.h" +#include "SC_Types.h" +#include "Hash.h" +#include "HashTable.h" +#include +#include + +class SC_NamedObj +{ +public: + SC_NamedObj(); + virtual ~SC_NamedObj(); + + const int32* Name() const { return mName; } + void SetName(const char *inName); + void SetName(const int32 *inName); + +private: + friend int32 GetHash(const SC_NamedObj *inObj); + friend const int32* GetKey(const SC_NamedObj *inObj); + + int32 mName[kSCNameLen]; + int32 mHash; +}; + +inline int32 GetHash(const SC_NamedObj *inObj) +{ + return inObj->mHash; +} + +inline const int32 *GetKey(const SC_NamedObj *inObj) +{ + return inObj->mName; +} + +#endif + diff --git a/sc4pd/headers/server/SC_Lib_Cintf.h b/sc4pd/headers/server/SC_Lib_Cintf.h new file mode 100755 index 0000000..64eda5e --- /dev/null +++ b/sc4pd/headers/server/SC_Lib_Cintf.h @@ -0,0 +1,124 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Lib_Cintf_ +#define _SC_Lib_Cintf_ + +#include "SC_Lib.h" +#include "SC_Reply.h" + +typedef SCErr (*SC_CommandFunc)(struct World *inWorld, int inSize, char *inData, ReplyAddress *inReply); + +class SC_LibCmd : public SC_NamedObj +{ +public: + SC_LibCmd(SC_CommandFunc inFunc); + + SCErr Perform(struct World *inWorld, int inSize, char *inData, ReplyAddress *inReply); + +private: + SC_CommandFunc mFunc; +}; + +extern Malloc gMalloc; +extern HashTable *gCmdLib; + +void initialize_library(); +SCErr NewCommand(const char *inPath, uint32 inCommandNumber, SC_CommandFunc inFunc); + +// command numbers: +enum { + cmd_none = 0, + + cmd_notify = 1, + cmd_status = 2, + cmd_quit = 3, + cmd_cmd = 4, + + cmd_d_recv = 5, + cmd_d_load = 6, + cmd_d_loadDir = 7, + cmd_d_freeAll = 8, + + cmd_s_new = 9, + + cmd_n_trace = 10, + cmd_n_free = 11, + cmd_n_run = 12, + cmd_n_cmd = 13, + cmd_n_map = 14, + cmd_n_set = 15, + cmd_n_setn = 16, + cmd_n_fill = 17, + cmd_n_before = 18, + cmd_n_after = 19, + + cmd_u_cmd = 20, + + cmd_g_new = 21, + cmd_g_head = 22, + cmd_g_tail = 23, + cmd_g_freeAll = 24, + + cmd_c_set = 25, + cmd_c_setn = 26, + cmd_c_fill = 27, + + cmd_b_alloc = 28, + cmd_b_allocRead = 29, + cmd_b_read = 30, + cmd_b_write = 31, + cmd_b_free = 32, + cmd_b_close = 33, + cmd_b_zero = 34, + cmd_b_set = 35, + cmd_b_setn = 36, + cmd_b_fill = 37, + cmd_b_gen = 38, + + cmd_dumpOSC = 39, + + cmd_c_get = 40, + cmd_c_getn = 41, + cmd_b_get = 42, + cmd_b_getn = 43, + cmd_s_get = 44, + cmd_s_getn = 45, + + cmd_n_query = 46, + cmd_b_query = 47, + + cmd_n_mapn = 48, + cmd_s_noid = 49, + + cmd_g_deepFree = 50, + cmd_clearSched = 51, + + cmd_sync = 52, + + NUMBER_OF_COMMANDS = 53 +}; + +extern SC_LibCmd* gCmdArray[NUMBER_OF_COMMANDS]; + + +#endif + diff --git a/sc4pd/headers/server/SC_List.h b/sc4pd/headers/server/SC_List.h new file mode 100755 index 0000000..d5bed41 --- /dev/null +++ b/sc4pd/headers/server/SC_List.h @@ -0,0 +1,229 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* + +A doubly linked list template. + +*/ + +#ifndef _SC_List_ +#define _SC_List_ + +#include +#ifndef NDEBUG +# define NDEBUG +#endif +#include + + +// A Link can be a node in a list or a list itself. + +template +class Link +{ +public: + Link() : mNext(this), mPrev(this) {} + + T* Prev() { return static_cast(mPrev); } + T* Next() { return static_cast(mNext); } + + void RemoveLeaveDangling() + { + mPrev->mNext = mNext; + mNext->mPrev = mPrev; + } + + void Remove() + { + RemoveLeaveDangling(); + mNext = mPrev = this; + } + + void InsertAfter(T *inLink) + { + mPrev = inLink; + mNext = inLink->mNext; + mNext->mPrev = this; + mPrev->mNext = this; + } + + void InsertBefore(T *inLink) + { + mNext = inLink; + mPrev = inLink->mPrev; + mNext->mPrev = this; + mPrev->mNext = this; + } + + T* Head() { return static_cast(mNext); } + T* Tail() { return static_cast(mPrev); } + + T* PopHead(); + T* PopTail(); + void PushHead(T* inBuf); + void PushTail(T* inBuf); + + bool ContainsBuf(T* inBuf); + bool IsEmpty() { return mNext == this; } + void BeEmpty() { mNext = mPrev = this; } + + void Cat(T* inLink); + + bool SanityCheck(); + void DebugDump(); + +//private: +// Codewarrior refuses to inline Next() in some places.. + Link *mNext, *mPrev; +}; + +template +void MakeListEmpty(Link *inLink, Alloc* inAlloc) +{ + Link* link = inLink->mNext; + while (link != inLink) { + Link* nextlink = link->mNext; + // SC uses placement new extensively, so here we do a 'placement delete'. + // Using DestructSelf allows me to have either virtual + // or non virtual destructors in subclasses at the discretion of the subclass. + ((T*)(link))->DestructSelf(); + inAlloc->Free(static_cast(link)); + link = nextlink; + } + inLink->mNext = inLink->mPrev = inLink; +} + +template +void Link::PushHead(T* inLink) +{ + assert(SanityCheck()); + + Link* link = static_cast*>(inLink); + link->InsertAfter(static_cast(this)); + + assert(SanityCheck()); +} + +template +T* Link::PopHead() +{ + assert(SanityCheck()); + if (IsEmpty()) return 0; + + Link* link = mNext; + + link->Remove(); + + assert(SanityCheck()); + return static_cast(link); +} + +template +void Link::PushTail(T* inLink) +{ + assert(SanityCheck()); + + Link* link = static_cast*>(inLink); + link->InsertBefore(static_cast(this)); + + assert(SanityCheck()); +} + +template +T* Link::PopTail() +{ + assert(SanityCheck()); + if (IsEmpty()) return 0; + + Link* link = mPrev; + link->Remove(); + + assert(SanityCheck()); + return static_cast(link); +} + +template +void Link::Cat(T* inLink) +{ + assert(SanityCheck()); + + Link* link = static_cast*>(inLink); + + if (link->IsEmpty()) return; + if (IsEmpty()) { + mNext = link->mNext; + mPrev = link->mPrev; + link->mNext->mPrev = this; + link->mPrev->mNext = this; + } else { + link->mNext->mPrev = mPrev; + link->mPrev->mNext = this; + mPrev->mNext = link->mNext; + mPrev = link->mPrev; + } + link->mPrev = link; + link->mNext = link; + + assert(SanityCheck()); +} + +template +bool Link::ContainsBuf(T* inLink) +{ + Link* link = static_cast*>(inLink); + Link* curLink = mNext; + while (curLink != this) { + if (curLink == link) return true; + curLink = curLink->mNext; + } + return false; +} + +template +void Link::DebugDump() +{ + Link* link = mNext; + while (link != this) { + //postbuf("Link-> %08X next %08X prev %08X\n", + // link, link->mNext, link->mPrev); + link = link->mNext; + } +} + +template +bool Link::SanityCheck() +{ + Link* link = mNext; + while (link != this) { + if (link->mPrev->mNext != link) { + throw std::runtime_error("Link: bad link <-,->"); + } + if (link->mNext->mPrev != link) { + throw std::runtime_error("Link: bad link ->,<-"); + } + link = link->mNext; + } + return true; +} + + + +#endif diff --git a/sc4pd/headers/server/SC_Lock.h b/sc4pd/headers/server/SC_Lock.h new file mode 100755 index 0000000..57635fe --- /dev/null +++ b/sc4pd/headers/server/SC_Lock.h @@ -0,0 +1,38 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Lock_ +#define _SC_Lock_ + +#include + +class SC_Lock +{ +public: + SC_Lock() { pthread_mutex_init (&mutex, NULL); } + ~SC_Lock() { pthread_mutex_destroy (&mutex); } + void Lock() { pthread_mutex_lock (&mutex); } + void Unlock() { pthread_mutex_unlock (&mutex); } +private: + pthread_mutex_t mutex; +}; + +#endif diff --git a/sc4pd/headers/server/SC_Prototypes.h b/sc4pd/headers/server/SC_Prototypes.h new file mode 100644 index 0000000..c2f353e --- /dev/null +++ b/sc4pd/headers/server/SC_Prototypes.h @@ -0,0 +1,213 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Prototypes_ +#define _SC_Prototypes_ + +#include // for size_t + +#include "SC_Types.h" + +//////////////////////////////////////////////////////////////////////// + +// replacement for calloc. +// calloc lazily zeroes memory on first touch. This is good for most purposes, but bad for realtime audio. +void* zalloc(size_t n, size_t size); + +//////////////////////////////////////////////////////////////////////// + +void World_Run(struct World *inWorld); +void World_Start(World *inWorld); +void World_Cleanup(World *inWorld); +void World_SetSampleRate(struct World *inWorld, double inSampleRate); + +extern "C" { +void* World_Alloc(struct World *inWorld, size_t inByteSize); +void* World_Realloc(struct World *inWorld, void *inPtr, size_t inByteSize); +void World_Free(struct World *inWorld, void *inPtr); +void World_NRTLock(World *world); +void World_NRTUnlock(World *world); +} + +size_t World_TotalFree(struct World *inWorld); +size_t World_LargestFreeChunk(struct World *inWorld); + + +int32 GetKey(struct Node *inNode); +int32 GetHash(struct Node *inNode); +bool World_AddNode(struct World *inWorld, struct Node* inNode); +bool World_RemoveNode(struct World *inWorld, struct Node* inNode); + +extern "C" { +struct Node* World_GetNode(struct World *inWorld, int32 inID); +struct Graph* World_GetGraph(struct World *inWorld, int32 inID); +} + +struct Group* World_GetGroup(struct World *inWorld, int32 inID); + +int32 *GetKey(struct UnitDef *inUnitDef); +int32 GetHash(struct UnitDef *inUnitDef); +bool AddUnitDef(struct UnitDef* inUnitDef); +bool RemoveUnitDef(struct UnitDef* inUnitDef); +struct UnitDef* GetUnitDef(int32* inKey); + +int32 *GetKey(struct BufGen *inBufGen); +int32 GetHash(struct BufGen *inBufGen); +bool AddBufGen(struct BufGen* inBufGen); +bool RemoveBufGen(struct BufGen* inBufGen); +struct BufGen* GetBufGen(int32* inKey); + +int32 *GetKey(struct PlugInCmd *inPlugInCmd); +int32 GetHash(struct PlugInCmd *inPlugInCmd); +bool AddPlugInCmd(struct PlugInCmd* inPlugInCmd); +bool RemovePlugInCmd(struct PlugInCmd* inPlugInCmd); +struct PlugInCmd* GetPlugInCmd(int32* inKey); +int PlugIn_DoCmd(struct World *inWorld, int inSize, char *inArgs, struct ReplyAddress *inReply); + +int32 *GetKey(struct GraphDef *inGraphDef); +int32 GetHash(struct GraphDef *inGraphDef); +bool World_AddGraphDef(struct World *inWorld, struct GraphDef* inGraphDef); +bool World_FreeGraphDef(struct World *inWorld, struct GraphDef* inGraphDef); +bool World_RemoveGraphDef(struct World *inWorld, struct GraphDef* inGraphDef); +struct GraphDef* World_GetGraphDef(struct World *inWorld, int32* inKey); +void World_FreeAllGraphDefs(World *inWorld); +void GraphDef_Free(GraphDef *inGraphDef); +void GraphDef_Define(World *inWorld, GraphDef *inList); +void GraphDef_FreeOverwritten(World *inWorld); + +SCErr bufAlloc(struct SndBuf* buf, int numChannels, int numFrames, double sampleRate); + +//////////////////////////////////////////////////////////////////////// + +void Rate_Init(struct Rate *inRate, double inSampleRate, int inBufLength); + +void Dimension_Init(struct SC_Dimension *inDimension, int inWidth, int inHeight); + +//////////////////////////////////////////////////////////////////////// + +#define GRAPHDEF(inGraph) ((GraphDef*)((inGraph)->mNode.mDef)) +#define GRAPH_PARAM_TABLE(inGraph) (GRAPHDEF(inGraph)->mParamSpecTable) + +int Graph_New(struct World *inWorld, struct GraphDef *def, int32 inID, struct sc_msg_iter* args, struct Graph** outGraph); +void Graph_Ctor(struct World *inWorld, struct GraphDef *inGraphDef, struct Graph *graph, struct sc_msg_iter *msg); +void Graph_Dtor(struct Graph *inGraph); +int Graph_GetControl(struct Graph* inGraph, uint32 inIndex, float& outValue); +int Graph_GetControl(struct Graph* inGraph, int32 inHash, int32 *inName, uint32 inIndex, float& outValue); +void Graph_SetControl(struct Graph* inGraph, uint32 inIndex, float inValue); +void Graph_SetControl(struct Graph* inGraph, int32 inHash, int32 *inName, uint32 inIndex, float inValue); +void Graph_MapControl(Graph* inGraph, uint32 inIndex, uint32 inBus); +void Graph_MapControl(Graph* inGraph, int32 inHash, int32 *inName, uint32 inIndex, uint32 inBus); +void Graph_Trace(Graph *inGraph); +void Graph_RemoveID(World* inWorld, Graph *inGraph); + +//////////////////////////////////////////////////////////////////////// + +int Node_New(struct World *inWorld, struct NodeDef *def, int32 inID, struct Node **outNode); +void Node_Dtor(struct Node *inNode); +void Node_Remove(struct Node* s); +void Node_Delete(struct Node* inNode); +void Node_AddAfter(struct Node* s, struct Node *afterThisOne); +void Node_AddBefore(struct Node* s, struct Node *beforeThisOne); +void Node_Replace(struct Node* s, struct Node *replaceThisOne); +void Node_SetControl(Node* inNode, int inIndex, float inValue); +void Node_SetControl(Node* inNode, int32 inHash, int32 *inName, int inIndex, float inValue); +void Node_MapControl(Node* inNode, int inIndex, int inBus); +void Node_MapControl(Node* inNode, int32 inHash, int32 *inName, int inIndex, int inBus); +void Node_StateMsg(Node* inNode, int inState); +void Node_Trace(Node* inNode); + +extern "C" { +void Node_SetRun(Node* inNode, int inRun); +void Node_SendTrigger(Node* inNode, int triggerID, float value); +void Node_End(struct Node* inNode); +void Node_NullCalc(struct Node* inNode); +void Unit_DoneAction(int doneAction, struct Unit* unit); +} + +//////////////////////////////////////////////////////////////////////// + +extern "C" { +void Group_Calc(Group *inGroup); +void Graph_Calc(struct Graph *inGraph); +} + +int Group_New(World *inWorld, int32 inID, Group** outGroup); +void Group_Dtor(Group *inGroup); +void Group_DeleteAll(Group *inGroup); +void Group_DeepFreeGraphs(Group *inGroup); +void Group_AddHead (Group *s, Node *child); +void Group_AddTail (Group *s, Node *child); +void Group_Insert(Group *s, Node *child, int inIndex); +void Group_SetControl(struct Group* inGroup, uint32 inIndex, float inValue); +void Group_SetControl(struct Group *inGroup, int32 inHash, int32 *inName, uint32 inIndex, float inValue); +void Group_MapControl(Group* inGroup, uint32 inIndex, uint32 inBus); +void Group_MapControl(Group* inGroup, int32 inHash, int32 *inName, uint32 inIndex, uint32 inBus); +void Group_Trace(Group* inGroup); + +//////////////////////////////////////////////////////////////////////// + +struct Unit* Unit_New(struct World *inWorld, struct UnitSpec *inUnitSpec, char*& memory); +void Unit_EndCalc(struct Unit *inUnit, int inNumSamples); +void Unit_End(struct Unit *inUnit); + +void Unit_Dtor(struct Unit *inUnit); + +extern "C" { +void Unit_ZeroOutputs(struct Unit *inUnit, int inNumSamples); +} + +//////////////////////////////////////////////////////////////////////// + +void SendDone(struct ReplyAddress *inReply, char *inCommandName); +void SendFailure(struct ReplyAddress *inReply, char *inCommandName, char *errString); +void ReportLateness(struct ReplyAddress *inReply, float32 seconds); +void DumpReplyAddress(struct ReplyAddress *inReplyAddress); +int32 Hash(struct ReplyAddress *inReplyAddress); + +//////////////////////////////////////////////////////////////////////// + +extern "C" { +int32 timeseed(); +} + +//////////////////////////////////////////////////////////////////////// + +typedef bool (*AsyncStageFn)(World *inWorld, void* cmdData); +typedef void (*AsyncFreeFn)(World *inWorld, void* cmdData); + +int PerformAsynchronousCommand + ( + World *inWorld, + void* replyAddr, + const char* cmdName, + void *cmdData, + AsyncStageFn stage2, // stage2 is non real time + AsyncStageFn stage3, // stage3 is real time - completion msg performed if stage3 returns true + AsyncStageFn stage4, // stage4 is non real time - sends done if stage4 returns true + AsyncFreeFn cleanup, + int completionMsgSize, + void* completionMsgData + ); + +//////////////////////////////////////////////////////////////////////// + +#endif + diff --git a/sc4pd/headers/server/SC_Reply.h b/sc4pd/headers/server/SC_Reply.h new file mode 100755 index 0000000..0400747 --- /dev/null +++ b/sc4pd/headers/server/SC_Reply.h @@ -0,0 +1,55 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Msg_ +#define _SC_Msg_ + +#include +#include +#ifdef SC_WIN32 +# include +#else +#include +#endif +#include "sc_msg_iter.h" + +typedef void (*ReplyFunc)(struct ReplyAddress *inReplyAddr, char* inBuf, int inSize); + +void null_reply_func(struct ReplyAddress* addr, char* msg, int size); + +struct ReplyAddress +{ + struct sockaddr_in mSockAddr; + int mSockAddrLen; + int mSocket; + ReplyFunc mReplyFunc; +}; + +bool operator==(const ReplyAddress& a, const ReplyAddress& b); + +inline void SendReply(ReplyAddress *inReplyAddr, char* inBuf, int inSize) +{ + (inReplyAddr->mReplyFunc)(inReplyAddr, inBuf, inSize); +} + +#endif + + diff --git a/sc4pd/headers/server/SC_Samp.h b/sc4pd/headers/server/SC_Samp.h new file mode 100644 index 0000000..dde9159 --- /dev/null +++ b/sc4pd/headers/server/SC_Samp.h @@ -0,0 +1,38 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Samp_ +#define _SC_Samp_ + +#include "SC_Types.h" + +const int kSineSize = 8192; +const int kSineMask = kSineSize - 1; + +extern float32 gSine[kSineSize+1]; +extern float32 gPMSine[kSineSize+1]; +extern float32 gInvSine[kSineSize+1]; +extern float32 gSineWavetable[2*kSineSize]; + +void SignalAsWavetable(float32* signal, float32* wavetable, long inSize); +void WavetableAsSignal(float32* wavetable, float32* signal, long inSize); + +#endif \ No newline at end of file diff --git a/sc4pd/headers/server/SC_SequencedCommand.h b/sc4pd/headers/server/SC_SequencedCommand.h new file mode 100644 index 0000000..d1a7fb5 --- /dev/null +++ b/sc4pd/headers/server/SC_SequencedCommand.h @@ -0,0 +1,481 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* + * Having SequencedCommands allows performing actions that might otherwise require + * taking a mutex, which is undesirable in a real time thread. + * Some commands require several stages of processing at both the real time + * and non real time levels. This class does the messaging between levels for you + * so that you only need to write the functions. + */ + +#ifndef _SC_SequencedCommand_ +#define _SC_SequencedCommand_ + +#include "OSC_Packet.h" +#include "SC_World.h" +#include "SC_BufGen.h" +#include "sc_msg_iter.h" +#include +#include + +#define CallSequencedCommand(T, inWorld, inSize, inData, inReply) \ + void* space = World_Alloc(inWorld, sizeof(T)); \ + T *cmd = new (space) T(inWorld, inReply); \ + if (!cmd) return kSCErr_Failed; \ + int err = cmd->Init(inData, inSize); \ + if (err) { \ + cmd->~T(); \ + World_Free(inWorld, space); \ + return err; \ + } \ + if (inWorld->mRealTime) cmd->CallNextStage(); \ + else cmd->CallEveryStage(); + + +class SC_SequencedCommand +{ +public: + SC_SequencedCommand(World *inWorld, ReplyAddress *inReplyAddress); + virtual ~SC_SequencedCommand(); + + void Delete(); + + void CallEveryStage(); + void CallNextStage(); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage1(); // real time + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + + void SendDone(char *inCommandName); + +protected: + int mNextStage; + ReplyAddress mReplyAddress; + World *mWorld; + + int mMsgSize; + char *mMsgData; + + virtual void CallDestructor()=0; +}; + +/////////////////////////////////////////////////////////////////////////// + +class SyncCmd : public SC_SequencedCommand +{ +public: + SyncCmd(World *inWorld, ReplyAddress *inReplyAddress); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + virtual void CallDestructor(); + int mID; +}; + +/////////////////////////////////////////////////////////////////////////// + +class BufGenCmd : public SC_SequencedCommand +{ +public: + BufGenCmd(World *inWorld, ReplyAddress *inReplyAddress); + virtual ~BufGenCmd(); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + int mBufIndex; + BufGen *mBufGen; + sc_msg_iter mMsg; + char *mData; + int mSize; + SndBuf mSndBuf; + float *mFreeData; + + virtual void CallDestructor(); + +}; + +/////////////////////////////////////////////////////////////////////////// + +class BufAllocCmd : public SC_SequencedCommand +{ +public: + BufAllocCmd(World *inWorld, ReplyAddress *inReplyAddress); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + int mBufIndex; + SndBuf mSndBuf; + int mNumChannels, mNumFrames; + float *mFreeData; + + virtual void CallDestructor(); + +}; + +/////////////////////////////////////////////////////////////////////////// + + +class BufFreeCmd : public SC_SequencedCommand +{ +public: + BufFreeCmd(World *inWorld, ReplyAddress *inReplyAddress); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + int mBufIndex; + float *mFreeData; + + virtual void CallDestructor(); +}; + + +/////////////////////////////////////////////////////////////////////////// + + +class BufCloseCmd : public SC_SequencedCommand +{ +public: + BufCloseCmd(World *inWorld, ReplyAddress *inReplyAddress); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + int mBufIndex; + + virtual void CallDestructor(); +}; + + +/////////////////////////////////////////////////////////////////////////// + + +class BufZeroCmd : public SC_SequencedCommand +{ +public: + BufZeroCmd(World *inWorld, ReplyAddress *inReplyAddress); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + int mBufIndex; + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +class BufAllocReadCmd : public SC_SequencedCommand +{ +public: + BufAllocReadCmd(World *inWorld, ReplyAddress *inReplyAddress); + virtual ~BufAllocReadCmd(); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + int mBufIndex; + float *mFreeData; + SndBuf mSndBuf; + char *mFilename; + int mFileOffset, mNumFrames; + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +class BufReadCmd : public SC_SequencedCommand +{ +public: + BufReadCmd(World *inWorld, ReplyAddress *inReplyAddress); + virtual ~BufReadCmd(); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + int mBufIndex; + char *mFilename; + int mFileOffset, mNumFrames, mBufOffset; + bool mLeaveFileOpen; + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +class BufWriteCmd : public SC_SequencedCommand +{ +public: + BufWriteCmd(World *inWorld, ReplyAddress *inReplyAddress); + virtual ~BufWriteCmd(); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + int mBufIndex; + char *mFilename; + SF_INFO mFileInfo; + int mNumFrames, mBufOffset; + bool mLeaveFileOpen; + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +class AudioQuitCmd : public SC_SequencedCommand +{ +public: + AudioQuitCmd(World *inWorld, ReplyAddress *inReplyAddress); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +class AudioStatusCmd : public SC_SequencedCommand +{ +public: + AudioStatusCmd(World *inWorld, ReplyAddress *inReplyAddress); + + virtual bool Stage2(); // non real time + +protected: + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +class NotifyCmd : public SC_SequencedCommand +{ +public: + NotifyCmd(World *inWorld, ReplyAddress *inReplyAddress); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + +protected: + + virtual void CallDestructor(); + + int mOnOff; + int mID; +}; + + +/////////////////////////////////////////////////////////////////////////// + +#define CallSendFailureCommand(inWorld, inCmdName, inErrString, inReply) \ + void* space = World_Alloc(inWorld, sizeof(SendFailureCmd)); \ + SendFailureCmd *cmd = new (space) SendFailureCmd(inWorld, inReply); \ + if (!cmd) return kSCErr_Failed; \ + cmd->InitSendFailureCmd(inCmdName, inErrString); \ + if (inWorld->mRealTime) cmd->CallNextStage(); \ + else cmd->CallEveryStage(); \ + +class SendFailureCmd : public SC_SequencedCommand +{ +public: + SendFailureCmd(World *inWorld, ReplyAddress *inReplyAddress); + virtual ~SendFailureCmd(); + + virtual void InitSendFailureCmd(const char *inCmdName, const char* inErrString); + + virtual bool Stage2(); // non real time + +protected: + char *mCmdName, *mErrString; + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +#include "SC_GraphDef.h" + +class LoadSynthDefCmd : public SC_SequencedCommand +{ +public: + LoadSynthDefCmd(World *inWorld, ReplyAddress *inReplyAddress); + virtual ~LoadSynthDefCmd(); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + char *mFilename; + GraphDef *mDefs; + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +#include "SC_GraphDef.h" + +class RecvSynthDefCmd : public SC_SequencedCommand +{ +public: + RecvSynthDefCmd(World *inWorld, ReplyAddress *inReplyAddress); + virtual ~RecvSynthDefCmd(); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + char *mBuffer; + GraphDef *mDefs; + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +class LoadSynthDefDirCmd : public SC_SequencedCommand +{ +public: + LoadSynthDefDirCmd(World *inWorld, ReplyAddress *inReplyAddress); + virtual ~LoadSynthDefDirCmd(); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + char *mFilename; + GraphDef *mDefs; + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +class SendReplyCmd : public SC_SequencedCommand +{ +public: + SendReplyCmd(World *inWorld, ReplyAddress *inReplyAddress); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + +protected: + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + + +typedef bool (*AsyncStageFn)(World *inWorld, void* cmdData); +typedef void (*AsyncFreeFn)(World *inWorld, void* cmdData); + +class AsyncPlugInCmd : public SC_SequencedCommand +{ +public: + AsyncPlugInCmd(World *inWorld, ReplyAddress *inReplyAddress, + const char* cmdName, + void *cmdData, + AsyncStageFn stage2, // stage2 is non real time + AsyncStageFn stage3, // stage3 is real time - completion msg performed if stage3 returns true + AsyncStageFn stage4, // stage4 is non real time - sends done if stage4 returns true + AsyncFreeFn cleanup, + int completionMsgSize, + void* completionMsgData); + + virtual ~AsyncPlugInCmd(); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + const char *mCmdName; + void *mCmdData; + AsyncStageFn mStage2, mStage3, mStage4; + AsyncFreeFn mCleanup; + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +#endif + diff --git a/sc4pd/headers/server/SC_Str4.h b/sc4pd/headers/server/SC_Str4.h new file mode 100644 index 0000000..306b823 --- /dev/null +++ b/sc4pd/headers/server/SC_Str4.h @@ -0,0 +1,103 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* a 4 byte aligned and zero padded string allows faster string operations. */ + +#ifndef _SC_Str4_ +#define _SC_Str4_ + +#include "Hash.h" +#include +#include + +#ifndef _LASTCHAR_ +#define _LASTCHAR_ +#if BYTE_ORDER == LITTLE_ENDIAN +const int32 kLASTCHAR = 0xFF000000; +#else +const int32 kLASTCHAR = 0x000000FF; +#endif +#endif + + +void str4cpy(int32 *dst, const char *src); +void mem4cpy(int32 *dst, const char *src, int charlen); + +// returns the number of pad bytes to add to a string of a given length +inline int str4padbytes(int charlen) +{ + return 4 - (charlen & 3); +} + +// converts length in bytes to length in words +inline int str4len(int charlen) +{ + return (charlen + 4) >> 2; +} + +// returns length in words of a char * +inline int str4len(const char *src) +{ + const char *src0 = src; + while (*src) { src++; } + return str4len(src - src0); +} + +// returns length in words of a int32 * +inline int str4len(const int32 *src) +{ + const int32 *src0 = src; + while (*src++ & kLASTCHAR) {} + int wordlen = src - src0; + return wordlen; +} + +// returns length in words of a int32 * +inline bool str4eq(const int32 *a, const int32 *b) +{ + while(true) { + if (*a != *b) return false; + if ((*a & kLASTCHAR) == 0) return true; + a++; b++; + } +} + +// copy an int32 * +inline void str4cpy(int32 *dst, const int32 *src) +{ + int32 c; + do { + *dst++ = c = *src++; + } while (c & kLASTCHAR); +} + +inline int sc_atoi(char *string) +{ + int value = 0; + if (*string == 0) return -1; + uint32 c; + while ((c = *string++ - '0') <= 9) { + value = value * 10 + c; + } + return value; +} + + +#endif diff --git a/sc4pd/headers/server/SC_SyncCondition.h b/sc4pd/headers/server/SC_SyncCondition.h new file mode 100755 index 0000000..a75fbaa --- /dev/null +++ b/sc4pd/headers/server/SC_SyncCondition.h @@ -0,0 +1,45 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_SyncCondition_ +#define _SC_SyncCondition_ + +#include + +class SC_SyncCondition +{ +public: + SC_SyncCondition(); + ~SC_SyncCondition(); + + void WaitEach(); + void WaitOnce(); + void WaitNext(); + void Signal(); + +private: + pthread_cond_t available; + pthread_mutex_t mutex; + int read, write; +}; + +#endif + diff --git a/sc4pd/headers/server/SC_SynthDef.h b/sc4pd/headers/server/SC_SynthDef.h new file mode 100644 index 0000000..89d5e47 --- /dev/null +++ b/sc4pd/headers/server/SC_SynthDef.h @@ -0,0 +1,43 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SynthDef_ +#define _SynthDef_ + +#include "SC_Types.h" +#include "sc_msg_iter.h" + +typedef void (*NodeDtorFunc)(struct Node* inNode); + +struct NodeDef +{ + int32 mName[kSCNameLen]; + int32 mHash; + + size_t mAllocSize; +}; +typedef struct NodeDef NodeDef; + +extern NodeDef gGroupNodeDef; + +void GroupNodeDef_Init(); +void NodeDef_Dump(NodeDef *inNodeDef); + +#endif diff --git a/sc4pd/headers/server/SC_UnitDef.h b/sc4pd/headers/server/SC_UnitDef.h new file mode 100644 index 0000000..0f75490 --- /dev/null +++ b/sc4pd/headers/server/SC_UnitDef.h @@ -0,0 +1,69 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _UnitDef_ +#define _UnitDef_ + +#include "SC_Types.h" +#include "SC_Unit.h" +#include "HashTable.h" + +struct PlugInCmd +{ + int32 mCmdName[kSCNameLen]; + int32 mHash; + PlugInCmdFunc mFunc; + void *mUserData; +}; + +struct UnitCmd +{ + int32 mCmdName[kSCNameLen]; + int32 mHash; + UnitCmdFunc mFunc; +}; + +struct UnitDef +{ + int32 mUnitDefName[kSCNameLen]; + int32 mHash; + + size_t mAllocSize; + UnitCtorFunc mUnitCtorFunc; + UnitDtorFunc mUnitDtorFunc; + + HashTable* mCmds; + uint32 mFlags; +}; + +extern "C" { +bool UnitDef_Create(char *inName, size_t inAllocSize, + UnitCtorFunc inCtor, UnitDtorFunc inDtor, uint32 inFlags); +bool UnitDef_AddCmd(char *inUnitDefName, char *inCmdName, UnitCmdFunc inFunc); +bool PlugIn_DefineCmd(char *inCmdName, PlugInCmdFunc inFunc, void *inUserData); +} + +int Unit_DoCmd(World *inWorld, int inSize, char *inData); + +inline int32* GetKey(UnitCmd *inCmd) { return inCmd->mCmdName; } +inline int32 GetHash(UnitCmd *inCmd) { return inCmd->mHash; } + + +#endif diff --git a/sc4pd/headers/server/SC_UnitSpec.h b/sc4pd/headers/server/SC_UnitSpec.h new file mode 100644 index 0000000..c72e103 --- /dev/null +++ b/sc4pd/headers/server/SC_UnitSpec.h @@ -0,0 +1,41 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SC_UnitSpec_ +#define _SC_UnitSpec_ + +#include // for size_t + +#include "SC_Unit.h" + +struct UnitSpec +{ + struct UnitDef* mUnitDef; + int16 mCalcRate; + uint16 mNumInputs, mNumOutputs; + int16 mSpecialIndex; + struct InputSpec* mInputSpec; + struct OutputSpec* mOutputSpec; + struct Rate* mRateInfo; + size_t mAllocSize; +}; +typedef struct UnitSpec UnitSpec; + +#endif diff --git a/sc4pd/headers/server/SC_WireSpec.h b/sc4pd/headers/server/SC_WireSpec.h new file mode 100644 index 0000000..33ea15c --- /dev/null +++ b/sc4pd/headers/server/SC_WireSpec.h @@ -0,0 +1,47 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SC_WireSpec_ +#define _SC_WireSpec_ + +#include "SC_Types.h" + +struct InputSpec +{ + // read from file: + int16 mFromUnitIndex; + int16 mFromOutputIndex; + // computed: + int16 mWireIndex; +}; +typedef struct InputSpec InputSpec; + +struct OutputSpec +{ + // read from file: + int16 mCalcRate; + // computed: + int16 mWireIndex; + int16 mBufferIndex; + int16 mNumConsumers; +}; +typedef struct OutputSpec OutputSpec; + +#endif diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt new file mode 100755 index 0000000..2125a06 --- /dev/null +++ b/sc4pd/make-files.txt @@ -0,0 +1,6 @@ +# all the source files from the package +SRCDIR = source +SRCS= \ + main.cpp Dust.cpp MantissaMask.cpp Hasher.cpp Median.cpp \ + BrownNoise.cpp ClipNoise.cpp GrayNoise.cpp WhiteNoise.cpp \ + PinkNoise.cpp Dust2.cpp Crackle.cpp \ No newline at end of file diff --git a/sc4pd/makefile.max-msvc b/sc4pd/makefile.max-msvc new file mode 100644 index 0000000..8a1225f --- /dev/null +++ b/sc4pd/makefile.max-msvc @@ -0,0 +1,77 @@ +# makefile adapted from thomas grill's xsample makefile +# +# Makefile for MSVC++ 6 and .NET +# +# usage: +# to build run "make -f makefile.max-msvc" +# + +!include config-max-msvc.txt + +# includes +INCPATH=/I$(MAXSDKPATH)\max-includes /I$(MAXSDKPATH)\msp-includes /I$(FLEXTPATH) /I./headers/plugin_interface /I./headers/common /I./headers/server /I./headers/app /I./headers/lang +LDFLAGS=/LIBPATH:$(FLEXTPATH) + +!ifdef MSVCPATH +INCPATH=$(INCPATH) /I$(MSVCPATH)\include +LDFLAGS=$(LDFLAGS) /LIBPATH:$(MSVCPATH)\lib +!endif + +!ifdef _DEBUG +LIBS=flext_d-maxwin.lib +!else +LIBS=flext-maxwin.lib +!endif + +LDFLAGS=$(LDFLAGS) /LIBPATH:$(MAXSDKPATH)\max-includes /LIBPATH:$(MAXSDKPATH)\msp-includes + +LIBS=$(LIBS) maxapi.lib maxaudio.lib + +# compiler definitions and flags +DEFS=/DFLEXT_SYS=1 $(UFLAGS) + +CFLAGS=/ML /GR- /GD /Ox /GX /Zp2 + +# the rest can stay untouched +# ---------------------------------------------- + +# all the source files from the package +!include make-files.txt + +# ----------------------------------------------- + +NAME=sc4pd +EXT=mxe +DIR=source + +all: $(OUTPATH) $(OUTPATH)\$(NAME).$(EXT) + +# remove build +clean: + -del /q $(OUTPATH) > nul + -rmdir $(OUTPATH) > nul + +OBJS= $(SRCS:.c=.obj) +OBJS= $(OBJS:.objpp=.obj) + + +$(OUTPATH): + -mkdir $(OUTPATH) > nul + +{$(DIR)}.cpp{}.obj: + cl /c /LD $(CFLAGS) $(DEFS) $(INCPATH) $** /Fo$(OUTPATH)/$@ + +{$(DIR)}.c{}.obj: + cl /c /LD $(CFLAGS) $(DEFS) $(INCPATH) $** /Fo$(OUTPATH)/$@ + + +$(OUTPATH)\$(NAME).$(EXT): $(OBJS) + cd $(OUTPATH) + link /DLL $(LDFLAGS) /out:$(NAME).$(EXT) /INCREMENTAL:NO $** $(LIBS) $(LIBPATH) + @-del *.exp + @-del *.lib + cd .. +!ifdef INSTPATH + @-if not exist $(INSTPATH) mkdir $(INSTPATH) + copy $@ $(INSTPATH) > nul +!endif diff --git a/sc4pd/makefile.pd-bcc b/sc4pd/makefile.pd-bcc new file mode 100644 index 0000000..41c06c2 --- /dev/null +++ b/sc4pd/makefile.pd-bcc @@ -0,0 +1,73 @@ +# makefile adapted from thomas grill's xsample makefile +# +# Makefile for BorlandC++ +# +# usage: make -f makefile.pd-bcc +# +# --------------------------------------------- + +!include config-pd-bcc.txt + +# all the source files from the package +!include make-files.txt + +SETUPFUNCTION=$(NAME)_setup + +# flext stuff +TARGET=pdwin + +# includes, libs +INCPATH=-I$(BCCPATH)\include -I$(PDPATH)\src -I$(FLEXTPATH) ./headers/plugin_interface ./headers/common ./headers/server ./headers/app ./headers/lang +LIBPATH=-L$(BCCPATH)\lib -L$(PDPATH)\lib +LIBS=cw32.lib import32.lib C0D32.OBJ + +# compiler definitions and flags +DEFS=-DFLEXT_SYS=2 +CFLAGS=-tWD $(UFLAGS) + + +# the rest can stay untouched +# ---------------------------------------------- + +# default target +all: $(OUTPATH)\$(NAME).dll + +# remove build +clean: + -del /s /q $(OUTPATH) > nul + rmdir $(OUTPATH) + + +install: + cp $(OUTPATH)\$(NAME).dll $(INSTDIR) + +# ---------------------------------------------- + +OBJS= $(SRCS:.cpp=.obj) + +#.PATH.OBJ=$(OUTPATH) + +#$(SRCS): $(HDRS) +# -touch $< + +{$(SRCDIR)}.cpp.obj: + bcc32 -c $(CFLAGS) $(DEFS) $(INCPATH) -n$(OUTPATH) $< + +$(OUTPATH): + -@if not exist $< mkdir $< + +$(OUTPATH)\pd.lib: $(PDPATH)\bin\pd.dll + implib -a $< $** + +$(OUTPATH)\$(NAME).def: + @echo EXPORTS $(SETUPFUNCTION) = _$(SETUPFUNCTION) > $< +# this next line fixes a strange problem with implib - lacking underscore?! + @echo IMPORTS _rtext_retext=PD.rtext_retext >> $< + +$(OUTPATH)\$(NAME).dll :: $(OUTPATH) $(OUTPATH)\$(NAME).def $(OUTPATH)\pd.lib + +$(OUTPATH)\$(NAME).dll :: $(OBJS) + cd $(OUTPATH) + ilink32 -C -Tpd $(LIBPATH) $** ,..\$<,,$(LIBS) pd.lib $(FLEXTPATH)\flext-$(TARGET).lib ,$(NAME).def + cd .. + \ No newline at end of file diff --git a/sc4pd/makefile.pd-cygwin b/sc4pd/makefile.pd-cygwin new file mode 100644 index 0000000..a04569d --- /dev/null +++ b/sc4pd/makefile.pd-cygwin @@ -0,0 +1,86 @@ +# makefile adapted from thomas grill's xsample makefile +# +# Makefile for gcc @ cygwin +# +# usage: +# to build run "make -f makefile.pd-cygwin" +# to install (as root), do "make -f makefile.pd-cygwin install" +# + +CONFIG=config-pd-cygwin.txt +MAKEFILE=makefile.pd-cygwin + +include ${CONFIG} + + +# compiler stuff +# /usr/include holds the cygwin pthread headers and must be first! +INCLUDES=/usr/include $(PDINC) ./headers/plugin_interface ./headers/common ./headers/server ./headers/app ./headers/lang + +FLAGS=-DFLEXT_SYS=2 +CFLAGS=-O2 -funroll-loops -fmove-all-movables -frerun-loop-opt -finline-functions -fno-rtti -fno-exceptions ${UFLAGS} + +PDLIBS=$(PD)/bin/pd.dll $(PD)/bin/pthreadVC.dll + + +ifdef FLEXT_SHARED + +CFLAGS+=-DFLEXT_SHARED +FLEXTLIB=$(FLEXTPATH)/flext.dll + +else + +FLEXTLIB=$(FLEXTPATH)/flext-pdwin.lib + +endif + + +# ---------------------------------------------- +# the rest can stay untouched +# ---------------------------------------------- + +NAME=sc4pd + +include make-files.txt + +TARGET=$(TARGDIR)/$(NAME).dll + +# default target +all: $(TARGDIR) $(TARGET) + +$(patsubst %,$(SRCDIR)/%,$(SRCS)): $(patsubst %,$(SRCDIR)/%,$(HDRS)) $(MAKEFILE) $(CONFIG) + touch $(patsubst %,$(SRCDIR)/%,$(SRCS)) + +$(TARGDIR): + -mkdir $(TARGDIR) + +$(TARGDIR)/%.o : $(SRCDIR)/%.cpp + $(CXX) -c $(CFLAGS) $(FLAGS) $(patsubst %,-I%,$(INCLUDES) $(FLEXTPATH)) $< -o $@ + +$(TARGET) : $(patsubst %.cpp,$(TARGDIR)/%.o,$(SRCS)) $(FLEXTLIB) + $(CXX) -shared $(LDFLAGS) $^ ${PDLIBS} $(patsubst %,-l%,$(LIBS)) -o $@ + strip --strip-unneeded $@ + chmod 755 $@ + +$(INSTDIR): + -mkdir $(INSTDIR) + +install:: $(INSTDIR) + +install:: $(TARGET) + cp $^ $(INSTDIR) +# chown root.root $(patsubst %,$(INSTDIR)/%,$(notdir $^)) + +$(HELPDIR): + -mkdir $(HELPDIR) + +install-help:: $(HELPDIR) + +install-help:: ./pd + chmod 644 $^/*.* + cp $^/*.* $(HELPDIR) + + +.PHONY: clean +clean: + rm -f $(TARGDIR)/*.o $(TARGET) diff --git a/sc4pd/makefile.pd-darwin b/sc4pd/makefile.pd-darwin new file mode 100755 index 0000000..04a3779 --- /dev/null +++ b/sc4pd/makefile.pd-darwin @@ -0,0 +1,77 @@ +# makefile adapted from thomas grill's xsample makefile +# +# Makefile for gcc @ OSX (darwin) +# +# usage: +# to build run "make -f makefile.pd-darwin" +# to install (as root), do "make -f makefile.pd-darwin install" +# to install help, do "make -f makefile.pd-darwin install-help" +# + +CONFIG=config-pd-darwin.txt + +include ${CONFIG} + +FLEXTLIB=$(FLEXTPATH)/libflext.a + +# compiler stuff +INCLUDES=$(PDINC) ./headers/plugin_interface ./headers/common ./headers/server ./headers/app ./headers/lang +FLAGS=-DFLEXT_SYS=2 +CFLAGS=${UFLAGS} -dynamic -O2 -Wno-unused -Wno-parentheses -Wno-switch -Wstrict-prototypes -funroll-loops -fmove-all-movables -frerun-loop-opt -fno-rtti -fno-exceptions +LIBS=m gcc +LDFLAGS=$(FLEXTLIB) -bundle -bundle_loader $(PDBIN) +FRAMEWORKS=Carbon veclib + +# ---------------------------------------------- +# the rest can stay untouched +# ---------------------------------------------- + +NAME=sc4dp + +include make-files.txt + +MAKEFILE=makefile.pd-darwin +TARGET=$(TARGDIR)/$(NAME).pd_darwin + + +# default target +all: $(TARGDIR) $(TARGET) + +$(patsubst %,$(SRCDIR)/%,$(SRCS)): $(patsubst %,$(SRCDIR)/%,$(HDRS)) $(MAKEFILE) $(CONFIG) + touch $(patsubst %,$(SRCDIR)/%,$(SRCS)) + +$(TARGDIR): + -mkdir $(TARGDIR) + +$(TARGDIR)/%.o : $(SRCDIR)/%.cpp + $(CXX) -c $(CFLAGS) $(FLAGS) $(patsubst %,-I%,$(INCLUDES) $(FLEXTPATH)) $< -o $@ + +$(TARGET) : $(patsubst %.cpp,$(TARGDIR)/%.o,$(SRCS)) + $(CXX) $(LDFLAGS) $^ $(patsubst %,-framework %,$(FRAMEWORKS)) $(patsubst %,-L%,$(LIBPATH)) $(patsubst %,-l%,$(LIBS)) -o $@ + chmod 755 $@ + + +$(INSTDIR): + -mkdir $(INSTDIR) + +install:: $(INSTDIR) + +install:: $(TARGET) + cp -R $^ $(INSTDIR) +# chown -R root.root $(INSTDIR) + + +$(HELPDIR): + -mkdir $(HELPDIR) + +install-help:: $(HELPDIR) + +install-help:: ./pd + cp $^/*.* $(HELPDIR) +# chown -R root.root $(HELPDIR) + + +.PHONY: clean +clean: + rm -f $(TARGDIR)/*.o $(TARGET) + diff --git a/sc4pd/makefile.pd-linux b/sc4pd/makefile.pd-linux new file mode 100644 index 0000000..994141c --- /dev/null +++ b/sc4pd/makefile.pd-linux @@ -0,0 +1,94 @@ +# makefile adapted from thomas grill's xsample makefile +# +# Makefile for gcc @ linux +# +# usage: +# to build run "make -f makefile.pd-linux" +# to install (as root), do "make -f makefile.pd-linux install" +# + +CONFIG=config-pd-linux.txt + +include ${CONFIG} + +FLEXTLIB=$(FLEXTPATH)/flext.a + +# compiler stuff +INCLUDES=$(PDINC) ./headers/plugin_interface ./headers/common \ + ./headers/server ./headers/app ./headers/lang +FLAGS=-DFLEXT_SYS=2 +CFLAGS=${UFLAGS} -O3 -I/home/tim/pd/externals/grill/flext/source -funroll-loops -fmove-all-movables -frerun-loop-opt -finline-functions -fno-rtti -fno-exceptions + +LIBS=m + +ifdef FLEXT_SHARED +CFLAGS+=-DFLEXT_SHARED -DFLEXT_THREADS +LDFLAGS+=-Bdynamic +LINKFLEXT=-lflext +else +LINKFLEXT=$(FLEXTLIB) +endif + + +# ---------------------------------------------- +# the rest can stay untouched +# ---------------------------------------------- + +NAME=sc4pd + +include make-files.txt + +MAKEFILE=makefile.pd-linux +TARGET=$(TARGDIR)/$(NAME).pd_linux + +# default target +all: $(TARGDIR) $(TARGET) + +$(patsubst %,$(SRCDIR)/%,$(SRCS)): $(patsubst %,$(SRCDIR)/%,$(HDRS)) $(MAKEFILE) $(CONFIG) + touch $(patsubst %,$(SRCDIR)/%,$(SRCS)) + +$(TARGDIR): + -mkdir $(TARGDIR) + +$(TARGDIR)/%.o : $(SRCDIR)/%.cpp + $(CXX) -c $(CFLAGS) $(FLAGS) $(patsubst %,-I%,$(INCLUDES) $(FLEXTPATH)) $< -o $@ + +$(TARGET) : $(patsubst %.cpp,$(TARGDIR)/%.o,$(SRCS)) + $(CXX) $(LDFLAGS) -shared $^ $(patsubst %,-l%,$(LIBS)) -L$(FLEXTPATH) $(LINKFLEXT) -o $@ + #strip --strip-unneeded $@ + chmod 755 $@ + +$(INSTDIR): + -mkdir $(INSTDIR) + +install:: $(INSTDIR) + +install:: $(TARGET) + cp $^ $(INSTDIR) + chown root.root $(patsubst %,$(INSTDIR)/%,$(notdir $^)) + +$(HELPDIR): + -mkdir $(HELPDIR) + +install-help:: $(HELPDIR) + +install-help:: ./pd + chmod 644 $^/*.* + cp $^/*.* $(HELPDIR) + + +.PHONY: clean +clean: + rm -f $(TARGDIR)/*.o $(TARGET) + + + + + + + + + + + + diff --git a/sc4pd/makefile.pd-mingw b/sc4pd/makefile.pd-mingw new file mode 100644 index 0000000..62cf1ae --- /dev/null +++ b/sc4pd/makefile.pd-mingw @@ -0,0 +1,85 @@ +# makefile adapted from thomas grill's xsample makefile +# +# Makefile for gcc @ minGW +# +# usage: +# to build run "make -f makefile.pd-mingw" +# to install (as root), do "make -f makefile.pd-mingw install" +# + +CONFIG=config-pd-mingw.txt +MAKEFILE=makefile.pd-mingw + +include ${CONFIG} + + +# compiler stuff +INCLUDES=$(PDINC) ./headers/plugin_interface ./headers/common ./headers/server ./headers/app ./headers/lang + +FLAGS=-DFLEXT_SYS=2 +CFLAGS=-O2 -funroll-loops -fmove-all-movables -frerun-loop-opt -finline-functions -fno-rtti -fno-exceptions ${UFLAGS} + +PDLIBS=$(PD)/bin/pd.dll $(PD)/bin/pthreadVC.dll + + +ifdef FLEXT_SHARED + +CFLAGS+=-DFLEXT_SHARED +FLEXTLIB=$(FLEXTPATH)/flext.dll + +else + +FLEXTLIB=$(FLEXTPATH)/flext-pdwin.lib + +endif + + +# ---------------------------------------------- +# the rest can stay untouched +# ---------------------------------------------- + +NAME=sc4pd + +include make-files.txt + +TARGET=$(TARGDIR)/$(NAME).dll + +# default target +all: $(TARGDIR) $(TARGET) + +$(patsubst %,$(SRCDIR)/%,$(SRCS)): $(patsubst %,$(SRCDIR)/%,$(HDRS)) $(MAKEFILE) $(CONFIG) +# echo touch $(patsubst %,$(SRCDIR)/%,$(SRCS)) # minGW has no touch + +$(TARGDIR): + -mkdir $(TARGDIR) + +$(TARGDIR)/%.o : $(SRCDIR)/%.cpp + $(CXX) -c $(CFLAGS) $(FLAGS) $(patsubst %,-I%,$(INCLUDES) $(FLEXTPATH)) $< -o $@ + +$(TARGET) : $(patsubst %.cpp,$(TARGDIR)/%.o,$(SRCS)) $(FLEXTLIB) + $(CXX) -shared $(LDFLAGS) $^ ${PDLIBS} $(patsubst %,-l%,$(LIBS)) -o $@ + strip --strip-unneeded $@ + chmod 755 $@ + +$(INSTDIR): + -mkdir $(INSTDIR) + +install:: $(INSTDIR) + +install:: $(TARGET) + cp $^ $(INSTDIR) +# chown root.root $(patsubst %,$(INSTDIR)/%,$(notdir $^)) + +$(HELPDIR): + -mkdir $(HELPDIR) + +install-help:: $(HELPDIR) + +install-help:: ./pd + chmod 644 $^/*.* + cp $^/*.* $(HELPDIR) + + +.PHONY: clean +clean: + rm -f $(TARGDIR)/*.o $(TARGET) diff --git a/sc4pd/makefile.pd-msvc b/sc4pd/makefile.pd-msvc new file mode 100644 index 0000000..11ccda9 --- /dev/null +++ b/sc4pd/makefile.pd-msvc @@ -0,0 +1,53 @@ +# makefile adapted from thomas grill's xsample makefile +# +# Makefile for MSVC++ 6 +# +# usage: +# to build run "make -f makefile.pd-msvc" +# + +!include config-pd-msvc.txt + +# includes +INCPATH=/I"$(MSVCPATH)\include" /I"$(PDPATH)\src" /I"$(FLEXTPATH)" /I"./headers/plugin_interface" /I"./headers/common" /I"/headers/server" /I"./headers/app" /I"./headers/lang +LIBPATH=/LIBPATH:"$(MSVCPATH)\lib" /LIBPATH:"$(PDPATH)\bin" /LIBPATH:"$(FLEXTPATH)" +LIBS=pd.lib pthreadVC.lib flext-pdwin.lib + +# compiler definitions and flags +DEFS=/DFLEXT_SYS=2 + +CFLAGS=/GR- /GX- /GD /G6 /Ox /EHsc /ML + +# the rest can stay untouched +# ---------------------------------------------- + +NAME=sc4pd + +!include make-files.txt + + +all: $(OUTPATH) $(OUTPATH)\$(NAME).dll + +# remove build +clean: + -del /q $(OUTPATH) > nul + -rmdir $(OUTPATH) > nul + +OBJS= $(SRCS:.cpp=.obj) + +$(OUTPATH): + -mkdir $(OUTPATH) > nul + +{$(SRCDIR)}.cpp{}.obj: + cl /c /LD $(CFLAGS) $(DEFS) $(INCPATH) $** /Fo$(OUTPATH)\$@ + +$(OUTPATH)\$(NAME).dll: $(OBJS) + cd $(OUTPATH) + link /DLL /out:$(NAME).dll /INCREMENTAL:NO $** $(LIBS) $(LIBPATH) + @-del *.exp + @-del *.lib + cd .. +!ifdef INSTPATH + @-if not exist $(INSTPATH) mkdir $(INSTPATH) + copy $@ $(INSTPATH) > nul +!endif diff --git a/sc4pd/pd/crackle.pd b/sc4pd/pd/crackle.pd new file mode 100644 index 0000000..7cbb5a0 --- /dev/null +++ b/sc4pd/pd/crackle.pd @@ -0,0 +1,10 @@ +#N canvas 0 0 450 300 10; +#X obj 266 210 dac~; +#X obj 279 128 Crackle~ 2; +#X obj 369 196 print~; +#X obj 378 161 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X connect 1 0 0 0; +#X connect 1 0 0 1; +#X connect 1 0 2 0; +#X connect 3 0 2 0; diff --git a/sc4pd/pd/dust.pd b/sc4pd/pd/dust.pd new file mode 100644 index 0000000..6a709ec --- /dev/null +++ b/sc4pd/pd/dust.pd @@ -0,0 +1,11 @@ +#N canvas 0 0 450 300 10; +#X obj 96 130 dac~; +#X floatatom 264 119 5 0 0 0 - - -; +#X obj 123 109 Median~ 20; +#X obj 72 51 Dust~ 600; +#X obj 123 82 Dust~ 1000; +#X obj 264 82 Dust 1; +#X connect 2 0 0 1; +#X connect 3 0 0 0; +#X connect 4 0 2 0; +#X connect 5 0 1 0; diff --git a/sc4pd/pd/hasher.pd b/sc4pd/pd/hasher.pd new file mode 100644 index 0000000..532f032 --- /dev/null +++ b/sc4pd/pd/hasher.pd @@ -0,0 +1,17 @@ +#N canvas 0 0 450 300 10; +#X obj 18 28 osc~ 441; +#X obj 12 159 dac~; +#X obj 89 131 print~; +#X obj 144 112 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X floatatom 265 37 9 0 0 0 - - -; +#X floatatom 266 110 9 0 0 0 - - -; +#X obj 266 78 Hasher; +#X obj 18 86 Hasher~; +#X connect 0 0 7 0; +#X connect 3 0 2 0; +#X connect 4 0 6 0; +#X connect 6 0 5 0; +#X connect 7 0 2 0; +#X connect 7 0 1 0; +#X connect 7 0 1 1; diff --git a/sc4pd/pd/mantissamask.pd b/sc4pd/pd/mantissamask.pd new file mode 100644 index 0000000..5e2d3ed --- /dev/null +++ b/sc4pd/pd/mantissamask.pd @@ -0,0 +1,21 @@ +#N canvas 0 0 450 300 10; +#X obj 18 28 osc~ 441; +#X obj 12 159 dac~; +#X obj 89 131 print~; +#X obj 144 112 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 18 86 MantissaMask~ 3; +#X floatatom 112 20 5 0 0 0 - - -; +#X msg 89 60 set \$1; +#X floatatom 265 37 9 0 0 0 - - -; +#X floatatom 266 110 9 0 0 0 - - -; +#X obj 266 78 MantissaMask 0; +#X connect 0 0 4 0; +#X connect 3 0 2 0; +#X connect 4 0 2 0; +#X connect 4 0 1 0; +#X connect 4 0 1 1; +#X connect 5 0 6 0; +#X connect 6 0 4 0; +#X connect 7 0 9 0; +#X connect 9 0 8 0; diff --git a/sc4pd/readme.txt b/sc4pd/readme.txt new file mode 100644 index 0000000..7372555 --- /dev/null +++ b/sc4pd/readme.txt @@ -0,0 +1,23 @@ +sc4pd: SuperCollider for PureData +(c) 2004 Tim Blechmann + +sc4pd includes the SuperCollider header files and is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + +Both SuperCollider and sc4pd are released under the GPL + + +sc4pd is a port of some SuperCollider UGens to PD objects. If you want to link +both applications, it's better to use jack. +sc4pd is using thomas grill's flext and should be portable to max/msp. + + +thanks to: + James McCartney for SuperCollider + Miller Puckette for PureData + Thomas Grill for Flext + three great pieces of software... + +bugs, suggestions, complains to: TimBlechmann@gmx.de \ No newline at end of file diff --git a/sc4pd/source/BrownNoise.cpp b/sc4pd/source/BrownNoise.cpp new file mode 100644 index 0000000..39cbc26 --- /dev/null +++ b/sc4pd/source/BrownNoise.cpp @@ -0,0 +1,150 @@ +/* sc4pd + BrownNoise, BrownNoise~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: AMM: Laminal + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ BrownNoise~ -------------------------------*/ + +class BrownNoise_ar: + public flext_dsp +{ + FLEXT_HEADER(BrownNoise_ar,flext_dsp); + +public: + BrownNoise_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + float m_level; + RGen rgen; +}; + +FLEXT_LIB_DSP_V("BrownNoise~",BrownNoise_ar); + +BrownNoise_ar::BrownNoise_ar(int argc, t_atom *argv) +{ + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(0); //set seed to 0 + m_level=rgen.frand2(); + + AddOutSignal(); +} + + +void BrownNoise_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + RGET; + + float z = m_level; + + for (int i = 0; i!= n;++i) + { + z += frand8(s1, s2, s3); + if (z > 1.f) + z = 2.f - z; + else + if (z < -1.f) + z = -2.f - z; + (*(nout)++) = z; + } + m_level = z; + + RPUT; +} + + +/* ------------------------ BrownNoise ---------------------------------*/ + +class BrownNoise_kr: + public flext_base +{ + FLEXT_HEADER(BrownNoise_kr,flext_base); + +public: + BrownNoise_kr(int argc, t_atom *argv); + +protected: + void m_perform(); + +private: + float m_level; + RGen rgen; + FLEXT_CALLBACK(m_perform); +}; + +FLEXT_LIB_V("BrownNoise",BrownNoise_kr); + +BrownNoise_kr::BrownNoise_kr(int argc, t_atom *argv) +{ + FLEXT_ADDBANG(0,m_perform); + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(0); //set seed to 0 + m_level=rgen.frand2(); + + AddOutFloat(); +} + +void BrownNoise_kr::m_perform() +{ + float z = m_level + rgen.frand8(); + if (z > 1.f) + z = 2.f - z; + else + if (z < -1.f) + z = -2.f - z; + ToOutFloat(0,z); + m_level = z; +} diff --git a/sc4pd/source/ClipNoise.cpp b/sc4pd/source/ClipNoise.cpp new file mode 100644 index 0000000..14b5101 --- /dev/null +++ b/sc4pd/source/ClipNoise.cpp @@ -0,0 +1,130 @@ +/* sc4pd + ClipNoise, ClipNoise~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Henry Threadgill: Everybodys Mouth's A Book + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ ClipNoise~ -------------------------------*/ + +class ClipNoise_ar: + public flext_dsp +{ + FLEXT_HEADER(ClipNoise_ar,flext_dsp); + +public: + ClipNoise_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + RGen rgen; +}; + +FLEXT_LIB_DSP_V("ClipNoise~",ClipNoise_ar); + +ClipNoise_ar::ClipNoise_ar(int argc, t_atom *argv) +{ + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(0); //set seed to 0 + + AddOutSignal(); +} + + +void ClipNoise_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + RGET; + + for (int i = 0; i!= n;++i) + { + (*(nout)++) = fcoin(s1, s2, s3); + } + + RPUT; +} + + +/* ------------------------ ClipNoise ---------------------------------*/ + +class ClipNoise_kr: + public flext_base +{ + FLEXT_HEADER(ClipNoise_kr,flext_base); + +public: + ClipNoise_kr(int argc, t_atom *argv); + +protected: + void m_perform(); + +private: + RGen rgen; + FLEXT_CALLBACK(m_perform); +}; + +FLEXT_LIB_V("ClipNoise",ClipNoise_kr); + +ClipNoise_kr::ClipNoise_kr(int argc, t_atom *argv) +{ + FLEXT_ADDBANG(0,m_perform); + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(0); //set seed to 0 + + AddOutFloat(); +} + +void ClipNoise_kr::m_perform() +{ + ToOutFloat(0,rgen.fcoin()); +} diff --git a/sc4pd/source/Crackle.cpp b/sc4pd/source/Crackle.cpp new file mode 100644 index 0000000..a86ea18 --- /dev/null +++ b/sc4pd/source/Crackle.cpp @@ -0,0 +1,161 @@ +/* sc4pd + Crackle, Crackle~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: David S. Ware: Threads + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ Crackle~ -------------------------------*/ + +class Crackle_ar: + public flext_dsp +{ + FLEXT_HEADER(Crackle_ar,flext_dsp); + +public: + Crackle_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + + void m_set(float f) + { + m_paramf = f; + } + +private: + FLEXT_CALLBACK_F(m_set); + float m_paramf; + float m_y1, m_y2; +}; + +FLEXT_LIB_DSP_V("Crackle~",Crackle_ar); + +Crackle_ar::Crackle_ar(int argc, t_atom *argv) + : m_y1(0.3f),m_y2(0.f) +{ + FLEXT_ADDMETHOD_(0,"set",m_set); + //parse arguments + AtomList Args(argc,argv); + m_paramf=sc_getfloatarg(Args,0); + + if (m_paramf == 0) + m_paramf = 1; + + AddOutSignal(); +} + + +void Crackle_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + float paramf = m_paramf; + float y1 = m_y1; + float y2 = m_y2; + float y0; + + for (int i = 0; i!= n;++i) + { + (*(nout)++) = y0 = fabs(y1 * paramf - y2 - 0.05f); + y2 = y1; + y1 = y0; + } + + m_y1=y1; + m_y2=y2; +} + + +/* ------------------------ Crackle ---------------------------------*/ + +class Crackle_kr: + public flext_base +{ + FLEXT_HEADER(Crackle_kr,flext_base); + +public: + Crackle_kr(int argc, t_atom *argv); + +protected: + void m_perform(); + + void m_set(float f) + { + m_paramf = f; + } + +private: + float m_paramf; + float m_y1, m_y2; + FLEXT_CALLBACK(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("Crackle",Crackle_kr); + +Crackle_kr::Crackle_kr(int argc, t_atom *argv) + : m_y1(0.3f),m_y2(0.f) +{ + FLEXT_ADDBANG(0,m_perform); + FLEXT_ADDMETHOD_(0,"set",m_set); + + //parse arguments + AtomList Args(argc,argv); + m_paramf=sc_getfloatarg(Args,0); + + if (m_paramf == 0) + m_paramf = 1; + + AddOutFloat(); +} + +void Crackle_kr::m_perform() +{ + float y0 = fabs(m_y1 * m_paramf - m_y2 - 0.05f); + m_y2 = m_y1; + m_y1 = y0; + + ToOutFloat(0,y0); +} diff --git a/sc4pd/source/Dust.cpp b/sc4pd/source/Dust.cpp new file mode 100644 index 0000000..19b6312 --- /dev/null +++ b/sc4pd/source/Dust.cpp @@ -0,0 +1,179 @@ +/* sc4pd: + Dust, Dust~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Assif Tsahar & Tatsuya Nakatani: Come Sunday +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + +/* ------------------------ Dust~ -------------------------------------*/ + +class Dust_ar: + public flext_dsp +{ + FLEXT_HEADER(Dust_ar,flext_dsp); + +public: + Dust_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp (int n,t_signalvec const * insigs, + t_signalvec const * outsigs); + + void m_set(float f) + { + m_density = f; + m_thresh = m_density/Samplerate(); + m_scale = m_thresh > 0.f ? 1.f / m_thresh : 0.f; + } + +private: + FLEXT_CALLBACK_F(m_set); + float m_density, m_thresh, m_scale; + RGen rgen; + +}; + +FLEXT_LIB_DSP_V("Dust~",Dust_ar); + +Dust_ar::Dust_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"set",m_set); + + //parse arguments + AtomList Args(argc,argv); + m_density=sc_getfloatarg(Args,0); + + rgen.init(0); //set seed to 0 + + AddOutSignal(); +} + +void Dust_ar::m_dsp(int n,t_signalvec const * insigs, + t_signalvec const * outsigs) +{ + m_thresh = m_density/Samplerate(); + m_scale = m_thresh > 0.f ? 1.f / m_thresh : 0.f; +} + +void Dust_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + RGET; + float thresh = m_thresh; + float scale = m_scale; + + for (int i = 0; i!= n;++i) + { + float z = frand(s1,s2,s3); + if (z < thresh) + (*(nout)++) = z * scale; + else + (*(nout)++) = 0.f; + } + + RPUT; +} + + +/* ------------------------ Dust ---------------------------------------*/ + +class Dust_kr: + public flext_base +{ + FLEXT_HEADER(Dust_kr,flext_base); + +public: + Dust_kr(int argc, t_atom *argv); + +protected: + void m_set(float f); + Timer Dust_timer; + void m_doit(); + +private: + float m_density, m_scale; + float mtbt; //medium time between trigger + RGen rgen; + FLEXT_CALLBACK_1(m_set,float); + FLEXT_CALLBACK_T(m_doit); +}; + +FLEXT_LIB_V("Dust",Dust_kr); + +Dust_kr::Dust_kr(int argc, t_atom *argv) + : Dust_timer(false) +{ + FLEXT_ADDMETHOD(0,m_set); + + //parse arguments + AtomList Args(argc,argv); + m_density=sc_getfloatarg(Args,0); + + rgen.init(0); //set seed to 0 + AddOutFloat(); + + FLEXT_ADDTIMER(Dust_timer,m_doit); + + m_set(m_density); +} + +void Dust_kr::m_set(float f) +{ + Dust_timer.Reset(); + + if(f==0) + { + return; + } + m_density = f; + mtbt = 1/f*1000; + + Dust_timer.Delay(mtbt * 0.002 * rgen.frand()); +} + +void Dust_kr::m_doit() +{ + ToOutFloat(0,rgen.frand()); + + Dust_timer.Delay(mtbt * 0.002 * rgen.frand()); +} diff --git a/sc4pd/source/Dust2.cpp b/sc4pd/source/Dust2.cpp new file mode 100644 index 0000000..a8cbbc3 --- /dev/null +++ b/sc4pd/source/Dust2.cpp @@ -0,0 +1,180 @@ +/* sc4pd: + Dust2, Dust2~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Herbert Eimert: Epitaph für Aikichi Kuboyama + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + +/* ------------------------ Dust2~ -------------------------------------*/ + +class Dust2_ar: + public flext_dsp +{ + FLEXT_HEADER(Dust2_ar,flext_dsp); + +public: + Dust2_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp (int n,t_signalvec const * insigs, + t_signalvec const * outsigs); + + void m_set(float f) + { + m_density = f; + m_thresh = m_density/Samplerate(); + m_scale = m_thresh > 0.f ? 1.f / m_thresh : 0.f; + } + +private: + FLEXT_CALLBACK_F(m_set); + float m_density, m_thresh, m_scale; + RGen rgen; + +}; + +FLEXT_LIB_DSP_V("Dust2~",Dust2_ar); + +Dust2_ar::Dust2_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"set",m_set); + + //parse arguments + AtomList Args(argc,argv); + m_density=sc_getfloatarg(Args,0); + + rgen.init(0); //set seed to 0 + + AddOutSignal(); +} + +void Dust2_ar::m_dsp(int n,t_signalvec const * insigs, + t_signalvec const * outsigs) +{ + m_thresh = m_density/Samplerate(); + m_scale = m_thresh > 0.f ? 2.f / m_thresh : 0.f; +} + +void Dust2_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + RGET; + float thresh = m_thresh; + float scale = m_scale; + + for (int i = 0; i!= n;++i) + { + float z = frand(s1,s2,s3); + if (z < thresh) + (*(nout)++) = z * scale - 1.f; + else + (*(nout)++) = 0.f; + } + + RPUT; +} + + +/* ------------------------ Dust2 ---------------------------------------*/ + +class Dust2_kr: + public flext_base +{ + FLEXT_HEADER(Dust2_kr,flext_base); + +public: + Dust2_kr(int argc, t_atom *argv); + +protected: + void m_set(float f); + Timer Dust2_timer; + void m_doit(); + +private: + float m_density, m_scale; + float mtbt; //medium time between trigger + RGen rgen; + FLEXT_CALLBACK_1(m_set,float); + FLEXT_CALLBACK_T(m_doit); +}; + +FLEXT_LIB_V("Dust2",Dust2_kr); + +Dust2_kr::Dust2_kr(int argc, t_atom *argv) + : Dust2_timer(false) +{ + FLEXT_ADDMETHOD(0,m_set); + + //parse arguments + AtomList Args(argc,argv); + m_density=sc_getfloatarg(Args,0); + + rgen.init(0); //set seed to 0 + AddOutFloat(); + + FLEXT_ADDTIMER(Dust2_timer,m_doit); + + m_set(m_density); +} + +void Dust2_kr::m_set(float f) +{ + Dust2_timer.Reset(); + + if(f==0) + { + return; + } + m_density = f; + mtbt = 1/f*1000; + + Dust2_timer.Delay(mtbt * 0.002 * rgen.frand()); +} + +void Dust2_kr::m_doit() +{ + ToOutFloat(0,2*rgen.frand() - 1 ); + + Dust2_timer.Delay(mtbt * 0.002 * rgen.frand()); +} diff --git a/sc4pd/source/GrayNoise.cpp b/sc4pd/source/GrayNoise.cpp new file mode 100644 index 0000000..8628bca --- /dev/null +++ b/sc4pd/source/GrayNoise.cpp @@ -0,0 +1,137 @@ +/* sc4pd + GrayNoise, GrayNoise~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Keith Rowe: Harsh + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ GrayNoise~ -------------------------------*/ + +class GrayNoise_ar: + public flext_dsp +{ + FLEXT_HEADER(GrayNoise_ar,flext_dsp); + +public: + GrayNoise_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + int m_counter; + RGen rgen; +}; + +FLEXT_LIB_DSP_V("GrayNoise~",GrayNoise_ar); + +GrayNoise_ar::GrayNoise_ar(int argc, t_atom *argv) +{ + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(0); //set seed to 0 + + AddOutSignal(); +} + + +void GrayNoise_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + RGET; + int counter = m_counter; + + for (int i = 0; i!= n;++i) + { + counter ^= 1L << (trand(s1,s2,s3) & 31); + (*(nout)++) = counter * 4.65661287308e-10f; + } + + m_counter=counter; + RPUT; +} + + +/* ------------------------ GrayNoise ---------------------------------*/ + +class GrayNoise_kr: + public flext_base +{ + FLEXT_HEADER(GrayNoise_kr,flext_base); + +public: + GrayNoise_kr(int argc, t_atom *argv); + +protected: + void m_perform(); + +private: + int m_counter; + RGen rgen; + FLEXT_CALLBACK(m_perform); +}; + +FLEXT_LIB_V("GrayNoise",GrayNoise_kr); + +GrayNoise_kr::GrayNoise_kr(int argc, t_atom *argv) +{ + FLEXT_ADDBANG(0,m_perform); + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(0); //set seed to 0 + + AddOutFloat(); +} + +void GrayNoise_kr::m_perform() +{ + m_counter ^= 1L << (rgen.trand() & 31); + m_counter * 4.65661287308e-10f; + ToOutFloat(0,m_counter * 4.65661287308e-10f); +} diff --git a/sc4pd/source/Hasher.cpp b/sc4pd/source/Hasher.cpp new file mode 100644 index 0000000..9fc2f48 --- /dev/null +++ b/sc4pd/source/Hasher.cpp @@ -0,0 +1,122 @@ +/* sc4pd + Hasher~, Hasher + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Philip Jeck: Stoke + +*/ + +#include +#include "support.hpp" +#include "SC_PlugIn.h" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + +/* ------------------------ Hasher~ -----------------------------------*/ + +class Hasher_ar + :public flext_dsp +{ + FLEXT_HEADER(Hasher_ar,flext_dsp); + +public: + Hasher_ar(); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); +private: + +}; + +FLEXT_LIB_DSP("Hasher~",Hasher_ar); + +Hasher_ar::Hasher_ar() +{ + AddOutSignal(); +} + +void Hasher_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + int32 *nin = (int32*)*in; + t_sample *nout = *out; + + for (int i = 0; i!= n;++i) + { + union { float f; int i; } u; + int z = (*(nin)++); + u.i = 0x40000000 | ((uint32)Hash(z) >> 9); + (*(nout)++) = u.f -3.f; + } +} + + +/* ------------------------ Hasher ------------------------------------*/ + +class Hasher_kr + :public flext_base +{ + FLEXT_HEADER(Hasher_kr,flext_base); + +public: + Hasher_kr(); + +protected: + void m_perform(float f); + +private: + FLEXT_CALLBACK_F(m_perform); +}; + +FLEXT_LIB("Hasher",Hasher_kr); + +Hasher_kr::Hasher_kr() +{ + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); +} + +void Hasher_kr::m_perform(float f) +{ + int32 * fi = (int32*) &f; + + union { float f; int i; } u; + int z = *fi; + u.i = 0x40000000 | ((uint32)Hash(z) >> 9); + + ToOutFloat(0,u.f -3.f); +} diff --git a/sc4pd/source/MantissaMask.cpp b/sc4pd/source/MantissaMask.cpp new file mode 100644 index 0000000..d3a867d --- /dev/null +++ b/sc4pd/source/MantissaMask.cpp @@ -0,0 +1,160 @@ +/* sc4pd + MantissaMask~, MantissaMask + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Wolfgang Mitterer: Amusie + +*/ + +#include +#include "support.hpp" +#include "SC_PlugIn.h" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + +/* ------------------------ MantissaMask~ -----------------------------*/ + +class MantissaMask_ar + :public flext_dsp +{ + FLEXT_HEADER(MantissaMask_ar,flext_dsp); + +public: + MantissaMask_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + void m_set(float f); + +private: + FLEXT_CALLBACK_F(m_set); + int32 mask; + +}; + +FLEXT_LIB_DSP_V("MantissaMask~",MantissaMask_ar); + +MantissaMask_ar::MantissaMask_ar(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD_(0,"set",m_set); + + AtomList Args(argc,argv); + int bits = sc_getfloatarg(Args,0); + + AddOutSignal(); + + mask = -1 << (23 - bits); + +} + +void MantissaMask_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + int32 *nout = (int32*)*out; + int32 *nin = (int32*)*in; + + for (int i = 0; i!= n;++i) + { + (*(nout)++) = mask & (*(nin)++); + } +} + +void MantissaMask_ar::m_set(float f) +{ + int bits = (int) f; + if ( bits < 0 || bits > 23) + { + post("value doesn't make sense"); + return; + } + mask = -1 << (23 - bits); +} + +/* ------------------------ MantissaMask ------------------------------*/ + +class MantissaMask_kr + :public flext_base +{ + FLEXT_HEADER(MantissaMask_kr,flext_base); + +public: + MantissaMask_kr(int argc,t_atom * argv); + +protected: + void m_set(float f); + void m_perform(float f); + +private: + FLEXT_CALLBACK_F(m_set); + FLEXT_CALLBACK_F(m_perform); + int32 mask; +}; + +FLEXT_LIB_V("MantissaMask",MantissaMask_kr); + +MantissaMask_kr::MantissaMask_kr(int argc,t_atom * argv) +{ + + AtomList Args(argc,argv); + int bits = sc_getfloatarg(Args,0); + + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD_(0,"set",m_set); + mask = -1 << (23 - bits); +} + +void MantissaMask_kr::m_perform(float f) +{ + float g; + int32 *gp = (int32*) &g; + + *(gp) = mask & *((int32*) &f); + + ToOutFloat(0,g); +} + +void MantissaMask_kr::m_set(float f) +{ + int bits = (int) f; + if ( bits < 0 || bits > 23) + { + post("value doesn't make sense"); + return; + } + mask = -1 << (23 - bits); +} diff --git a/sc4pd/source/Median.cpp b/sc4pd/source/Median.cpp new file mode 100644 index 0000000..77b0a5d --- /dev/null +++ b/sc4pd/source/Median.cpp @@ -0,0 +1,220 @@ +/* sc4pd + Median, Median~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Morton Feldman: For John Cage + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + +/* ------------------------ Median(~) ---------------------------------*/ + + +const int kMAXMEDIANSIZE = 32; + +class median_shared +{ +public: + + inline void Init(long size, float value); + inline float Insert(float value); + +private: + float m_medianValue[kMAXMEDIANSIZE]; + long m_medianAge[kMAXMEDIANSIZE]; + long m_medianSize, m_medianIndex; +}; + +void median_shared::Init(long size, float value) +{ + // initialize the arrays with the first value + m_medianSize = size; + for (int i=0; i>1] + + last = m_medianSize - 1; + // find oldest bin and age the other bins. + for (i=0; i m_medianValue[pos+1]) { + m_medianValue[pos] = m_medianValue[pos+1]; + m_medianAge[pos] = m_medianAge[pos+1]; + pos++; + } + m_medianValue[pos] = value; + m_medianAge[pos] = 0; // this is the newest bin, age = 0 + return m_medianValue[m_medianSize>>1]; +} + + +/* ------------------------ Median~ -----------------------------------*/ + +class Median_ar + :public flext_dsp +{ + FLEXT_HEADER(Median_ar,flext_dsp); + +public: + Median_ar(int argc, t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp (int n,t_signalvec const * insigs, + t_signalvec const * outsigs); + + void m_set(float f) + { + m_size=(int)f; + Median.Init(m_size,Median.Insert(0)); /* this is not beautiful, but i'm not + aware of a nicer way */ + } + +private: + FLEXT_CALLBACK_F(m_set); + + median_shared Median; //median + int m_size; //median size +}; + +FLEXT_LIB_DSP_V("Median~",Median_ar); + +Median_ar::Median_ar(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD_(0,"set",m_set); + + AtomList Args(argc,argv); + m_size=sc_getfloatarg(Args,0); + + AddOutSignal(); +} + +void Median_ar::m_dsp(int n,t_signalvec const * insigs, + t_signalvec const * outsigs) +{ + Median.Init(m_size,0); //how is this done in SuperCollider? +} + +void Median_ar::m_signal(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin = *in; + + for (int i = 0; i!= n;++i) + { + (*(nout)++) = Median.Insert(*(nin)++); + } +} + + +/* ------------------------ Median ------------------------------------*/ + +class Median_kr + :public flext_dsp +{ + FLEXT_HEADER(Median_kr,flext_dsp); + +public: + Median_kr(int argc, t_atom * argv); + +protected: + void m_set(float f) + { + m_size=(int)f; + Median.Init(m_size,Median.Insert(0)); /* this is not beautiful, but i'm not + aware of a nicer way */ + } + void m_perform(float f); + +private: + FLEXT_CALLBACK_F(m_set); + FLEXT_CALLBACK_F(m_perform); + + median_shared Median; //median + int m_size; //median size +}; + +FLEXT_LIB_V("Median",Median_kr); + +Median_kr::Median_kr(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD_(0,"set",m_set); + FLEXT_ADDMETHOD(0,m_perform); + + + AtomList Args(argc,argv); + m_size=sc_getfloatarg(Args,0); + + float m_set=sc_getfloatarg(Args,1); + + Median.Init(m_size,m_set); + AddOutSignal(); +} + +void Median_kr::m_perform(float f) +{ + ToOutFloat(0,Median.Insert(f)); +} diff --git a/sc4pd/source/PinkNoise.cpp b/sc4pd/source/PinkNoise.cpp new file mode 100644 index 0000000..bf6db62 --- /dev/null +++ b/sc4pd/source/PinkNoise.cpp @@ -0,0 +1,168 @@ +/* sc4pd + PinkNoise, PinkNoise~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Gottfried Michael Koenig: Klangfiguren II + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ PinkNoise~ -------------------------------*/ + +class PinkNoise_ar: + public flext_dsp +{ + FLEXT_HEADER(PinkNoise_ar,flext_dsp); + +public: + PinkNoise_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + uint32 m_dice[16]; + int32 m_total; + RGen rgen; +}; + +FLEXT_LIB_DSP_V("PinkNoise~",PinkNoise_ar); + +PinkNoise_ar::PinkNoise_ar(int argc, t_atom *argv) + : m_total(0) +{ + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(0); //set seed to 0 + + for (int i=0; i<16; ++i) + { + uint32 newrand = rgen.trand() >> 13; + m_total += newrand; + m_dice[i] = newrand; + } + + AddOutSignal(); +} + + +void PinkNoise_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + RGET; + uint32 total = m_total; + uint32 *dice = m_dice; + + for (int i = 0; i!= n;++i) + { + uint32 counter = trand(s1,s2,s3); // Magnus Jonsson's suggestion. + uint32 newrand = counter >> 13; + int k = (CTZ(counter)) & 15; + uint32 prevrand = dice[k]; + dice[k] = newrand; + total += (newrand - prevrand); + newrand = trand(s1,s2,s3) >> 13; + uint32 ifval = (total + newrand) | 0x40000000; + (*(nout)++) = ((*(float*)&ifval) - 3.0f); + } + RPUT; +} + + +/* ------------------------ PinkNoise ---------------------------------*/ + +class PinkNoise_kr: + public flext_base +{ + FLEXT_HEADER(PinkNoise_kr,flext_base); + +public: + PinkNoise_kr(int argc, t_atom *argv); + +protected: + void m_perform(); + +private: + uint32 m_dice[16]; + int32 m_total; + RGen rgen; + FLEXT_CALLBACK(m_perform); +}; + +FLEXT_LIB_V("PinkNoise",PinkNoise_kr); + +PinkNoise_kr::PinkNoise_kr(int argc, t_atom *argv) + : m_total(0) +{ + FLEXT_ADDBANG(0,m_perform); + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(0); //set seed to 0 + + for (int i=0; i<16; ++i) + { + uint32 newrand = rgen.trand() >> 13; + m_total += newrand; + m_dice[i] = newrand; + } + + AddOutFloat(); +} + +void PinkNoise_kr::m_perform() +{ + uint32 counter = rgen.trand(); // Magnus Jonsson's suggestion. + uint32 newrand = counter >> 13; + int k = (CTZ(counter)) & 15; + uint32 prevrand = m_dice[k]; + m_dice[k] = newrand; + m_total += (newrand - prevrand); + newrand = rgen.trand() >> 13; + uint32 ifval = (m_total + newrand) | 0x40000000; + + ToOutFloat(0,((*(float*)&ifval) - 3.0f)); +} diff --git a/sc4pd/source/WhiteNoise.cpp b/sc4pd/source/WhiteNoise.cpp new file mode 100644 index 0000000..ecedf3d --- /dev/null +++ b/sc4pd/source/WhiteNoise.cpp @@ -0,0 +1,130 @@ +/* sc4pd + WhiteNoise, WhiteNoise~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Otomo Yoshihide: Ensemble Cathode + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ WhiteNoise~ -------------------------------*/ + +class WhiteNoise_ar: + public flext_dsp +{ + FLEXT_HEADER(WhiteNoise_ar,flext_dsp); + +public: + WhiteNoise_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + RGen rgen; +}; + +FLEXT_LIB_DSP_V("WhiteNoise~",WhiteNoise_ar); + +WhiteNoise_ar::WhiteNoise_ar(int argc, t_atom *argv) +{ + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(0); //set seed to 0 + + AddOutSignal(); +} + + +void WhiteNoise_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + RGET; + + for (int i = 0; i!= n;++i) + { + (*(nout)++) = frand2(s1, s2, s3); + } + + RPUT +} + + +/* ------------------------ WhiteNoise ---------------------------------*/ + +class WhiteNoise_kr: + public flext_base +{ + FLEXT_HEADER(WhiteNoise_kr,flext_base); + +public: + WhiteNoise_kr(int argc, t_atom *argv); + +protected: + void m_perform(); + +private: + RGen rgen; + FLEXT_CALLBACK(m_perform); +}; + +FLEXT_LIB_V("WhiteNoise",WhiteNoise_kr); + +WhiteNoise_kr::WhiteNoise_kr(int argc, t_atom *argv) +{ + FLEXT_ADDBANG(0,m_perform); + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(0); //set seed to 0 + + AddOutFloat(); +} + +void WhiteNoise_kr::m_perform() +{ + ToOutFloat(0,rgen.frand2()); +} diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp new file mode 100644 index 0000000..d7b187b --- /dev/null +++ b/sc4pd/source/main.cpp @@ -0,0 +1,91 @@ +/* sc4pd library initialization + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Phosphor + +*/ + +#include + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + +#define SC4PD_VERSION "0.01" + +void sc4pd_library_setup() +{ + post("\nsc4pd: by tim blechmann"); + post("based on SuperCollider by James McCartney"); + post("version "SC4PD_VERSION); + post("compiled on "__DATE__); + post("contains: Dust(~), MantissaMask(~), Hasher(~), Median(~), " + "BrownNoise(~),"); + post(" ClipNoise(~), GrayNoise(~), Dust2(~), WhiteNoise(~), " + "PinkNoise(~)\n"); + + //initialize objects + FLEXT_DSP_SETUP(Dust_ar); + FLEXT_SETUP(Dust_kr); + + FLEXT_DSP_SETUP(MantissaMask_ar); + FLEXT_SETUP(MantissaMask_kr); + + FLEXT_DSP_SETUP(Hasher_ar); + FLEXT_SETUP(Hasher_kr); + + FLEXT_DSP_SETUP(Median_ar); + FLEXT_SETUP(Median_kr); + + FLEXT_DSP_SETUP(BrownNoise_ar); + FLEXT_SETUP(BrownNoise_kr); + + FLEXT_DSP_SETUP(ClipNoise_ar); + FLEXT_SETUP(ClipNoise_kr); + + FLEXT_DSP_SETUP(GrayNoise_ar); + FLEXT_SETUP(GrayNoise_kr); + + FLEXT_DSP_SETUP(WhiteNoise_ar); + FLEXT_SETUP(WhiteNoise_kr); + + FLEXT_DSP_SETUP(PinkNoise_ar); + FLEXT_SETUP(PinkNoise_kr); + + FLEXT_DSP_SETUP(Dust2_ar); + FLEXT_SETUP(Dust2_kr); + + FLEXT_DSP_SETUP(Crackle_ar); + FLEXT_SETUP(Crackle_kr); +} + +FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); diff --git a/sc4pd/source/support.hpp b/sc4pd/source/support.hpp new file mode 100644 index 0000000..8456f4d --- /dev/null +++ b/sc4pd/source/support.hpp @@ -0,0 +1,80 @@ +/* sc4pd: + support functions + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Phosphor + +*/ + +#include +#include + +#include +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +inline bool sc_add (flext::AtomList a) +{ + for (int i = 0; i!=a.Count();++i) + { + if ( flext::IsSymbol(a[i]) ) + { + const char * teststring; + teststring = flext::GetString(a[i]); + if((strcmp(teststring,"add"))==0) + return true; + } + } + return false; +} + +inline float sc_getfloatarg (flext::AtomList a,int i) +{ + if (a.Count() >0 || a.Count() + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + -- cgit v1.2.1