Need help with melody stretch cycle glove

Heya,

For a project we are making a stretchable glove that cycles or pauses music. It depends on 2 inputs: Input pins: A1,A0 They both measure the amount of stretch of the glove and run a function when a certain trigger level is hit.

If stretch 1 measures 2 hits of the trigger level in a short duration, it should cycle the song.

If stretch 1 measures 1 hit of the trigger level, it should mute the song.

If stretch 2 measures 1 hit of the trigger level, it should turn off or on the code

Currently I'm stuck on having to cycle the songs, since I am having the error that I can't call the song function. Does anybody know how to fix this?

#include "got.h"
#define INPUT_PIN A0
#define INPUT_PIN2 A1
#define SPEAKER 8

int trigLevel = 1000 ;
int trigLevel2 = 900;
bool switchState = false;
float avg = 0.0;
float avg2 = 0.0;

int notes = sizeof(melody) / sizeof(melody[0]) / 2;
int wholenote = (60000 * 4) / tempo;
int divider = 0, noteDuration = 0;

struct SONG {
  int *melody;
  int *tempo;
  uint16_t notes;
};

SONG song[] = {
  {melody, tempo, notes(melody)},
  {melody2, tempo2, notes(melody2)},
  {melody3, tempo3, notes(melody3)},
  {melody4, tempo4, notes(melody4)},
  {melody5, tempo5, notes(melody5)}
};

void setup() {
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
}

void playMelody(int songNumber) {
  songNumber--;
  int numberOfNotes = songs[songNumber].numNotes;
  // Remember, the array is twice the number of notes (notes + durations)
  int wholenote = (60000 * 4) / tempo;
  for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) {

    // calculates the duration of each note
    divider = melody[thisNote + 1];
    if (divider > 0) {
      // regular note, just proceed
      noteDuration = (wholenote) / divider;
    } else if (divider < 0) {
      // dotted notes are represented with negative durations!!
      noteDuration = (wholenote) / abs(divider);
      noteDuration *= 1.5; // increases the duration in half for dotted notes
    }

    float stretch = measureStretchAmount();
    bool state = performAction(stretch);
    Serial.print(stretch);
    Serial.println(" ");

    // we only play the note for 90% of the duration, leaving 10% as a pause
    if (!state)
      tone(SPEAKER, melody[thisNote], noteDuration * 0.9);

    // Wait for the specific duration before playing the next note.
    delay(noteDuration);

    // stop the waveform generation before the next note.
    noTone(SPEAKER);

    if (fingerActionPerformed()) {
      return;
    }
    state == next
  }
}

enum states {off, play, muted, next};
states state = off;
int song = 0;

void loop() {

  if (state == off) {
    Serial.print("State is off")
    if (preformWristAction()) {
      state == play
    }
  }

  if (state == play) {
    Serial.print("State is playing")
    playMusic(song);
  }

  if (state == muted) {
    Serial.print("State is muted")
    unsigned int timeOut = 500;
    unsigned long muteTime = millis();
    while ((muteTime + timeOut) > millis()) {
      if performAction(stretch)) {
        state == next
      }
    }
  }
  if (state == next) {
    Serial.print("State is skipped")
    song++;
    if (song > 4) song = 0;
    state = play;
  }
  if (preformWristAction()) {
    state = off;
  }
}

// Function to measure the amount of stretch. Change the filter response (fast or slow) as per your need.
float measureStretchAmount() {
  int aVal = analogRead(INPUT_PIN);
  avg = 0.5 * avg + 0.5 * aVal;
  return avg;
}

float measureWristAmount() {
  int aVal2 = analogRead(INPUT_PIN2);
  avg2 = 0.5 * avg2 + 0.5 * aVal2;
  return avg2;
}

// Function to implement any action based on the amount of stretch
bool performAction(float stretch)
{
  static bool crossedTrigger = false;
  if (stretch > trigLevel) {
    if (crossedTrigger == false)
      switchState = !switchState;

    crossedTrigger = true;
  } else {
    crossedTrigger = false;
  }

  digitalWrite(LED_BUILTIN, switchState);
  return switchState;
}

bool performWristAction(float stretch2)
{
  static bool crossedTrigger = false;
  if (stretch2 > trigLevel2) {
    if (crossedTrigger == false)
      switchState = !switchState;

    crossedTrigger = true;
  } else {
    crossedTrigger = false;
  }

  digitalWrite(LED_BUILTIN, switchState);
  return switchState;
}

"can't call function'? Why?

You don't seem to have a "song()" function. You have a global "SONG" struct definition, a global "song[]" array of SONG structs, and a local "int song;", but no "song()" function.

Do you have a function called notes() defined? It appears you want the number of notes as the 3rd element in you struct but that has nothing to do with the variable notes defined above.

You are doing a comparision there and then throwing away the result, not assigning a new value to 'state'

I think you meant:
#define notes(x) ((sizeof(x) / sizeof((x)[0]) / 2)