public static void Main() { //Set interuppt Button.OnInterrupt += new NativeEventHandler(ButtonPushed); //Looping while (true) { //Reload the Queue -- Not exactly efficient but it's just for fun if(SongQueue.Count < 1) { SongQueue = Playlist.GetQueue(); } //Check to see what stat our play variable is at based on switch press if (IsPlay) { CurrentSong = (Song)SongQueue.Dequeue(); Play(); Thread.Sleep(2000); } else { Thread.Sleep(100); } } }
/********************************************************* * I ported some of this code from a open source C arduino library to c# / Netduino * http://code.google.com/p/rogue-code/source/browse/Arduino/libraries/Tone/trunk/examples/RTTTL/RTTTL.pde * *********************************************************/ public Song GetSong() { Song song = new Song(this.Beat, this.Duration); song.Notations = new ArrayList(); //used for parsing the current section char[] charParserArray; //quarter note unless specified int defaultDuration = 4; //middle c octave int defaultOctave = 6; int durationParseNumber = 0; int currentDuration = 0; int currentScale = 0; int currentNote = 0; foreach (string myNote in this.Notes) { charParserArray = myNote.ToCharArray(); //start parsing a note entry for (int i = 0; i < myNote.Length; i++) { durationParseNumber = 0; currentNote = 0; currentDuration = 0; currentScale = 0; // first, get note duration, if available while (i < charParserArray.Length && isdigit(charParserArray[i])) { //construct the duration durationParseNumber = (durationParseNumber * 10) + (charParserArray[i++] - '0'); } if (durationParseNumber > 0) { currentDuration = durationParseNumber; } else { currentDuration = defaultDuration; } // c is first note i.e. c = 1 // b = 12 // pause or undefined = 0 if (i<charParserArray.Length) { switch (charParserArray[i]) { case 'c': currentNote = 1; break; case 'd': currentNote = 3; break; case 'e': currentNote = 5; break; case 'f': currentNote = 6; break; case 'g': currentNote = 8; break; case 'a': currentNote = 10; break; case 'b': currentNote = 12; break; case 'p': currentNote = 0; break; default: currentNote = 0; break; } } i++; // process whether the note is sharp if (i<charParserArray.Length && charParserArray[i] == '#') { currentNote++; i++; } // is it dotted note, divide the duration in half if (i < charParserArray.Length && charParserArray[i] == '.') { currentDuration += currentDuration / 2; i++; } // now, get octave if (i < charParserArray.Length && isdigit(charParserArray[i])) { currentScale = charParserArray[i] - '0'; i++; } else { currentScale = defaultOctave; } //offset if necessary currentScale += OctaveOffset; //add the note by calculating it's location in the RTTTL note array, scale/octave offsets are by 12 notes song.Notations.Add(new Notation((uint)RTTTLNotes[(currentScale - 1) * 12 + currentNote], (uint)currentDuration)); } } return song; }