Archive for Unsolicited advice

Panslation

I wanted to see something translated into everything, for some reason; the code below does it okay. You need a UTF-8-capable console like Terminal on OS X, or redirect to a file and view it in a browser. Example:

$ CLASSPATH=.:google-api-translate-java-0.8.jar java Panslate "unbelievably interesting"
sq: unbelievably interesante
ar: المثيرة للاهتمام
bg: невероятно интересно
ca: increïblement interessant
zh: 令人难以置信的有趣
zh-CN: 令人难以置信的有趣
zh-TW: 令人難以置信的有趣
hr: nevjerojatno zanimljiv
cs: neuvěřitelně zajímavé
da: utroligt interessant
nl: ongelooflijk interessant
en: unbelievably interesting
et: äärmiselt huvitav
tl: unbelievably kagiliw-giliw na
fi: uskomattoman mielenkiintoista
fr: incroyablement intéressante
gl: incrible interesante
de: unglaublich interessant
el: απίστευτα ενδιαφέρον
iw: מעניין שלא תיאמן
hi: अविश्वसनीय दिलचस्प
hu: Hihetetlenül érdekes
id: luar biasa menarik
it: incredibilmente interessante
ja: 信じられないほど面白い
ko: 엄청 재미
lv: neticami interesanti
lt: neįtikėtinai įdomūs
mt: unbelievably interessanti
no: utrolig interessant
fa: unbelievably جالب
pl: niesamowicie ciekawe
pt: incrivelmente interessante
ro: incredibil de interesant
ru: невероятной интересно
sr: невероватно занимљиво
sk: neuveriteľne zaujímavé
sl: Neverjetno zanimivo
es: increíblemente interesante
sv: Otroligt intressant
th: น่าเหลือเชื่อ
tr: inanılmaz ilginç
uk: неймовірною цікаво
vi: không ngờ thú vị

You’ll need google-api-translate-java. Here’s the Java code:

import java.io.PrintStream;
import java.net.InetAddress;
import com.google.api.translate.Language;
import com.google.api.translate.Translate;

public class Panslate {
  public static void main(String[] args) throws Exception {
    PrintStream out = new PrintStream(System.out, true, "UTF-8");
    Translate.setHttpReferrer(InetAddress.getLocalHost().getHostName());
    for (Language target : Language.values()) {
      if (target == Language.AUTO_DETECT) continue;
      String translatedText = Translate.execute(args[0],
                                                Language.ENGLISH,
                                                target);
      out.println(target + ": " + translatedText);
    }
  }
}

Comments

GHWT & Rock Band MIDI Filter for Drums

Mildly unsatisfied with my earlier, more obvious solution for using an electronic drum kit to play Guitar Hero World Tour (that is, just changing a few MIDI note settings), I’ve put together a solution I like better – a microcontroller which filters the MIDI signal between the drum kit sound module and the GHWT controller.

The advantages are these:

  • The hi-hat pedal serves the proper function in the game, in that the pedal, rather than velocity, distinguishes an open from closed hi-hat hit.
  • No need to mess with the MIDI settings of the drum sound module (so it’s more portable & flexible, and less invasive).
  • Cuter

The drum sound module (Roland TD-3 in my case) feeds into a MIDI IN circuit connected to an Arduino microcontroller, which adjusts the MIDI data appropriately, then sends it on to MIDI out, where the GHWT controller is connected. This “appropriate” adjustment to which I refer is just the remapping of certain MIDI note numbers so that, for example, the yellow pad can be triggered by both the edge and the bell of the hi-hat. In addition, the velocity of just hi-hat hits is replaced with a value based on the position of the hi-hat pedal. The details of the necessary mappings are evident in the code below or in yonder spreadsheet.

Three AAA batteries provide power (held together with electrical tape, with heavy oven pan foil providing the electrical connections – changing the batteries will be a bit inconvenient). I was hoping it could be powered just by drum sound module through the MIDI IN connector, but there doesn’t seem to be enough current to power the circuit and the MIDI OUT. Or very possibly, I didn’t sufficiently isolate the MIDI IN circuit from the rest of the circuit; but this goes beyond my electronics knowledge. However, I did use the MIDI IN power to toggle a relay to switch on the battery power, thus saving me the trouble of switching it on, and, worse, forgetting to switch it off. As long as it is plugged into a switched-on drum module, it’s on. You just plug it in and forget it and that works beautifully.

The Arduino clone I used is an RBBB from Modern Devices, which is small enough to fit. I power the Arduino directly on the +5V bus (albeit with only 4.5V); thus the power jack and voltage regular can be omitted and trimmed off the board. I also left a bunch of other stuff off – all that was needed were the two 0.1μF caps, the 10kΩ resistor, the resonator, the reset switch, the programming header, and the microcontroller chip (sans socket, to save room). This is connected to the other (MIDI, LED & relay) circuitry via the programming header (plus one wire to pin D3).

As is traditional with DIY electronics projects, it is housed, after some effort to miniaturize, in an Altoids tin. I did spray paint the tin orange for aesthetics. Also, it’s actually a Hershey’s Cacao Reserve tin, which is the same size, but doesn’t have “Altoids” stamped into the top, and has better tasting contents. A slightly larger container would be better, since with this one the MIDI cords have to be awkwardly plugged into the bottom of the tin.

