User:Eleanorg/Prototyping Notes 20 Oct 2011

From XPUB & Lens-Based wiki

20 October 2011 Prototyping

FOLK MUSIC, PUBLIC DOMAIN & REMIXING

The mood was set with much tea and a playlist including Noelene Batley - Soldier Soldier (Won't You Marry Me). http://pzwart3.wdka.hro.nl/wiki/Prototyping/Soldier_Soldier_Will_You_Marry_Me

This song, Soldier Soldier, is in the public domain, and lots of different versions have been made. Link to Exquisite Corpse - song itself is repetitive, and there is a repetition (with variation) in the way it's been covered. Folk tradition includes 'talking around' the song with comments & banter - a form of commentary.

Millions of versions on Youtube. Including very creepy puppet-acted nursery rhyme style one.

Folk tradition continued on YouTube. Nothing like this on more self-conscious platforms like Vimeo. But copyright issues are not made explicit. Song is public domain, but each version of it is copyrighted by default.

See recent news of free-trade pacts between US & countries like South Korea, with copyright strings attached (DMCA) Info about how there are no public domain sound recordings in US: http://www.pdinfo.com/record.php

Copyright 'grey zone' a nightmare for archivists, although YouTube's success arguably rests on exploiting & existing within this grey zone.

See their current approach of allowing record companies to exploit pirated copies of songs being posted there, by sharing in advertising revenue.

PROGRAMMING LANGUAGES

'Formal (computer) language' - any language that's not spoken - eg, mathematical or computing. Made for expressing human ideas in a way that can be automatically/mathematically processed. Two main classes of formal languages: Procedural/imparative (ie command form) & Declarative (descriptive form)

  • Imperative languages: BASH, python, php, java, javascript, ruby...

Scripting languages are imperative; they tell the computer what to do. Cooking metaphor: a traditional recipe - 'do these steps'

  • Declarative languages are more descriptive, for example SVG (you're describing the result you want so the computer can 'draw' it.) Other examples are HTML, CSS. Then a browser usually does the dirty of passing explicit instructions to the computer. They tend to be very domain-specific, solving particular problems.

Cooking metaphor: a description of a dinner party, ie a set of constraints, to be interpreted. ('There are two vegans coming, there is tofu in the cupboard...')

PYTHON

You can run python from the terminal and use it like BASH. Or, you can save scripts written in a text editor.print

'expressions' - basic building blocks. Eg, the expression 5 * 2 - this evaluates to 10.

you need to put quotes (double or single) around text, even without whitespace, in Python (and in other modern languages). If a text string includes a single quote, though (eg can't), use double quotes.

Text data has the type 'string' or 'str'. Integers are 'int'.

Assignment of variables

name = "nor" This doesn't return anything to the screen, but assigns "nor" to the variable called name.

Type dir() to see a list of all variables in the memory (including default ones like the word 'help').

Concatenate text using a comma (,). eg: print "hello", name, "how are you"

Line breaks To enter variable data with line breaks in, enclose the whole within three sets of double quotes (""" ... """).

eg: poem = """line one ...: line two ...: line three""" lyric


COPYING & PASTING Ctrl + shift + c = copy Ctrl + shift + v = paste (whenever using the terminal)

exit ipython with Ctrl + d

RUNNING A SCRIPT

  • Save your script as blah.py in the same folder that's your working dir in the terminal.
  • Then run it from the terminal by typing: python blah.py

.py extension is important when using python to run the script (as above), no need to make the file executable.


LOOPS Invariant part repeats without changing. The variable changes.


COMMENTS

  1. at start of line makes a comment

In Gedit you can install a plugin 'code comment' that lets you highlight a secion then type Ctrl + m to comment it out


SYNTATIC INDENTATION

Every time you use a : you must indent the next line by 4 spaces


FOR LOOPS Do an action for each item in a list. Cooking metaphor: For each chocolate in the box, eat it. The program will go through the box and eat each one.


ZIPPING You can attach two lists together to avoid having to make a sepeate loop to go through each one.

So instead of eating all the available treats like this:

for biscuit in (buiscuits):

   eat biscuit

for chocolate in (chocolates):

   eat chocolate

You can scoff them more efficiently like this:

for biscuit, chocolate in zip(biscuits, chocolates):

   eat buiscuit, chocolate

IMPORT

You can import special functions of python that aren't loaded by default if you want to do special things. A good one is 'Random' foo = ['a', 'b', 'c', 'd', 'e'] from random import choice print choice(foo)


MANIPULATING SVGs WITH PYTHON Python can manipulate natural languages like English, but it can also manipulate other formal languages like XML. You can generate SVG in the same way that scripts generate, for example, HTML pages dynamically on the web.

see Michael's 'variable television' logo Lots of variations on a single SVG generated by a python script uses LXML library - for querying xml documents. Eg, 'go get all the rectangles and do x with them' The script grabs the SVG, manipulates the XML, then spits out a new SVG.

You can also install a python script as a function in Inkscape, and process the SVG with a click according to that script.

XML SYNTAX

In Inkscape you can edit an image with XML using Edit > XML editor (or SHift + Ctrl + X) Similar to HTML:

...

tag<tag name> content of tag </end of tag>

You can also add attributes: <rect style="blah">....</rect>

As with HTML you can also use <rect style=.... /> all in one tag

Whitespace not important But syntax is strict. When you try to open an SVG in a browser, you'll get an error message with a line number. Look around the line no., especially above it, to find the error.

Command-line tool xmllint will help you debug with more detailed error messages.

LOOKING AT XML OF AN SVG CODE


Make a shape in Inkscape, then change its id using the XML editor. Scan the document for the important bits - eg, the id of the shape you've created.


Paste XML code into a python file and make it into a script which just prints the code:

print """xml code bollox"""

Now when you run this script it will print the XML code to the terminal. But you can also redirect it, printing the code to a file:

python xml.py > mysvg.svg

This will create a file that you can open in a browser

for x in range(100):

range(90, 100) (ninety to 100) range(90, 100 2) (ninety to 100, every 2nd number only)



STRING FUNCTIONS

.format Newish in python, another way of calling items from a list. Unlike the normal way of assigning variables at the start and then calling them, here you call them, and then define them at the end:

print "hello {0} nice {1}".format(nor, hat)

{0} is the 0th index of the list given in brackets at the end, {1} the first, etc. It comes out as: hello nor nice hat


for x in range(100):

   print """
   <rect
      style="fill:#aa0000"
      id="seedrect"
      width="{0}"
      height="411.42856"
      x="148.57143"
      y="220.93361" />

""".format(x)


Here you're using range(100) to count from 0 to 99 (counting to 100 in computer-land) For x in range prints a rectangle on each number - so you get 100 rectangles. Then the .format(x) at the end adds some magic. It corresponds to the variable within the text {0}. This means to use the 0th value in the list in brackets at the end. There's only one thing in the list (x), so it uses that. This means that each time a rectangle is created as the script loops, its width will be taken from the current number. So you end up with 100 rectangles of different sizes.


Of course you can make things more interesting by changing the current number, for example by multiplying it to create a new number:

for x in range(100):

   print """
   <rect
      style="fill:#aa0000"
      id="seedrect"
      width="{0}"
      height="411.42856"
      x="148.57143"
      y="220.93361" />

""".format(x * 9)

...or even multiplying it by a random number. Just include import: random

at the top of your script. Then use the random numbers in the list using random.random() like this:

for x in range(100):

   print """
   <rect
      style="fill:#aa0000"
      id="seedrect"
      width="{0}"
      height="411.42856"
      x="148.57143"
      y="220.93361" />

""".format(x * random.random())


THOUGHTS FOR FURTHER EXPERIMENTATION


Folk tradition continued with coded remixing Apply to sea shanties? How can they be interestingly processed using tools from this session? Random function probably not that useful. But which functions would mirror or mimic the traditional treatment these songs would undergo? Link to ocean as a geographical public domain where works are remixed by sailors singing? maybe try using ffmpeg to make a gif to refresh earlier session with aymeric