Code a function into another function

#define MotorA1 6
#define MotorA2 7
#define LedA1 2
#define LedA2 12
#define LedB1 3
#define LedB2 4
#define MotorB1 9
#define MotorB2 10
#define horn 13
 


char command = 'S';
char prevCommand = 'A';
int velocity=0;

void setup() 
{       
  Serial.begin(9600);  //Set the baud rate to that of your Bluetooth module.
  

   pinMode(MotorA1 , OUTPUT);
   pinMode(MotorA2 , OUTPUT);
   pinMode(MotorB1 , OUTPUT);
   pinMode(MotorB2 , OUTPUT);
   pinMode (LedA1, OUTPUT);
  pinMode (LedA2, OUTPUT);
  pinMode (LedB1, OUTPUT);
  pinMode (LedB2, OUTPUT);
   pinMode(horn , OUTPUT);
 

   
}

void loop(){ 

  

  if(Serial.available() > 0){ 
 
    prevCommand = command;
    command = Serial.read(); 
    Serial.println(command);
    //Change pin mode only if new command is different from previous.   
    if(command!=prevCommand){
      //Serial.println(command);
      switch(command)
      {
      case 'F':  
      
   
        digitalWrite(MotorA1, HIGH);
        digitalWrite(MotorA2, LOW);
        digitalWrite(MotorB1, HIGH);
        digitalWrite(MotorB2, LOW);
   digitalWrite (LedA1, HIGH);
   digitalWrite (LedA2, LOW);
   digitalWrite (LedB1, HIGH);
   digitalWrite (LedB2, LOW);        
        
        break;
      case 'B': 
      
        digitalWrite(MotorA1, LOW);
        digitalWrite(MotorA2, HIGH);
        digitalWrite(MotorB1, LOW);
        digitalWrite(MotorB2, HIGH);
   digitalWrite (LedA1, LOW);
   digitalWrite (LedA2, HIGH);
   digitalWrite (LedB1, LOW);
   digitalWrite (LedB2, HIGH);        
        break;
      case 'L': 
      
        digitalWrite(MotorA1, HIGH);
        digitalWrite(MotorA2, LOW);
        digitalWrite(MotorB1, LOW);
        digitalWrite(MotorB2, HIGH);
   digitalWrite (LedA1, HIGH);
   digitalWrite (LedA2, HIGH);
   digitalWrite (LedB1, LOW);
   digitalWrite (LedB2, LOW);        
        break;
      case 'R':
      
        digitalWrite(MotorA1, LOW);
        digitalWrite(MotorA2, HIGH);
        digitalWrite(MotorB1, HIGH);
        digitalWrite(MotorB2, LOW);
   digitalWrite (LedA1, LOW);
   digitalWrite (LedA2, LOW);
   digitalWrite (LedB1, HIGH);
   digitalWrite (LedB2, HIGH);
        break;
      case 'S':  
        
        digitalWrite(MotorA1, LOW);
        digitalWrite(MotorA2, LOW);
        digitalWrite(MotorB1, LOW);
        digitalWrite(MotorB2, LOW);
        digitalWrite (LedA1, LOW);
        digitalWrite (LedA2, LOW);
        digitalWrite (LedB1, LOW);
        digitalWrite (LedB2, LOW);
        break;

         case 'V': 
        digitalWrite(horn, HIGH);
        break;
       
        case 'v': 
        digitalWrite(horn, LOW);
        break;


      }
    }
  }
}

I have this code for a working Bluetooth car, To replace the horn case with a melody I know I need to create another function. How would I create another function for the code below and plug it into Case V for the horn to play the melody?

#include "pitches.h"