One LED shows that the board is powered up – I used a biggish 2.2kΩ resistor to dim it. Another LED indicates when note on/off messages are received, which is helpful for troubleshooting and looks cool. The brightness is proportional to the note velocity. One could add 6 LEDs in the appropriate colors to indicate notes on each controller pad, but I didn’t.

Here is a schematic:


(the resistor I forgot to label off of D3 is 220Ω.)

And here’s the Processing sketch (why in hell are they called “sketches” rather than programs?) that makes it all happen:

// Read MIDI messages from a TD-3 drum cotroller, modify them for use with GHWT,
// and pass them thru
//
// Hookups:
// - MIDI in circuit on pin RX/D0 (& +5V & Gnd)
// - MIDI out circuit on pin TX/D1 (& +5V & Gnd)
// - LED on pin 13 and/or 3
//
// GHWT MIDI note numbers
// kick 	36  purple
// snare 	38  red
// hi-hat 	46  yellow
// hi tom 	48  blue
// ride 	49  orange
// low tom 	45  green

void setup() {
  Serial.begin(31250);  // MIDI uses this odd serial rate
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  pinMode(3, OUTPUT);
  digitalWrite(3, LOW);
}

// MIDI messages received are decoded into these globals (which isn't kludgey;
// it's the right thing to do, I hereby declare)
int midiStatus = 0;           // most recent status byte
int midiMessageOffset = 999;  // offset from status byte
int midiChannel;              // channel given in status byte
int midiMessageType;          // message type given in status byte
int midiNote;                 // note number in most recent note on/off

// Hi-hat velocities are determined by the pedal being open or closed, since
// that's usually what this represents in the game (but if velocity is
// zero, leave it alone)
int SOFT = 63;   // Half strength
int HARD = 127;  // Full strength

void loop() {
  if (Serial.available()) {

    int midibyte = Serial.read();

    ++midiMessageOffset;

    if (midibyte >= 0x80) {
      // Status byte
      midiStatus = midibyte;
      midiMessageOffset = 0;
      midiNote = 0;
      midiMessageType = midiStatus >> 4;
      midiChannel = midiStatus & 0xF;
    }
    else if(midiStatus == 0x99 || midiStatus == 0x89) {
      // Percussion note-on or -off

      if (midiMessageOffset & 1) {
        // Note number
        midiNote = midibyte;
        switch (midibyte) {
        case 22:  // hi-hat clsd, edge
        case 26:  // hi-hat open, edge
        case 42:  // hi-hat clsd, bow
        case 52:  // crash 2 edge
        case 57:  // crash 2 bow
          midibyte = 46;
          break;
        case 40:  // snare rim
          midibyte = 38;
          break;
        case 41:  // tom 3
          midibyte = 45;
          break;
        case 51:  // ride bow
        case 53:  // ride edge
        case 55:  // crash 1 edge
          midibyte = 49;
          break;
        }
      }
      else {
        // Velocity
        if (midiMessageType == 0x9 && midibyte > 0) switch (midiNote) {
        case 22:  // hi-hat clsd, edge
        case 42:  // hi-hat clsd, bow
          midibyte = SOFT;
          break;
        case 26:  // hi-hat open, edge
        case 46:  // hi-hat open, bow
          midibyte = HARD;
          break;
        }
      }

    }

    Serial.write(midibyte);

    // Update an LED to show notes when we see the velocity byte
    if (((midiMessageOffset & 1) == 0) &&
        (midiMessageType == 0x9 || midiMessageType == 0x8)) {
      // Light up the traditional pin D13 to show activity
      digitalWrite(13, (midibyte == 0 ||
                        midiMessageType == 0x8) ? LOW : HIGH);
      // ...and use pin D3 to indicate velocity by brightness
      analogWrite(3, (midiMessageType == 0x8) ? 0 : midibyte * 2);
    }
  }
}

I’ll mention that due to my poor soldering skills, plus the fact that I didn’t realize I had poor soldering skills, made this sucker take me a long time to put together and debug. Once I got in there with a loupe, the problem was evident. “Problems”, I should say.

Comments

Real(ish) Drums for Guitar Hero World Tour

I jumped through a lot of hoops to try to use my Roland V-Drums in place of the Rock Band drum controller, with unsatisfying results. Guitar Hero World Tour makes it awfully easy though – the controller has a MIDI IN port. If you plug it, it will play, but it can also be easily be improved upon. In a nutshell, I mapped other pads so they could also be used, and, more importantly, mapped both the rim and head of each pad so you don’t have to hit a particular part to trigger.

I assigned the pads as illustrated here:

The perhaps controversial and/or innovative idea was to reverse the crash cymbals from the more obvious left-right configuration. I did this because orange is used for crashes when the right hand is on the hi-hat, and yellow is when the right hand is riding the ride, and in real life, you’d use the crash closest to hand. I’m trying to get as close to playing the actual drum part as possible here.

Whether to assign the middle tom to blue or green is matter of preference, I suppose.

