Fluxamasynth Arduino Library Reference

Modern Device >>

Download the latest version of the library from Github at https://github.com/fluxly/Fluxamasynth.

The Command Set

Fluxamasynth()
Fluxamasynth(byte rxPin, byte txPin)
fluxWrite(byte c)
fluxWrite(byte *buf, int cnt)
noteOn(byte channel, byte pitch, byte velocity)
noteOff(byte channel, byte pitch)
programChange(byte bank, byte channel, byte voice)
pitchBend(byte channel, int velocity)
pitchBendRange(byte channel, byte velocity)
midiReset()
setChannelVolume(byte channel, byte level)
allNotesOff(byte channel)
setMasterVolume(byte level)
setReverb(byte channel, byte program, byte level, byte delayFeedback)
setChorus(byte channel, byte program, byte level, byte feedback, byte chorusDelay)

noteOn()

 


This function sounds the given MIDI note on the specified channel (0..15) or “voice” with which to play the note. Assign an instrument to the voice with programChange(). A velocity of 0 is the same as noteOff().

Syntax

noteOn(channel, pitch, velocity)

Parameters

  • Channel: A byte specifying the channel (0-15). Values greater than 15 will wrap around.
  • Pitch: A byte between 0 and 127 indicating the pitch. 60 = middle C (C4) = 261.63Hz. For note values see Table 4.
  • Velocity: A value between 0 and 127 indicating the attack of the note. On a keyboard this corresponds to how hard the key was struck. A velocity of 0 is the same as noteOff().

Example

#include <Fluxamasynth.h>