int melody[] = {
  NOTE_E7, NOTE_E7, 0, NOTE_E7,
  0, NOTE_C7, NOTE_E7, 0,
  NOTE_G7, 0, 0,  0,
  NOTE_G6, 0, 0, 0,
 
  NOTE_C7, 0, 0, NOTE_G6,
  0, 0, NOTE_E6, 0,
  0, NOTE_A6, 0, NOTE_B6,
  0, NOTE_AS6, NOTE_A6, 0,
 
  NOTE_G6, NOTE_E7, NOTE_G7,
  NOTE_A7, 0, NOTE_F7, NOTE_G7,
  0, NOTE_E7, 0, NOTE_C7,
  NOTE_D7, NOTE_B6, 0, 0,
 
  NOTE_C7, 0, 0, NOTE_G6,
  0, 0, NOTE_E6, 0,
  0, NOTE_A6, 0, NOTE_B6,
  0, NOTE_AS6, NOTE_A6, 0,
 
  NOTE_G6, NOTE_E7, NOTE_G7,
  NOTE_A7, 0, NOTE_F7, NOTE_G7,
  0, NOTE_E7, 0, NOTE_C7,
  NOTE_D7, NOTE_B6, 0, 0
};

int noteDurations[] = {
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
 
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
 
  9, 9, 9,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
 
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
 
  9, 9, 9,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
};

const int tonePin = 13;
unsigned long previousMillis = 0;
int counter = 0;
int numberOfNotes = sizeof(melody)/sizeof(int);
boolean outputTone = false;

void setup() {
  pinMode(tonePin, OUTPUT); 
  //Serial.begin(9600);
}

void loop() {
  unsigned long currentMillis = millis();
  unsigned long noteDuration = 1000 / noteDurations[counter];
  unsigned long pauseBetweenNotes = noteDuration * 1.30;


  if (counter < numberOfNotes) {
    if (outputTone && ((currentMillis - previousMillis) >= noteDuration)) {
        previousMillis = currentMillis;
        noTone(tonePin);
        outputTone = false;
        counter++;
    }
    else {
        if ((currentMillis - previousMillis) >= pauseBetweenNotes) {
        previousMillis = currentMillis;
        Serial.println(melody[counter]);

        if (melody[counter] == 0) {
          noTone(tonePin);
        } else {
          tone(tonePin, melody[counter]);
        }

        outputTone = true;
      }
    }
  }
}

Basically, rename your melody loop() function into something else, copy all the setup() code into the other setup() and do the same with all your global variables.

Then, use a variable to indicate if the horn should play or not and then call it every time through loop() so it will continue to play and your serial input will still be responsive.
untested

#include "pitches.h"

int melody[] = {
  NOTE_E7, NOTE_E7, 0, NOTE_E7,
  0, NOTE_C7, NOTE_E7, 0,
  NOTE_G7, 0, 0,  0,
  NOTE_G6, 0, 0, 0,

  NOTE_C7, 0, 0, NOTE_G6,
  0, 0, NOTE_E6, 0,
  0, NOTE_A6, 0, NOTE_B6,
  0, NOTE_AS6, NOTE_A6, 0,

  NOTE_G6, NOTE_E7, NOTE_G7,
  NOTE_A7, 0, NOTE_F7, NOTE_G7,
  0, NOTE_E7, 0, NOTE_C7,
  NOTE_D7, NOTE_B6, 0, 0,

  NOTE_C7, 0, 0, NOTE_G6,
  0, 0, NOTE_E6, 0,
  0, NOTE_A6, 0, NOTE_B6,
  0, NOTE_AS6, NOTE_A6, 0,

  NOTE_G6, NOTE_E7, NOTE_G7,
  NOTE_A7, 0, NOTE_F7, NOTE_G7,
  0, NOTE_E7, 0, NOTE_C7,
  NOTE_D7, NOTE_B6, 0, 0
};

int noteDurations[] = {
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,

  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,

  9, 9, 9,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,

  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,

  9, 9, 9,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
};

const int tonePin = 13;
unsigned long previousMillis = 0;
int counter = 0;
int numberOfNotes = sizeof(melody) / sizeof(melody[0]);
boolean outputTone = false;
boolean hornPlaying = false;

