Page 1 of 1

fluxamasynth examples

Posted: Sat Apr 23, 2011 5:03 pm
by stevecooley
Sigh. This shield is pretty cool. The example code is a bit thin. So, here's a sketch that plays a bunch of random notes, as it steps through the different sounds the fluxamasynth can play.

Code: Select all

#include "Fluxamasynth.h"

Fluxamasynth synth;

int counter = 0;
int channel = 0;
int voice = 0;
int j = 0;

void setup() {
  Serial.begin(31250);
  synth.programChange(0, 9, 40);
  synth.programChange(0, 1, 0);
}

void loop()
{

  while(counter < 128)
  {
    if(voice >128)
    {
      voice = 0;
    }

    synth.programChange(channel, 0, voice);



    for(int i=0; i<10; i++)
    {

      int note = int(random(36,100));

      synth.noteOn(channel, note, 127); 

      int coinflip = int(random(0,20));

      if(coinflip == 5)
      {
        while(j < 200)
        {
          synth.pitchBend(channel, j);
          j+= 16;
          delay(10);
        }
        j = 0; 
      }

      delay(100);
      synth.noteOff(channel, note);
    }

    voice++;

  }
  channel++;
  counter++;
}






Re: fluxamasynth examples

Posted: Sun Apr 24, 2011 8:57 am
by paul
Thanks Steve,

We'll put it up in the wiki.

http://wiki.moderndevice.com/

There are some user pages under Fluxamasynth - feel free to put up other sketches if you cook up other interesting things

Paul

Re: fluxamasynth examples

Posted: Tue Apr 26, 2011 3:09 am
by stevecooley
Okidoke. Will do. :) I've been trying to get the software serial theory into practice, without any luck. Just looking at the Fluxamasynth.cpp file, I can see that it's calling "Serial" for all of its commands. Is that going to be hard coded to the hardware serial device? I don't know much about how this works, but if I wanted to use a different serial device, like the software serial device, wouldn't I need to pass a reference for which serial device to make the function calls to?

Re: fluxamasynth examples

Posted: Tue Apr 26, 2011 3:11 am
by stevecooley
Maybe when the fluxamasynth object is being created, pass in which serial device I want it to work with? Just stabbing at science here. I barely speak english, and zero c++... so feel free to edify me. Please edify me, I mean.

Re: fluxamasynth examples

Posted: Tue Apr 26, 2011 1:54 pm
by stevecooley
Ok, right, so... software serial doesn't have a "write" function, so that's not going to work as-is. I can see that softwareserial has a print function, and seemingly with a BIN converter, but ... I don't know how to handle the buffer length parameter with software serial. Any clues?

Re: fluxamasynth examples

Posted: Tue Apr 26, 2011 2:05 pm
by stevecooley
Am I on the right track here? I can see the buffer length matches the string of commands lined up, so if I break each of the commands into its own mySerial.print(command1,BIN); does that get me to functional parity as what the hardware serial is doing? Here's the first few lines of the fluxamasynth.cpp file converted with my "stabbing at science" method. I'm posting it up here so hopefully you can stop me or correct me before I go through and change the rest of the file... if I'm wrong, I don't want to spend a lot of time on being wrong. So.. I'll wait to hear back before proceeding further.

Code: Select all

#include "WProgram.h"
#include "Fluxamasynth.h"
#include <SoftwareSerial.h>


Fluxamasynth::Fluxamasynth() {

    SoftwareSerial mySerial =  SoftwareSerial(5, 4);
    mySerial.begin(31250);

}

void Fluxamasynth::noteOn(byte channel, byte pitch, byte velocity) {
    // here's the old command:
    // byte command[3] = { 0x90 | (channel & 0x0f), pitch, velocity };
    // Serial.write(command,3);

    // here's my best guess at how I'd do this with softwareserial
    mySerial.print(0x90 | (channel & 0x0f), BIN);
    mySerial.print(pitch, BIN);
    mySerial.print(velocity, BIN);  
}

... et cetera ... 
for reference, here's software serial's print command : http://www.arduino.cc/en/Reference/SoftwareSerialPrint
and hardware Serial's write command : http://www.arduino.cc/en/Serial/Write

Re: fluxamasynth examples

Posted: Wed Apr 27, 2011 9:15 pm
by paul
Steve,

What you are doing with software serial will certainly work, but it's a bit of coding though. The right place to do this is in the library and we're currently merging in some customer code that does this (uses software serial) Check the wiki in a week or so.

Paul

Re: fluxamasynth examples

Posted: Mon May 02, 2011 4:56 pm
by stevecooley
Awesome! I eagerly await for some news on this. Thanks, Paul!