Fluxamasynth synth = Fluxamasynth();
void setup() { synth.setMasterVolume(255); } void loop() { for (int note=60; note<85; note++) { synth.noteOn(0, note, 100); delay(200); synth.noteOn(0, note, 0); // Be sure to turn the note off! } }

noteOff()

 


Turns off the note in the specified channel that was previously turned on with a noteOn() command at the given pitch.

Syntax

noteOff(channel, pitch)

Parameters

  • Channel: A byte specifying the channel (0-15). Values greater than 15 will wrap around.
  • Pitch: A byte between 0 and 127 indicating the pitch. 60 = middle C (C4) = 261.63Hz. For note values see Table 4.

Example

#include <Fluxamasynth.h>

Fluxamasynth synth = Fluxamasynth();
void setup() { synth.setMasterVolume(255); } void loop() { for (int note=60; note<85; note++) { synth.noteOn(0, note, 100); delay(200); synth.noteOff(0, note); synth.noteOn(1, note, 100); synth.noteOn(1, note+3, 100); synth.noteOn(1, note+7, 100); delay(200); synth.noteOff(1, note); synth.noteOff(1, note+3); synth.noteOff(1, note+7); } }

programChange()

 


Changes the program (instrument) for the specified channel. Channel 9 is a special drumset channel; see the drum sound table in (Table 3). Drumsets can be also be assigned to other channels (see SYSEX MIDI channel to part assign and part to rhythm allocation).

Syntax

programChange(bank, channel, voice)

Parameters

  • Bank: Either bank 0 (see Table 1) or bank 127 (see Table 2). Bank 127 is also called the MT-32 sound bank.
  • Channel: A byte specifying the channel (0-15). Values greater than
    15 will wrap around.
  • Value: A byte

Example


#include <Fluxamasynth.h>Fluxamasynth synth = Fluxamasynth();
byte instrument = 0; void setup() { synth.setMasterVolume(255); } void loop() { for (int note=60; note<85; note++) { synth.programChange(0, 0, instrument); synth.programChange(0, 1, instrument); synth.noteOn(0, note, 100); delay(200); synth.noteOff(0, note); synth.noteOn(1, note, 100); synth.noteOn(1, note+3, 100); synth.noteOn(1, note+7, 100); delay(200); synth.noteOff(1, note); synth.noteOff(1, note+3); synth.noteOff(1, note+7); instrument = (instrument+1) & 127; } }

pitchBend()

Bends the pitch up or down, with a default swing of +/- 1 semitone. The range can be changed using pitchBendRange(). The value is a number between 0 and 1023, where 512 is the center point (no bending).

Syntax

 void pitchBend(channel, value)

Parameters

  • Channel: A byte specifying the channel (0-15). Values greater than
    15 will wrap around.
  • Value:A number in the range 0 to 1023, where 0 is bent to the low end of the range and 1023 bends to the maximum.

Example

#include 

Fluxamasynth synth;

int i = 512;                   // middle of pitch bend range

void setup()
{
  synth.programChange(127, 0, 91);
  synth.pitchBendRange(0, 4);  //double the pitch bend sensitivity (4 semitones)
  synth.noteOn(0, 62, 127);
}

void loop()
{
  while (i < 1023)             // loop to upper bound of pitch bend range
  {
    synth.pitchBend(0, i);
    i+= 16;
    delay(10);
  }

  while (i > 0)                // loop to lower bound of pitch bend range
  {
    synth.pitchBend(0, i);
    i-= 16;
    delay(10);
  }
}

pitchBendRange()

 


Sets the pitch bend sensitivity in semitones (default = 2 semitones, -1 to +1). The maximum pitch bend is +/-1 whole tone.

Syntax

pitchBendRange(channel, value)

Parameters

  • Channel: a byte specifying the channel (0-15). Values greater than
    15 will wrap around.
  • Value:a byte

midiReset()

 


Reset to power-up condition.

Syntax

midiReset()

Parameters

    none

setChannelVolume()

 


Sets the volume for a particular channel.

Syntax

setChannelVolume(channel, level)

Parameters

  • Channel: A number in the range 0-15
  • Level: A number in the range 0-127 specifying the volume level (0 = silent)

Example

#include <Fluxamasynth.h>

Fluxamasynth synth = Fluxamasynth(); int tone1 = 53; int tone2 = 61; int vol1 = 64; // volumes must be inverses of eachother int vol2 = 127 - vol1; // or they'll get out of sync int i = 1; // step size int dir = 1; // direction to step in: 1 = up, -1 = down void setup() { Serial.begin(31250); synth.programChange(0, 0, 90); // give our two channels different voices synth.programChange(0, 1, 89); synth.setChannelVolume(0, vol1); // set their volumes synth.setChannelVolume(1, vol2); synth.noteOn(0, tone1, 127); // turn on a note for each channel synth.noteOn(1, tone2, 127); } void loop() { while (vol1 > i && vol1 < (127 - i)) // loops while in valid volume range { delay(20); vol1+= i * dir; // vol1 increments by i in direction dir vol2 = 127 - vol1; // vol2 is always the inverse synth.setChannelVolume(0, vol1); // update volumes synth.setChannelVolume(1, vol2); } dir*= -1; // once volumes reach bounds, reverse dir vol1+= i * dir; // increment once in new direction int vol2 = 127 - vol1; // to ensure volumes are back in range }

setMasterVolume()

 


Sets the volume for all channels.

Syntax

setMasterVolume(level)

Parameters

  • Level: A number in the range 0-127 specifying the volume level (0 = silent)

allNotesOff()

 


Sends a noteOff() for every note on a specified channel.

Syntax

allNotesOff(channel)

Parameters

  • Channel: A number in the range 0-15

Example

#include <Fluxamasynth.h>

Fluxamasynth synth = Fluxamasynth(); // create our synth int i = 0; // i detirmines what note // of the chord we're on int lastNote; const int OCTAVE_RANGE = 12; // number of semitones in an octave const int lowestTone = 48; // low end of note range const int minInterval = 2; // smallest interval allowed, in semitones const int chordSize = 4; // number of notes per chord const int delayTime = 300; // time to delay between notes const int channel = 0; // channel number to use const int instrument = 25; // instrument to use for our channel void setup() { Serial.begin(31250); // Set MIDI baud rate: synth.programChange(channel, 0, instrument); randomSeed(analogRead(0)); // seed random with arbitrary analog noise } void loop() { int note; // note to play if (i == 0) // if this is first note of chord { // mute all notes of previous chord synth.allNotesOff(channel); // note is a random tone in our range note = lowestTone + random(OCTAVE_RANGE); } else // otherwise, { // note is a random interval above last note // (between minInterval and OCTAVE_RANGE) note = lastNote + random(OCTAVE_RANGE - minInterval) + minInterval; } lastNote = note; // play note synth.noteOn(channel, note, 127); i = (i + 1) % chordSize; // increment i // (loop between 0 and chordSize) delay(delayTime); }

setReverb()

 


Description

Applies a reverb effect to a specified channel.

Syntax

setReverb(channel, program, level, delayFeedback)

Parameters

  • Channel: A number in the range 0-15
  • Program:
    0: room1
    1: room2
    2: room3
    3: hall1
    4: hall2
    5: plate
    6: delay
    7: pan delay
    
  • Level: A number in the range 0-127
  • DelayFeedback: If using program 6 or 7, this specified the feedback level.

Example

/* 
 * DrumPatternPlayer
 * A drum machine for the Modern Device Fluxamasynth Shield
 * 
 * https://moderndevice.com/product/fluxamasynth-shield/
 * https://github.com/moderndevice/Fluxamasynth-Shield
 *
 * By Michel Gutlich 26-2-2011 
 * A sensor signal on analog input 0 gives some tempo dynamics
 * Contact at iching@xs4al.nl
*/

#include 

# define bass 36              // Define midi note numbers for several GM drum sounds
# define snare 38
# define hihatC 42
# define hihatP 44
# define hihatO 46

Fluxamasynth synth;		// create a synth object

/* **** Our drum pattern ***/
int patternSize = 16;         // A pattern of max 16 ticks ( actualy 15, because we loop and 16 is tick no. 1....you dig it ? )

// Every array cell is the velocity of the note played 
// Tick         1   2   3   4   5   6   7   8   9  10  11  12  13  14  15

int bd  [] = {127,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 90,  0}; //Bassdrum
int sn  [] = {  0,  0,  0,  0,127,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}; //Snare
int hho [] = {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,127,  0}; //Hihat Open
int hhc [] = {127, 40, 80, 40,127, 40, 80, 40,127, 40, 80, 40,127,  0,  0}; //Hihat Close
int hhp [] = {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,127}; //Hihat Pedal

// * Some basic settings */
int channel = 9;              // MIDI channel number
int tempo = 120;              // Start tempo

/*     */
int tickNo;                   // Our tick number variable

void setup() {

  synth.midiReset();            // Do a complete MIDI reset

  //setReverb( channel , program , level , feedback , delayFeedback )
  // Program 
  // 0: Room1   1: Room2    2: Room3 
  // 3: Hall1   4: Hall2    5: Plate
  // 6: Delay   7: Pan delay
  synth.setReverb(channel,5,255,100); // A Plate Reverb with maximum effect level

  synth.setChannelVolume(channel, 127); // max. channel volume
  synth.setMasterVolume(255);	// max. master volume
}

void loop() {
  for(int tickNo; tickNo < patternSize; tickNo++)
  {
    tempo = tempo + (random(5) - 2);  // random walk
    tempo = constrain(tempo, 40, 250);
    bassDrm(bd[tickNo]);
    snareDrm(sn[tickNo]);
    hihatClose(hhc[tickNo]);
    hihatOpen(hho[tickNo]);
    hihatPedal(hhp[tickNo]);
    tick();    
  }
} 

// Maybe it looks a bit overdone to send both velocity 0 note On and note Off information
// It saves some memory NOT to check for double note Off information...ah well..

void bassDrm (int vel )
{
 synth.noteOn(channel, bass, vel);      // play a note
 synth.noteOff(channel, bass);         // send note off
}

void snareDrm (int vel)
{
 synth.noteOn(channel, snare, vel);	// play a note
 synth.noteOff(channel, snare);         // send note off

}

void hihatClose (int vel )
{
 synth.noteOn(channel, hihatC, vel);	// play a note
 synth.noteOff(channel, hihatC);        // send note off 
}

void hihatPedal (int vel)
{
 synth.noteOn(channel, hihatP, vel);	// play a note
 synth.noteOff(channel, hihatP);        // send note off   
}

void hihatOpen (int vel )
{
 synth.noteOn(channel, hihatO, vel);	// play a note
 synth.noteOff(channel, hihatO);        // send note off 
}

void tick ()
{
 delay(tempo);
}

Applies a chorus effect to a specified channel.

Syntax

setChorus(channel, program, level, feedback, chorusDelay)

Parameters

  • Channel: A number in the range 0-15
  • Program:
    0: Chorus 1
    1: Chorus 2
    2: Chorus 3
    3: Chorus 4
    4: Feedback
    5: Flanger
    6: Short Delay
    7: Feedback Delay
    
  • Level: A number in the range 0-127
  • DelayFeedback: If using program 6 or 7, this specified the feedback level.

 

Table 1: MIDI program numbers for bank 0. Assign sounds to a channel with the ProgramChange() function.

 

1 Acoustic Grand Piano

2 Bright Acoustic Piano

3 Electric Grand Piano

4 Honky-tonk Piano

5 Electric Piano 1

6 Electric Piano 2

7 Harpsichord

8 Clavinet

9 Celesta

10 Glockenspiel

11 Music Box

12 Vibraphone

13 Marimba

14 Xylophone

15 Tubular Bells

16 Dulcimer

17 Drawbar Organ

18 Percussive Organ

19 Rock Organ

20 Church Organ

21 Reed Organ

22 Accordion

23 Harmonica

24 Tango Accordion

25 Acoustic Guitar (nylon)

26 Acoustic Guitar (steel)

27 Electric Guitar (jazz)

28 Electric Guitar (clean)

29 Electric Guitar (muted)

30 Overdriven Guitar

31 Distortion Guitar

32 Guitar HarmonicsBass

33 Acoustic Bass

34 Electric Bass (finger)

35 Electric Bass (pick)

36 Fretless Bass

37 Slap Bass 1

38 Slap Bass 2

39 Synth Bass 1

40 Synth Bass 2

41 Violin

42 Viola

43 Cello

44 Contrabass

45 Tremolo Strings

46 Pizzicato Strings

47 Orchestral Harp

48 Timpani
Ensemble

49 String Ensemble 1

50 String Ensemble 2

51 Synth Strings 1

52 Synth Strings 2

53 Choir Aahs

54 Voice Oohs

55 Synth Choir

56 Orchestra Hit

57 Trumpet

58 Trombone

59 Tuba

60 Muted Trumpet

61 French Horn

62 Brass Section

63 Synth Brass 1

64 Synth Brass 2

65 Soprano Sax

66 Alto Sax

67 Tenor Sax

68 Baritone Sax

69 Oboe

70 English Horn

71 Bassoon

72 Clarinet
Pipe

73 Piccolo

74 Flute

75 Recorder

76 Pan Flute

77 Blown Bottle

78 Shakuhachi

79 Whistle

80 Ocarina

Synth Lead

81 Lead 1 (square)

82 Lead 2 (sawtooth)

83 Lead 3 (calliope)

84 Lead 4 (chiff)

85 Lead 5 (charang)

86 Lead 6 (voice)

87 Lead 7 (fifths)

88 Lead 8 (bass + lead)

Synth Pad

89 Pad 1 (new age)

90 Pad 2 (warm)

91 Pad 3 (polysynth)

92 Pad 4 (choir)

93 Pad 5 (bowed)

94 Pad 6 (metallic)

95 Pad 7 (halo)

96 Pad 8 (sweep)

Synth Effects

97 FX 1 (rain)

98 FX 2 (soundtrack)

99 FX 3 (crystal)

100 FX 4 (atmosphere)

101 FX 5 (brightness)

102 FX 6 (goblins)

103 FX 7 (echoes)

104 FX 8 (sci-fi)

So-called "Ethnic"

105 Sitar

106 Banjo

107 Shamisen

108 Koto

109 Kalimba

110 Bagpipe

111 Fiddle

112 Shanai

113 Tinkle Bell

114 Agogo

115 Steel Drums

116 Woodblock

117 Taiko Drum

118 Melodic Tom

119 Synth Drum

Sound effects

120 Reverse Cymbal

121 Guitar Fret Noise

122 Breath Noise

123 Seashore

124 Bird Tweet

125 Telephone Ring

126 Helicopter

127 Applause

128 Gunshot

 

Table 2: MIDI program numbers for bank 127, also called the MT-32 sound bank.


 

1 Piano 1

2 Piano 2

3 Piano 3

4 Detuned EP 1

5 E.Piano1

6 E.Piano2

7 Detuned EP2

8 Honky-Tonk

9 Organ 1

10 Organ 2

11 Organ 3

12 Detuned Or. 1

13 Church Org. 2

14 Church Org.

15 Church Org.

16 Accordion Fr.

17 Harpsichord

18 Coupled Hps.

19 Coupled Hps.

20 Clav.

21 Clav.

22 Clav.

23 Celesta

24 Celesta

25 Synth Brass1

26 Synth Brass2

27 Synth Brass3

28 Synth Brass4

29 Synth Bass1

30 Synth Bass2

31 Synth Bass3

32 Synth Bass4

33 Fantasia

34 Syn Calliope

35 Choir Aahs

36 Bowed Glass

37 Soundtrack

38 Atmosphere

39 Crystal

40 Bag Pipe

41 Tinkle Bell

42 Ice Rain

43 Oboe

44 Pan Flute

45 Saw Wave

46 Charang

47 Tubular Bells

48 Square Wave

49 Strings

50 Tremolo Str.

51 Slow Strings

52 Pizzicato Str.

53 Violin

54 Viola

55 Cello

56 Cello

57 Contrabass

58 Harp

59 Harp

60 Nylon-str. Gt

61 Steel-Str. Gt

62 Chorus Gt.

63 Funk Gt.

64 Sitar

65 Acoustic Bs.

66 Fingered Bs.

67 Picked Bs.

68 Fretless Bs.

69 Slap Bs. 1

70 Slap Bs. 2

71 Fretless Bs.

72 Fretless Bs.

73 Flute

74 Flute

75 Piccolo

76 Piccolo

77 Recorder

78 Pan Flute

79 Soprano Sax

80 Alto Sax

81 Tenor Sax

82 Baritone Sax

83 Clarinet

84 Clarinet

85 Oboe

86 English Horn

87 Bassoon

88 Harmonica

89 Trumpet

90 Muted Trumpet

91 Trombone

92 Trombone

93 French Horn

94 French Horn

95 Tuba

96 Brass

97 Brass 2

98 Vibraphone

99 Vibraphone

100 Kalimba

101 Tinkle Bell

102 Glockenspiel

103 Tubular-Bell

104 Xylophone

105 Marimba

106 Koto

107 Taisho Koto

108 Shakuhachi

109 Whistle

110 Whistle

111 Bottle Blow

112 Pan Flute

113 Timpani

114 Melo Tom

115 Melo Tom

116 Synth Drum

117 Synth Drum

118 Taiko

119 Taiko

120 Reverse Cym.

121 Castanets

122 Tinkle Bell

123 Orchestra Hit

124 Telephone

125 Bird

126 Helicopter

127 Bowed Glass

128 Ice Rain

 

Table 3: Program values for Percussion (channel 9).


A blank cell indicates that it uses the default "Standard Set" sound. * indicates no sound.

td >  Gun Shot

# Note Prog 0 Prog 16 Prog 40 Prog 48 Prog 127
27 D#1 Closed Hi-Hat [EXC1] *
28 E1 Pedal Hi-Hat [EXC1] *
29 F1 Open Hi-Hat [EXC1] *
30 F#1 Ride Cymbal *
31 G1 *
32 G#1 *
33 A1 *
34 A#1 *
35 B1 Kick Drum 2 Jazz BD 2 Kick Drum
36 C2 Kick Drum 1 Jazz BD 1  td> Kick Drum
37 C#2 Side Stick Rim Shot
38 D2 Snare Drum 1 Gated Snare Brush Tap Snare Drum 2 Snare Drum
39 D#2 Hand Clap Brush Slap Castanets Hand Clap
40 E2 Snare Drum 2 Brush Swirl Snare Drum 2 Elec. Snare Drum
41 F2 Low Floor Tom Timpani F Acoustic Low Tom
42 F#2 Closed Hi Hat [EXC1] Timpani F# Closed Hi-Hat [Exc1]
43 G2 High Floor Tom Timpani G Acoustic Low Tom
44 G#2 Pedal Hi-Hat [EXC1] Timpani G# Open Hi-Hat 2
45 A2 Low Tom Timpani A Acoustic Middle Tom
46 A#2 Open Hi-Hat [EXC1] Timpani A# Open Hi-Hat 1 [Exc1]
47 B2 Low/Mid Tom  td> Timpani B Acoustic Middle Tom
48 C3 Hi/Mid Tom Timpani C Acoustic High Tom
49 C#3 Crash Cymbal 1 Timpani C# Crash Cymbal
50 D3 High Tom Timpani D Acoustic High Tom
51 D#3 Ride Cymbal 1 Timpani D# Ride Cymbal
52 E3 Chinese Cymbal Timpani E *
53 F3 Ride Bell Timpani F *
54 F#3 Tambourine Tambourine
55 G3 Splash Cymbal *
56 G#3 Cowbell Cowbell
57 A3 Crash Cymbal 2 *
58 A#3 Vibraslap *
59 B3 Ride Cymbal 2 *
60 C4 Hi Bongo
61 C#4 Low Bongo
62 D4 Mute Hi Conga
63 D#4 Open Hi Conga
64 E4 Low Conga
65 F4 High Timbale
66 F#4 Low Timbale
67 G4 High Agogo
68 G#4 Low Agogo
69 A4 Cabasa
70 A#4 Maracas
71 B4 Short Whistle [EXC2]
72 C5 Long Whistle [EXC2]
73 C#5 Short Guiro [EXC3] Vibra Slap
74 D5 Long Guiro [EXC3] *
75 D#5 Claves Claves
76 E5 Hi Wood Block *
77 F5 Low Wood Block *
78 F#5 Mute Cuica [EXC4] *
79 G5 Open Cuica [EXC4] *
80 G#5 Mute Triangle [EXC5] *
81 A5 Open Triangle [EXC5] *
82 A#5 Applauses
83 B5 *
84 C6 *
85 C#6 *
86 D6 *
87 D#6 *
88 E6 Applauses *
89 F6 *
90 f#6 *
91 G6 *
92 G#6 *
93 A6 *
94 A#6 Helicopter
95 B6 *
96 C7
97 C#7 *
98 D7 *
99 D#7 *
100 E7 *
101 F7 *
102 F#7 Birds
103 G7 *
104 g#7 *
105 A7 *
106 A#7 Seashore

Table 4: MIDI Notes

 

 

Oct C C# D D# E F F# G G# A A# B
-1 0 1 2 3 4 5 6 7 8 9 10 11
0 12 13 14 15 16 17 18 19 20 21 22 23
1 24 25 26 27 28 29 30 31 32 33 34 35
2 36 37 38 39 40 41 42 43 44 45 46 47
3 48 49 50 51 52 53 54 55 56 57 58 59
4 60 61 62 63 64 65 66 67 68 69 70 71
5 72 73 74 75 76 77 78 79 80 81 82 83
6 84 85 86 87 88 89 90 91 92 93 94 95
7 96 97 98 99 100 101 102 103 104 105 106 107
8 108 109 110 111 112 113 114 115 116 117 118 119
9 120 121 122 123 124 125 126 127

Midi Note Cheat Sheet

Oct C C# D D# E F F# G G# A A# B
-1 0 1 2 3 4 5 6 7 8 9 10 11
0 12 13 14 15 16 17 18 19 20 21 22 23
1 24 25 26 27 28 29 30 31 32 33 34 35
2 36 37 38 39 40 41 42 43 44 45 46 47
3 48 49 50 51 52 53 54 55 56 57 58 59
4 60 61 62 63 64 65 66 67 68 69 70 71
5 72 73 74 75 76 77 78 79 80 81 82 83
6 84 85 86 87 88 89 90 91 92 93 94 95
7 96 97 98 99 100 101 102 103 104 105 106 107
8 108 109 110 111 112 113 114 115 116 117 118 119
9 120 121 122 123 124 125 126 127

 

Back to blog