Processing, Minim, and Music

I recently discovered Processing. It’s a programming language and programming environment, based on Java, designed for artists, particularly those with an interest in what is sometimes called “generative art.” While Processing’s main focus is visual art, it includes a sound/synthesis library, Minim, which lets you programmatically tinker with audio and synthesis.

Creating audio with Processing takes me way back to the Atari 400 I got for Christmas one year, with which I managed to, hamfistedly but joyfully, create various noise makers including a decent drum machine.

I decided to give Processing a try and quickly found Dan Ellis‘s page of sample code, which included a nice little sine-wave piano, which I stole, extended a bit, and share with you here:

I do this with permission from Dan, who has moved on from Processing and now likes to do things in Pd, which is an open source branch of Max.

There is, these days, a version of Processing reimplemented in JavaScript called Processing.js, but, in my tests at least, there’s no support for audio. So, sorry that I had to resort to the Processing IDEs Java Applet export. Performance is better if you run it straight from the Processing IDE, of course. And there’s a link to the source if you want to give that a whirl (or hack your own).

Keyboard layout is simple. The Z-row is a C major scale. The A-row is the same, one octave up. The Q-row plays the major or minor third, relative to the root note below it in the A- and Z- rows. The number row plays the perfect fifth for the same. So, as a diatonic instrument, there are no wrong notes. And you can easily play major and minor chords or intervals by pressing keys in any vertical column. Make sure you don’t have caps lock on, as I’ve only defined the lower case characters so far.

Popularity: 4% [?]

Applying Excel Subtotals with VBA

Excel’s subtotal option (Data –> Subtotal) lets you display a subtotal on any number of columns for each change in a particular column. This is useful for sheets where each day, for instance, might have multiple entries recording some bit of data, and you want subtotals for each day giving you the sum, or the min, or max, or some other aggregate. Say you have something like this visit-tracking data, sorted by Date:

If you choose Data –> Subtotal, you get this dialog, which you use to define which column Excel should check for changes, and which column(s) should get a subtotal, and what sort of subtotal it should be (e.g. SUM, COUNT, AVERAGE, MAX, MIN, etc.):

After pressing the OK button and adjusting column widths, your sheet looks like this:

You can see that Excel adds subtotal lines for each change in date, as well as a grand total line at the bottom. If you single-click B5, B9, B13, and B14, you’ll see that Excel has written SUBTOTAL() functions for each of the three ranges created by the changes in the Date column, and has applied the same function to the entire range to get the grand total.

You can turn them back off by opening the Subtotal dialog a second time and clicking the Remove All button instead.

That’s handy, but wouldn’t it be handier to turn this on and off via VBA? I thought so, and it’s pretty easy to do. Fire up the VBA Editor (Developer –> Code –> Visual Basic), double-click the sheet which contains your data (e.g. Sheet1) from the Project Explorer on the left, and create two subroutines. The first, AddSubs() will turn on the subtotals. A second, RemoveSubs() will turn turn them off. Here is the code for AddSubs():

Sub AddSubs()
    Worksheets("Sheet1").Activate
    Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(2)
End Sub

It’s pretty simple. You can see that the worksheet is specified by name in the second line. In the third line, the GroupBy value (i.e. 1), is used to specify the column where Excel should look for changes. In VBA, the columns are numbered from left to right. So 1 is Column A, our Date column. The TotalList array specifies the columns which should get a subtotal. So 2 is Column B, our Visits column. If you have more than one of them, just separate each number with a comma (e.g. Array(2, 3)). The Function parameter tells Excel what sort of subtotal to create. You feed it one of several contants (e.g. xlSum, xlMin, xlMax, etc.).

Turning subtotals off is equally easy. So long as you get the worksheet name right, you should be in business. Here’s the code for RemoveSubs():

Sub RemoveSubs()
    Worksheets("Sheet1").Activate
    Selection.RemoveSubtotal
End Sub 

To use either one, click your mouse inside any of the cells that contain your data (here, any cell in the A1:B10 range) choose Developer –> Code –> Macros, select the macro from the list, and press the Run button.

Popularity: 6% [?]

HTML5 Converter for Adobe Captivate

I’m a fan of both Apple and Adobe, which puts me in rather an odd place at times. Apple makes the hardware and operating systems I like best. Adobe makes some software that I can’t live without. Up until now, a lot of what I create with Adobe Captivate won’t play on the iPhone and iPad, since Apple sees HTML5 as the future and doesn’t support Flash on its mobile devices. 1