void playTune() {
  unsigned long currentMillis = millis();
  unsigned long noteDuration = 1000 / noteDurations[counter];
  unsigned long pauseBetweenNotes = noteDuration * 1.30;

  if (counter < numberOfNotes) {
    if (outputTone && ((currentMillis - previousMillis) >= noteDuration)) {
      previousMillis = currentMillis;
      noTone(tonePin);
      outputTone = false;
      counter++;
    }
    else {
      if ((currentMillis - previousMillis) >= pauseBetweenNotes) {
        previousMillis = currentMillis;
        Serial.println(melody[counter]);

        if (melody[counter] == 0) {
          noTone(tonePin);
        } else {
          tone(tonePin, melody[counter]);
        }
        outputTone = true;
      }
    }
  }
  else {
    // horn melody is complete
    hornPlaying = false;
    counter = 0;
  }
}


#define MotorA1 6
#define MotorA2 7
#define LedA1 2
#define LedA2 12
#define LedB1 3
#define LedB2 4
#define MotorB1 9
#define MotorB2 10
//#define horn 13

char command = 'S';
char prevCommand = 'A';
int velocity = 0;

void setup()
{
  Serial.begin(9600);  //Set the baud rate to that of your Bluetooth module.

  pinMode(MotorA1 , OUTPUT);
  pinMode(MotorA2 , OUTPUT);
  pinMode(MotorB1 , OUTPUT);
  pinMode(MotorB2 , OUTPUT);
  pinMode (LedA1, OUTPUT);
  pinMode (LedA2, OUTPUT);
  pinMode (LedB1, OUTPUT);
  pinMode (LedB2, OUTPUT);
//  pinMode(horn , OUTPUT);

  pinMode(tonePin, OUTPUT);
}

void loop() {

  if (hornPlaying == true) {
    playTune();
  }
  
  if (Serial.available() > 0) {
    prevCommand = command;
    command = Serial.read();
    Serial.println(command);
    //Change pin mode only if new command is different from previous.
    if (command != prevCommand) {
      //Serial.println(command);
      switch (command) {
        
        case 'F':
          digitalWrite(MotorA1, HIGH);
          digitalWrite(MotorA2, LOW);
          digitalWrite(MotorB1, HIGH);
          digitalWrite(MotorB2, LOW);
          digitalWrite (LedA1, HIGH);
          digitalWrite (LedA2, LOW);
          digitalWrite (LedB1, HIGH);
          digitalWrite (LedB2, LOW);
          break;

        case 'B':
          digitalWrite(MotorA1, LOW);
          digitalWrite(MotorA2, HIGH);
          digitalWrite(MotorB1, LOW);
          digitalWrite(MotorB2, HIGH);
          digitalWrite (LedA1, LOW);
          digitalWrite (LedA2, HIGH);
          digitalWrite (LedB1, LOW);
          digitalWrite (LedB2, HIGH);
          break;

        case 'L':
          digitalWrite(MotorA1, HIGH);
          digitalWrite(MotorA2, LOW);
          digitalWrite(MotorB1, LOW);
          digitalWrite(MotorB2, HIGH);
          digitalWrite (LedA1, HIGH);
          digitalWrite (LedA2, HIGH);
          digitalWrite (LedB1, LOW);
          digitalWrite (LedB2, LOW);
          break;

        case 'R':
          digitalWrite(MotorA1, LOW);
          digitalWrite(MotorA2, HIGH);
          digitalWrite(MotorB1, HIGH);
          digitalWrite(MotorB2, LOW);
          digitalWrite (LedA1, LOW);
          digitalWrite (LedA2, LOW);
          digitalWrite (LedB1, HIGH);
          digitalWrite (LedB2, HIGH);
          break;

        case 'S':
          digitalWrite(MotorA1, LOW);
          digitalWrite(MotorA2, LOW);
          digitalWrite(MotorB1, LOW);
          digitalWrite(MotorB2, LOW);
          digitalWrite (LedA1, LOW);
          digitalWrite (LedA2, LOW);
          digitalWrite (LedB1, LOW);
          digitalWrite (LedB2, LOW);
          break;

        case 'V':
          //digitalWrite(horn, HIGH);
          hornPlaying = true;
          break;

        case 'v':
          //digitalWrite(horn, LOW);
          hornPlaying = false;
          counter = 0;
          noTone(tonePin);
          break;
      }
    }
  }
}

Thanks, mate really appreciate it.