{ "metadata": { "name": "Va pensiero iPython client" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": "# Tarmo Johannes, Toshihiro Kita \"V\u00e1, pensiero\" - interactive network piece\n# iPython client for sending Csound code to Csound(6) server via TCP\n\n\nimport socket\nTCP_IP = '54.228.204.118' # 'localhost' # 'johannes.homeip.net'\nTCP_PORT = 5005 #30100\nBUFFER_SIZE = 1024\nNAME = \"YOUR_NAME\"\n\ndef sendTCP(sendString):\n\ts = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n\ttry:\n\t\ts.connect((TCP_IP, TCP_PORT))\n\texcept socket.error:\n\t\tprint \"Connection error. Maybe the server is not running\"\n\t\treturn\t\n\ttry:\n\t\ts.send(sendString)\n\texcept socket.error:\n\t\tprint \"Send error\"\n\t\treturn\n\n\ttry:\n\t\tdata = s.recv(1024) # TODO: test if data==sendString\n\texcept socket.error:\n\t\tprint \"Receive error\" # the message is either OK, Csound error or if the message was comment (\";something to say,, not compile\"), echoes the comment\n\t\treturn\n\tprint data", "language": "python", "metadata": {}, "outputs": [], "prompt_number": 44 }, { "cell_type": "code", "collapsed": false, "input": "sendTCP(\";name \"+NAME) # send your name first in the form \";name YOURNAME\"", "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": ";name YOUR_NAME\n" } ], "prompt_number": 40 }, { "cell_type": "code", "collapsed": false, "input": "# instruments of the test choir of va_pensiero_orc.csd\n# Copy and paste any of them to next cell, change it and send the change\ninstruments = '''\n\n; CHOIR ==========================\n\n; SOPRANOS:\n; these are just test instruments now. Later they will be replaced with the instruments written by participants\n\n; event_i \"i\",\"S1_1\",0,3,0.3,440, 0.5\ninstr S1_1\n\tiamp = p4 ; NB! iamp must be calculated - for how many players there are!\n\tifreq = p5\n\tipan = p6\n\tkenv madsr 0.1,0.1,0.4,0.5\n\t\n\tasig vco2 iamp*kenv, ifreq\n\taout butterlp asig, expsegr(ifreq*8,1,ifreq*2,0.5,ifreq*1.5)\n\taL,aR pan2 aout, ipan\n\touts aL, aR \nendin\n\n; event_i \"i\",\"S1_2\",0,0.5,0.3,440, 0.5\ngiGrainEnv ftgen 0,0,1024, 20, 2\ngkDens init 2000\ninstr S1_2 \n\t\n\t\n\tiamp = p4 ; NB! iamp must be calculated - for how many players there are!\n\tifreq = p5\n\tipan = p6\n\tkenv linenr iamp,0.25,0.1,0.01\n\t\n\tkgdur line 0.01,1,0.05 \n\taout grain 0.004, ifreq, gkDens, 0.005, 10000, kgdur, -1,giGrainEnv, 1 \n\t\n\t\n\taL,aR pan2 aout, ipan\n\touts aL, aR \nendin\n\n; event_i \"i\",\"S2_1\",0,1,2,440, 0.5\ninstr S2_1\n\tiamp = p4 ; NB! iamp must be calculated - for how many players there are!\n\tifreq = p5\n\tipan = p6\n\tkenv madsr 0.1,0.1,0.8,0.5\n\t\n\tasig vco2 iamp*kenv, ifreq\n\taout rezzy asig, expsegr(ifreq*8,0.25,ifreq*4,0.5,ifreq*8),40 ; expsegr(ifreq*8,0.25,ifreq*2,0.5,ifreq*1.5)\n\taL,aR pan2 aout, ipan\n\touts aL, aR \nendin\n\n; event_i \"i\",\"S2_2\",0,1,0.3,440, 0.5\ngkCx init -0.5\ninstr S2_2 ; bass\n\t\n\tiamp = p4 ; NB! iamp must be calculated - for how many players there are!\n\tifreq = p5\n\tipan = p6\n\tkenv linenr iamp,0.1,0.5,0.01\n\t\n\t;aout foscil kenv,ifreq,1,linsegr(1.5,0.25,1.25,0.2,1),linsegr(2,0.1,6,0.5,2),-1\n\tkrx line 0.1,1,0.5\n\tawterr wterrain kenv, ifreq,gkCx, 0, krx/2, krx, -1,-1\n\taout dcblock awterr\n\t\n\taL,aR pan2 aout, ipan\n\touts aL, aR \nendin\n\n; ALTOS --------------\n; event_i \"i\",\"A1\",0,1,0.3,440, 0.5\ngkVibrRate init 8\ngkVibrAmp init 1.9;0.5\ninstr A1\n\t\n\tiamp = p4 ; NB! iamp must be calculated - for how many players there are!\n\tifreq = p5\n\tipan = p6\n\tkenv linenr iamp,0.1,0.5,0.01\n\ta1 poscil kenv, ifreq, -1\n\ta2 poscil kenv*gkVibrAmp,ifreq+gkVibrRate,-1 ; beatings 4 Hz\n\taL,aR pan2 a1+a2, ipan\n\touts aL, aR \nendin\n\n\n; TENORS\n; event_i \"i\",\"T1_1\",0,1,0.3,220, 0.5\ngkTilt init 50\ninstr T1_1\n\tiamp = p4 ; NB! iamp must be calculated - for how many players there are!\n\tifreq = p5\n\tipan =p6\n\tkenv linenr iamp, 0.25,0.5, 0.01\n\tasig fmvoice kenv, ifreq, 1+int(rnd(6)), gkTilt, 0.005, 5, -1,-1,-1,-1,-1\n\taL,aR pan2 asig,ipan\n\touts aL, aR \nendin\n\n; event_i \"i\",\"T2_1\",0,1,0.3,220, 0.5\ninstr T2_1\n\tiamp = p4 \n\tifreq = p5\n\tipan = p6\n\tkenv madsr 0.05,0.05,0.4, 0.3\n\tasig wgbow kenv*iamp,ifreq,expsegr(5,0.05,3,0.1,1),0.125,6,iamp*0.01,-1\n\taL,aR pan2 asig,ipan\n\touts aL, aR \nendin\n\n; BASSES\n; event_i \"i\",\"B1\",0,1,0.3,110, 0.5\ninstr B1\n\tiamp = p4 ; NB! iamp must be calculated - for how many players there are!\n\tifreq = p5\n\tipan = p6\n\tkenv madsr 0.05,0.1,0.6,0.3\n\tasig pluck kenv*iamp,ifreq,ifreq,0,1\n\taout butterlp asig, ifreq*3\n\taL,aR pan2 aout, ipan\n\touts aL, aR\nendin\n\n; event_i \"i\",\"B2\",0,1,0.3,110, 0.5\ngkFMIndex init 1.25\ninstr B2\n\tiamp = p4 ; NB! iamp must be calculated - for how many players there are!\n\tifreq = p5\n\tipan = p6\n\tkenv linenr iamp,0.25,0.1,0.01\n\t\n\taout foscil kenv,ifreq,1,gkFMIndex,linsegr(4,0.25,2,0.5,1),-1\n\t\n\taL,aR pan2 aout, ipan\n\touts aL, aR \n\t\nendin\n\n; event_i \"i\",\"B3\",0,1,0.3,110, 0.5\ninstr B3\t\n\tiamp = p4 ; NB! iamp must be calculated - for how many players there are!\n\tifreq = p5\n\tipan = p6\n\tkenv linenr iamp,0.1,0.5,0.01\n\t\n\taout foscil kenv,ifreq,1,linsegr(1.5,0.25,1.25,0.2,1),linsegr(2,0.1,6,0.5,2),-1\n\t\n\taL,aR pan2 aout, ipan\n\touts aL, aR \nendin\n\n\n'''", "language": "python", "metadata": {}, "outputs": [], "prompt_number": 8 }, { "cell_type": "code", "collapsed": false, "input": "# this a instrument of test_orc.csd\n# you may add also new instruments but then program also executing them wtih event_i, scoreline_i or other way\n\ntest_instr = '''\n\n;event_i \"i\",100,0,1, 0.3, 400 ; test sound\ngiSine ftgen 0, 0, 4096, 10, 1, 0.5, 0.3, 0.1 ; ftable for pluck\ngkBend init 1\ninstr 100 ; sound\n\tmidinoteoncps p5, p4\n\tiamp = (p4<1)? p4 : p4/127 ; score amplitude 0..1\n\ticps = p5\n\tprint icps, iamp\n\t;kenv linenr iamp, 0.05,0.1,0.5\n\tkenv madsr 0.1,0.1,0.8,0.5\n\tasig pluck iamp*kenv,icps,icps,giSine,1\n\touts asig,asig\nendin\n\n'''\n", "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": "Connection error. Maybe the server is not running\n" } ], "prompt_number": 9 }, { "cell_type": "code", "collapsed": false, "input": "# send some Csound code from here\n# you can completely rewrite these instruments, if you like\n\nsendTCP('''\n;put the code here\n''')", "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": "\n;put the code here\n\n" } ], "prompt_number": 16 }, { "cell_type": "code", "collapsed": false, "input": "#an example for test orchestra\nsendTCP(''' \ngiSine ftgen 0, 0, 4096, 10, 1,0.8, 0.6, 0.5\nscoreline_i {{i 100 0 1 0.3 220 }}\n''')\n", "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": "OK\n" } ], "prompt_number": 43 }, { "cell_type": "code", "collapsed": false, "input": "sendTCP(\"scoreline_i {{i \\\"S1_1\\\" 0 1 0.1 315 0.5}}\")\n", "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": "OK\n" } ], "prompt_number": 41 }, { "cell_type": "code", "collapsed": false, "input": "sendTCP(\"scoreline_i {{i 1 0 1 0.1 200 }}\")", "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": "OK\n" } ], "prompt_number": 30 }, { "cell_type": "code", "collapsed": false, "input": "", "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }