Thursday, November 22, 2007

iTunes Cache

So my MacBook's partition map got screwed up yesterday. I'm pretty well backed up, so instead of recovering I decided to just start over from scratch. My biggest issue is dealing with music- I only have a 60GB hard drive, like 30GB of music, and Tiger is somehow like 15GB. With everything else I'm usually between 1GB and 4GB of free space. 

I instead of copying my whole library back over, I set up a simple music cache with Automator and Python.

Working on the premise that I'm most likely to listen to music I've already listened to, the Automator script copies the current track from my external drive to the directory "~/Music/Local Cache/".

I wrote a Python script to run the Automator script every 30 seconds. 

#! /usr/bin/env python
import os
import time

while(1):
  os.popen4("automator '~/Music/iTunes Cache/Scripts/iTunesCache.workflow'")
  time.sleep(30)


Named it "iTunes Launcher.py" and saved it in "~Music/iTunes Cache/Scripts/" along with "iTunesCache.workflow"

Made it executable, changed the icon, and placed it in the dock:

Run iTunes from the launcher, and your current songs are cached. The Automator script is set to load each copied song into the playlist "Local Cache." This places the song in my library twice, the local and external versions, so I can go back later and remove references to the external drive using iTunes "Show Duplicates" feature.

Friday, November 16, 2007

Touchpad + Arduino + Cocoa + Quartz, Part 2

Touchscreen -> Arduino -> USB -> Cocoa (AMSerial, modified) -> Quartz






Touchscreen -> Arduino -> PWM. Controlling a light source with the single axis, instead of the 3d cube.


Touchpad + Arduino + Cocoa + Quartz

I bought a LCD off eBay about a year ago with a 4 wire touchscreen. Unfortunately, I'm unable to find the LCDs specs, but I'm still able to use the touchpad. One axis of the touchscreen is connected to the Arduino, which performs input, smoothing, and serial output. I modified the AMSerial Cocoa application from "Harmless Cocoa" ( http://www.harmless.de/cocoa.php ) to control a Quartz viewer with the incoming serial data.


The Cocoa application. I am a little unclear on USB drivers and how the AMSerial software works, so the Arduino application must be open with the serial monitor running in order to function. Right now this project is in the 'It works but I'm not really sure why' stage.


The touchscreen circuit. I'll post schematics and references later. Only one axis is configured.


Snippet of code converts serial data (0 to 1024) to NSString representation of degrees, then sends data to the qcPatchController.
// data is NSData object taken from serial port. Converted to float
// for rotation
NSString* rotString = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];

float rotVal = [rotString floatValue]/1024*400;

// Only accept rotation values between 0 degrees and 400 degrees
// Reduces trackpad and serial read errors, since
// 0 <= rotVal <= 400.

if(rotVal > 0 && rotVal < 400)
{
rotString = [NSString stringWithFormat:@"%f",rotVal];
[qcController setValue:rotString forKeyPath:@"patch.yrot.value"];
lastRotVal = rotVal;
}


Arduino Single Axis Touchscreen Code (singleaxistouchpad.c)

Arduino Touchpad (modified AMSerial) xCode project