To program my drum module, a Roland TD-3, I chose a kit I didn’t mind scrambling the MIDI numbers on, then hit EDIT > CONTROL and arrowed to the note number setting. The settings are summarized here:

Pad Color Instrument MIDI Note MIDI Instrument
red snare 38 SNR:H02 SNR:R02
yellow hi-hat 46 HH:H03 HH:R03 CR2:H10 CR2:R10
blue hi tom 48 T1:H04
orange ride 49 RD:H11 RD:R11 CR1:H09 CR1:R09
green low tom 45 T2:H05 T3:H07
purple kick 36 KIK:H01

Note that you have to keep your foot off the hi-hat pedal. (Or unplug it.) (Or assign to note number 50 and always keep your foot on it.)

Comments (3)

Feeding Google Talk status into Twitter

I don’t really get Twitter, or rather I only sort of do. I never got MySpace. I feel like I almost do now, but not quite. (Is it even still around?) I halfway get Facebook. I think email is great. Given all these facts you could probably calculate my exact age.

In any case, so that I can use Twitter without ever getting it, I thought my Google Talk status messages should feed into Twitter. They can and it’s easy.

  1. In FriendFeed: [Share something] → [Import] → [Gmail/Google Talk]

  2. In TwitterFeed (should the site happen to be up): [Create new twitter feed] using the URL http://friendfeed.com/api/feed/user/USERNAME?format=rss Include the title only, do not include the link.

Comments (2)

Backpacking

I’m off to the Olympics tomorrow for a 3-day (2 night) trip, my first solo. My goal is for an ultralight pack (<10lbs per certain rules), but I guess I missed it by 3 lbs. Here’s my comprehensive gear list (with weights), and here’s some thoughts about equipment choices that cohered for me.

Comments

Drum part for Tomorrow Never Knows

The drum part for Tomorrow Never Knows (the Beatles’ song – not the imaginary James Bond movie of the same name) runs thus:

Rd |x---x---x---x---|
Sn |----o-----------|
Tm |----------oo----|
Bd |o-----o-o-------|
   |1 + 2 + 3 + 4 + |

Comments (1)

Solids

i has a karot

Comments

Booking flights

Here’s what I’ve settled on for air travel.

Start with Expedia or Orbitz which work well and have all the options. If your search isn’t too complex, you might try Qixo before you buy. Its UI sucks, is much less flexible, and is incredibly slow…but it sometimes finds flights Expedia doesn’t. Travelocity’s UI is frustrating and they use popunders – don’t bother with it.

If I find something, I sometimes go right to the airline and buy the ticket from them, not to save $5, but to avoid the situation where the travel site and airline pass the buck to each other in case of changes to be made.

Search the “discount” airlines like Southwest separately since they aren’t included in any of the travel sites. Nowadays the major airlines are worse experiences than these “no-frills” ones, if they have your route. I use Southwest when I can because I don’t have to worry about fees for changing or not using tickets, kind of like the way the world should be.

In terms of comfort in economy class, Southwest, AA and United (only if you pay for Economy Plus) are a little better. Continental and Northwest are a little worse.

Comments

His Reading Materials

I read a good article in the New Yorker about Philip Pullman wherein he disses CS Lewis and JRR Tolkien. Not because they have initials for first names, but because they provide no useful moral lessons in their books. He feels this is the job of books, and that religion is therefore not as neccessary as some folks think, IIRC. In any case it inspired me to read his His Dark Materials, an excellent story. It’s a Yearling book so it’s a little embarassing to haul around, but worth the pain, unlike that Harry Potter drivel. I think “book for kids” means: the prose isn’t too flowery and doesn’t search for cool obscure words, and the story’s about kids coming of age right in front of your face. Rating: READ IT

I love a good Raymond Chandler, and High Window is no slouch. Representative quote: “You two are as cute as a couple of lost golf balls.” Rating: READ IT

That same New Yorker had an article about Knut Hamsun. Hamsun would be revered if he wasn’t such a Nazi, his apparently sympathy for whom doesn’t come through in his writing, I’m happy to report and Pan is great stuff. (It’s also on Project Gutenberg, but that’s probably the old, puritanized translation.) Its very reminiscent of Celine, who was also a Nazi and also an excellent author, who wrote with the same exuberance that made the author seem schitzoid, unless you understand it to reflect the turmoil of your own thought rather than the edited end product we see presented by others. Rating: READ IT (and that goes for Celine too)

I can’t believe I didn’t read the Elric saga back when I was into Conan. I guess it was loyalty to Robert E Howard. But Moorcock’s stories are better written, compelling and epic, and should be read by everybody with some geek in their blood. It’s a little tricky to put the series together since it’s out of print in its proper form, so here’s what to read, in order (but I’ll let you dig up the Amazon links, except to say that these white ones work fine):

  1. Elric of Melnibone
  2. The Sailor on the Seas of Fate
  3. The Weird of the White Wolf
  4. The Vanishing Tower
  5. The Bane of the Black Sword
  6. Stormbringer

I confess, however, that I’m only halfway through the list. Rating: READ IT while listening to BÖC

Comments