fluxamasynth examples

Post your projects. Pictures, code, and bragging welcome.
stevecooley
Posts: 24
Joined: Mon Aug 24, 2009 12:20 pm

fluxamasynth examples

Post 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++;
}






oz
Site Admin
Posts: 542
Joined: Mon May 12, 2008 4:19 pm

Re: fluxamasynth examples

Post by oz »

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

stevecooley
Posts: 24
Joined: Mon Aug 24, 2009 12:20 pm

Re: fluxamasynth examples

Post 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?

stevecooley
Posts: 24
Joined: Mon Aug 24, 2009 12:20 pm

Re: fluxamasynth examples

Post 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.

stevecooley
Posts: 24
Joined: Mon Aug 24, 2009 12:20 pm

Re: fluxamasynth examples

Post 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?

stevecooley
Posts: 24
Joined: Mon Aug 24, 2009 12:20 pm

Re: fluxamasynth examples

Post 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

oz
Site Admin
Posts: 542
Joined: Mon May 12, 2008 4:19 pm

Re: fluxamasynth examples

Post by oz »

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

stevecooley
Posts: 24
Joined: Mon Aug 24, 2009 12:20 pm

Re: fluxamasynth examples

Post by stevecooley »

Awesome! I eagerly await for some news on this. Thanks, Paul!

Post Reply