Following Microsoft’s recent announcement that Internet Explorer 10 will not support plugins (including Flash) when running in its new Metro style, opting, as Apple has done, to embrace HTML5 as the future, the question becomes, where does Adobe fit into all of this?

I’ve long thought that the way forward for Adobe is to retool its apps to support HTML5 output. With respect to Adobe Captivate–the tool I use most in my work–I’m happy to say they’ve made substantial strides in this direction. For the past few weeks, I’ve been beta-testing Adobe’s Captivate-to-HTML5 converter. And the initial testing has been so promising that Adobe is now offering it on Adobe Labs so it can reach a wider testing audience. Is it perfect? Of course not. But I do like it and I’m very happy that Adobe is heading this direction, because I like building things in Adobe Captivate and Flash Professional.

[Updates:]

The Adobe Captivate Blog has a post about the HTML 5 converter and some samples of converted projects.

Popularity: 9% [?]

Notes:

  1. I feel that Apple has both good and bad reasons for not supporting Flash, but that’s a topic for another post, and probably one that will never get written, as it has become something of a moot point.

Where is the Excel Personal Macro Workbook Located?

Sometimes I blog things mostly so I can remember them and in the off chance that they might be useful to others. This post falls into that category. If you use Microsoft Excel, and you have a macro that you want to be available globally–in any open workbook–you can place it in your Personal Macro Workbook, which is just an Excel Workbook (in binary, XLSB, format, for speed) that lives at a particular location, where Excel will look for it whenever it launches.

On Windows 7, it lives here: 1

C:\Users\AppData\Roaming\Microsoft\Excel\XLSTART\PERSONAL.XLSB

On Windows 7, it lives here:

C:\Documents and Settings\Application Data\Microsoft\Excel\XLSTART\PERSONAL.XLSB

In either case, the easy way to create PERSONAL.XLSB is not to muck around with the file system directly. Instead, just record a macro in Excel and, when you’re prompted to save it, choose Personal Macro Workbook from the Store Macro In drop-down menu on the Record Macro dialog box. Record yourself typing a few numbers and adding some formatting to them or something similar. Afterwards, you can open up the Personal Macro Workbook via the Visual Basic button on the Developer tab later and delete whatever you record. Once you create it, your Personal Macro Workbook will be listed in the VBA Editor as “VBAProject (PERSONAL.XLSB)”.

Some Additional Details for the Truly Nerdy

The location of the Personal Macro Workbook is a little confusing, because older versions of Excel stored it in an XLSTART folder buried inside the Program Files folder. Even though you can’t write any files to it, Excel 2007 and Excel 2010 also have XLSTART folders inside the Program Files directory. Here are the paths:

For Excel 2010:

C:\Program Files\Microsoft Office\Office14\XLSTART\

For Excel 2007:

C:\Program Files\Microsoft Office\Office12\XLSTART\

“Office 14″ is the internal name for Office 2010. It’s actually the 13th version of Office, but Microsoft saw fit to skip naming it Office 13, due, one suspects to superstition. So “Office 12″ is Office 2007, “Office 11″ is Office 2003, and so on. If you happen to be stuck running Excel 2003 on a Windows XP box, you’ll find PERSONAL.XLSB at this path:

C:\Program Files\Microsoft Office\Office11\XLSTART\

.

Popularity: 39% [?]

Notes:

  1. If there’s no Roaming directory in your setup, use Local instead. The rest of the path will remain the same.

How to Show All Files in the OS X Finder

When you’re doing development work on an OS X box and need to shuttle your files to a web server, you’ll notice that the Finder (OS X’s equivalent of Windows Explorer) hides “dot files” like the all-important .htaccess files used by many web applications. You can tell the Finder to show you all files, including all invisible ones, by typing this string into the terminal and pressing return. Case is significant:

defaults write com.apple.Finder AppleShowAllFiles YES

You have to relaunch the finder to make it take effect. There are few ways to do that. One is to choose Force Quit from the Apple menu (or press Command-Option-Esc), select Finder from the list of running applications, and click the Relaunch button (you’ll be asked if you’re sure, requiring you to press a second Relaunch button). Another way is to hold the Option key, then click and hold the Finder icon in the Dock, then choose Relaunch from the context menu. 1

To reverse it, so that you (or your wife, or kid, or pet) don’t accidentally delete something, you repeat the same command, but substitute NO at the end, like this:

defaults write com.apple.Finder AppleShowAllFiles NO

As before, you’ll have to relaunch the Finder for the changes to take effect.

Popularity: 14% [?]

Notes:

  1. Still another is to hold down both Control and Option, click the Finder icon in the Dock, and choose Relaunch from the context menu.