Random Guitar Tablature

Actionscript:
  1. // number of notes in chord
  2. var noteNum:int = 3;
  3. var lowNote:Number = 0;
  4. var highNote:Number = 4;
  5. // delay between chords
  6. var delay:int = 2000;
  7. ////////////////////////////////////////
  8. var chord:String = "";
  9. highNote += 1;
  10. var tab:TextField = TextField(addChild(new TextField()));
  11. tab.x = tab.y = 20;
  12. tab.defaultTextFormat = new TextFormat("Courier", 12);
  13. tab.multiline = true;
  14. tab.width = 200;
  15.  
  16. changeChord();
  17. setInterval(changeChord, delay);
  18.  
  19. function changeChord():void{
  20.     var strings:Array = [];
  21.     strings[0] = "e|---------------\n"
  22.     strings[1] = "B|---------------\n"
  23.     strings[2] = "G|---------------\n"
  24.     strings[3] = "D|---------------\n"
  25.     strings[4] = "A|---------------\n"
  26.     strings[5] = "E|---------------\n"
  27.    
  28.     for (var i:int = 0; i<3; i++){
  29.         var place:int = 5 + i * 4;
  30.         var choices:Array = [0,1,2,3,4,5];
  31.         for (var j:int = 0; j<noteNum; j++){
  32.             var ii:int = int(Math.random()*choices.length);
  33.             var index:int = choices[ii];
  34.             strings[index] = strings[index].slice(0, place) + (int(Math.random()*highNote)+lowNote) +  strings[index].substring(place+1);
  35.             choices.splice(ii, 1);
  36.         }
  37.     }
  38.     chord = strings.join("");
  39.     tab.text = chord;
  40. }

I'm working on a small program to help me practice guitar. It randomly generates guitar tabs. The idea for the program is similar to a program that helps you learn to type (like Mavis Beacon).

I wrote this snippet today as a proof of concept - just to help me start thinking about what kind of features I want the program to have. There are settings at the top so that you can tweak the number of notes in the chord and the delay between chords etc....

It generates three chords at a time... here are some stills:

This entry was posted in random, string manipulation, strings and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

6 Comments

  1. Posted June 19, 2009 at 2:02 am | Permalink

    Ha! This is brilliant - really looking forwards to your updates on it.
    If it comes together well, I’d like to make it stream from right to left, so you can play along with it - and I’ve been working on midi-out from flash too - so you could have it auto playing along with you. Sounds like a fun project to me :)

  2. Posted June 19, 2009 at 8:50 am | Permalink

    Thanks :) How’s your midi-out stuff coming? I just recently started learning about the structure of the midi file format….

  3. Posted June 20, 2009 at 9:22 am | Permalink

    I’ve got a really basic Flash to midi setup working which I’m quite happy with - but it has a lot of limitations. The main one being, it works through an intermediate processing app - but it’s fun to play with none-the-less.
    Joa Ebert (one of the guys behind the Hobnox Audiotool) has some interesting suggestions if you’re looking into Flash + Midi stuff. In the comments here -
    http://blog.joa-ebert.com/2009/02/11/rasselbock-loves-the-lemur/
    Let me know if you get any midi stuff working - it would be great to see Flash Midi instruments running in browser - or as Air Apps.

  4. Posted June 20, 2009 at 10:09 am | Permalink

    Cool. Makes sense that the audio tool uses java for that… I’ll let you know if I get any midi stuff working… I’m currently interested in reading and writing midi files - writing a midi file should be somewhat easy… reading it and playing it back could be a bit trickier… but this and related pages seem like they may be a good place to start

  5. Posted June 22, 2009 at 3:20 am | Permalink

    Check this out as well – MIDI in Flash http://code.google.com/p/miditoflash/

  6. Posted June 26, 2009 at 8:05 am | Permalink

    Thanks Og2t! I saw this project a while ago, but didn’t realise they had shared the source. Great!

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*