Refactoring No Clergy
Posted by kev Sat, 15 Oct 2005 20:54:40 GMT
Kevin Baird
What is No Clergy?
Live, generative music for a small ensemble
Influences (Earlier Open-Form Pieces)
- Karlheinz / Piano
- Earle Brown: Available Froms I & II / Small Ensemble
Setup
- Performers read music via web browser
- Equivalent of turning written pages is a web page refresh
- The conductor is a bash script
(Sample of trumpet and violin musical score pages)
2nd and Later Pages
- The audience has access to web forms in the concert space. The audience is able to modify pitch, direction, volume, etc. for the various characteristics. They can express how strong their conviction is. “I mean it, damnit!” or “Take it with a grain of salt.”
- Web forms are specific to each instrument I should mention that I wanted web forms because i serves a useful aesthetic and functional performance. People are familiar with web browsers, and it is easy for people to bring laptops to the concert space in order to participate.
Markovian transformations are used. A marko chain is a data set that is a derivation of some previous data set. The new data set bears a strong resemblance to the original set, but is a new set. It’s used for things like modeling a (shakespeare play?) The point of using it here is so that the new page of notation is similar to the original. That makes it not terribly interesting for the second page, but by the third page, it gets interesting.
(Sample pages of trumpet and violin musical scores with audience having asked for fewer notes, or more intensity for each instrument).
- By the second page, instruments are already starting to diverge
Originally written in Python
The piece was originally written in Python. Scores, measure, and notes are used. A sound or silence event is defined. A struct keeps the state.
Data formats & output
The output is stored in MusicXML. It renders notation output via Lilypond, which renders LaTeX to PDF or other output formats.
Why Ruby?
- Flexibilit of Perl without the kludges and ugliness
- Real access control and scope
- Ruby’s specific take on blocks and iterators
- Influence of Lisp, although not aware at the time
- Open Classes vs. Paul Graham’s On List
- Also mentioned in Agile Web Development With Rails
- Self-education
Why Refactor?
- Had started informal code. It was a mess and so I said, “Why not refactor it and do it in Ruby?”
The Changes: Ruby vs. Python
- Differences…
- Culture not just technical features
- Thanks to Hal Fulton for The Ruby Way
- Much heavier use of boolean predicates… e.g. has_something?
- Rdoc encouraged much better documentation
Substitute Algorithm
Patterns
- Merge a superclass and a subclass together
- Collapse Hierarchy moves superclasses and subclasses together. this was developed in a very ad hoc process. I tried to visualize how I would generate the initial pages vs. the subsequent pages.* Extract Interface – Move conceptually similar methods into a separate module *The most horrible name in the project is “tupplable” which refers to a musical term.
- Extract Method – Break a larger code fragment into separate methods
- I broke a lot of methods up. In the note class, I had a notation for rendering the output. I broke it up into a public method and several privates representing the notes, pitch, etc.
- Extract Superclass / Pull up method – Move methods into a superclass
- I made a new parent class called HasSound that represents the ….
Various instruments have this thing called transposition. I used this as a class variable and many things I had used as an instrance variable became class variables, and occasionally symbolic constants.
- Replace Array with Object – Create Object from Array with dissimilar contents
Replace Magic Numbers with Sumbolic Constants
- I also have a hash that also reads the full name from the abbreviation
Encapsulate Field / Self Encapsulate Field - Make a public variable private and createa accessors
- Separate Query from Modifier – Isoloate methods that either return a value or change a state
Conclusions
Future Plans
- Continue some refactoring. Dynamics are only meaningful for notation and should be proken out in case I am not producing output for notation.
- Eliminate bash wrapper scripts, convert to pure Ruby. Thankfully, I followed Matz suggestion to learn some Lisp and SmallTack, it was useful in understanding Ruby.
- Make transformations and XML storage facilities avaliable as general libraries
- Implement transformation unrelated to audience feedback. Blend some styles.
- Python good / Ruby better (for me)
I care about encapsulation
- Good design in itself
- Practical benefits for headspace issues
- Aided by having Real Access
Ruby’s openness, flexibility and transparency made each Refactoring easier and cleaner
- Perl taught me to hate sigils
- Ruby taught me to love them again
Q & A
Speaker: I’d like to ask the audience about Packaging, inclined to package once its ready.
Q: Do you have any recordings of what this sounds like live? A: I don’t have any with me, the audio quality isn’t great. I found that focusing on output gives me a niche… and I love that everything you hear isn’t just blowing out of a wooden tube from a hundred years ago or something like that.
David Black: I’d say it’d be good to release as a gem. If it requires lillypond, then it requires lillypond.
Q: I’m a trumpet player, and I was wondering if there would be an option to say how much they hate a specific musician? Is there a way to make sure that the music is not too physically difficult to play (for the performers)? A: I’ve talked to my advisior, and is it aesthetically and conceptually correct to limit what gets output to what is physically playable? What if something comes out that is logistically unplayable? Well, do your best. You’re the elected official. This will be highly dependent on your performers.
Q: Just what you said about the playability and all that… just the concept of constraints. I’ve wondered if you’ve considered adding the ability to add constraints, something like that? A: I’m somewhat reluctant to do too much on that, because I want to give the audience a lot of freedom in an environment where they haven’t had it before. When something impossible happens, that’s when… alright make the trumpet’s a little higher and the … a little lower.
Q: You really seem to be into refactoring; have you noticed a relation between the way how you think about the structure of a software program and how you think about the structure of a piece of music? A: That’s a really interesting question. I think I’m more inclined to do it with code… and obviously people will disagree… [with code] it’s closer to saying this is the right way to do it and this is the wrong way to do it… but with music I find it a lot more subjective. Q2: Refactoring is, as far as I know, changing how something happens without changing what the final outcome is, whereas in music the output is different once you’ve changed something. A2: We can argue about this later
Q: Why the name? A: It’s not an anti-religioius… musical professionals could be seen as a type of clergy. I had an earlier pice called no cathedral. This is a logical extension of that… so how could I make it more anti-clerical than that? Get rid of the clerics. It’s a metaphor.
Q: Speaking as someone who’s performed a bit of contemporary music, I wonder what the reaction has been by the audience?
A: Generally it has been very good, but with that there is a caveat: I could only get other composers to perform this for me.
One thing I should mention about the notation is that the sound of the music is identical, but the beat marks are….So that would be an improvement in presentation. That would help in that regard. A: I hear good things about smalltalk. Actually, last weekend I started learning about smalltalk and lisp. Actually, I
Q: How many people have used a refactoring browser before? How many people miss it in Ruby?
Even in the lobby last night, I was not changing things because it was painful to change things in more than one place. I was lazy, or I din’t have a refactoring browser. If anyone is interested, I would love to get this started. [Matt Shelleburty]
Q: This is another question about the packaging… you presented it earlier as an iether/or… why is that? (Debian/ruby). A: I’m lazy. Q: A: That’s a good point, and that’s the ideal solution. Yeah, that’d be the way to go probably. Q: That’s the way gems work, I’ve worke din Debian mostly. You might look in to (…) [Stephanie]
Q: Mine was in response to the refactoring guy’s question. Things to point out is what environment you’re working in. Things like RDT which I don’t use because it brings your machine to a crawl. I think a bunch of people started, tried to put it in FreeRIDE… I don’t know if that would be possible. If anyone is interested in putting it in Emacs.
Q: Just a clarification on that too… one thing that furstrates me on that too… theres’ so many smart people that have spread themselves out. [missed a lot here] I’d rather do code than GUI anyway.
Q: I apologize in advance to continuing to steal your thunder on this refactoring thing. But since the topic came up. I’m one of the founders of the FreeRide IDE project, along with Rich Kilmer. I’m very interested in getting refactoring support in FreeRIDe. []’s got problems. Enough problems that we actually removed it from FreeRide. If there’s people that are interesteed in working on it and bringin it up to snuff, I’d be really interested in talking about it. Thanks.
Q: How big of a role did Unit Testing play in refactoring? And second, I didn’t understand why you ditched PYthon.
A: With regard to the changeover, I knew I wanted to do a substantial re-write. I was learning Ruby at the time, and everything I learned about it I thought ‘why did I learn Python’? Fortuitous coincidence in time I guess.


Great notes. Thank you.
Some minor clarifications: Karlheinz’s last name is Stockhausen
“tupplable” is “Tupletable”
“isn’t just blowing out of a wooden tube” should be “is just blowing out of a wooden tube” – I appreciate that I’m doing computer music that depends on old technology for the actual sound.
These are extremely minor points. Thanks very much for taking and posting such excellent notes.
Slides should be up at http://www.zenspider.com/Languages/Ruby/ soon.