Melody and blinking leds at the same time?

I'm trying to combine two sketches: One blinks three leds and the other one plays melody. They work well separately, but when I put them into the same sketch, they function one after the other. Not at the same time, how I like it to work. How could I do that?
Here's the sketch:

int redPin = 12; // Red LED connected to digital pin 12
int greenPin = 11; // Green LED connected to digital pin 11
int yellowPin = 10; // Yellow LED connected to digital pin 10

int speakerPin = 8;

int length = 40; // the number of notes
char notes[] = "cccedddfeeddc eeeegfddddfecccedddfeeddc "; // a space represents a rest
int beats[] = { 1,1,1,1,1,1,1,1,1,1,1,1,3,1,1,1,1,1,2,2,1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,3,1};
int tempo = 300;

void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);
}
}

void playNote(char note, int duration) {
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

// play the tone corresponding to the note name
for (int i = 0; i < 8; i++) {
if (names == note) {
_ playTone(tones*, duration);_
_
}_
_
}_
_
}_
void setup() {
_
pinMode(speakerPin, OUTPUT);_
_
pinMode(redPin, OUTPUT); // sets the digital pin as output*_
* pinMode(greenPin, OUTPUT); // sets the digital pin as output*
* pinMode(yellowPin, OUTPUT); // sets the digital pin as output*
}
void loop() {
* for (int i = 0; i < length; i++) {*
_ if (notes == ' ') {
delay(beats * tempo); // rest
* } else {_
playNote(notes, beats _ tempo);
* }
// pause between notes*

* delay(tempo / 2);
}
digitalWrite(redPin, HIGH); // sets the Red LED on*

* digitalWrite(greenPin, LOW); // sets the Green LED off*
* digitalWrite(yellowPin, LOW); // sets the Yellow LED off*
* delay(500); // waits for half a second*
* digitalWrite(redPin, LOW); // sets the Red LED off*
* digitalWrite(greenPin, HIGH); // sets the Green LED on*
* digitalWrite(yellowPin, LOW); // sets the Yellow LED off*
* delay(500); // waits for half a second*
* digitalWrite(redPin, LOW); // sets the Red LED off*
* digitalWrite(greenPin, LOW); // sets the Green LED off*
* digitalWrite(yellowPin, HIGH); // sets the Yellow LED on*
* delay(500); // waits for half a second*
* digitalWrite(redPin, LOW); // sets the Red LED off*
* digitalWrite(greenPin, LOW); // sets the Green LED off*
* digitalWrite(yellowPin, LOW); // sets the Yellow LED off*
* delay(500); // waits for half a second*
* digitalWrite(redPin, HIGH); // sets the Red LED on*
* digitalWrite(greenPin, HIGH); // sets the Green LED on*
* digitalWrite(yellowPin, HIGH); // sets the Yellow LED on*
* delay(1000); // waits for a second*
* digitalWrite(redPin, LOW); // sets the Red LED off*
* digitalWrite(greenPin, LOW); // sets the Green LED off*
* digitalWrite(yellowPin, LOW); // sets the Yellow LED off*
* delay(500); // waits for half a second*
}_

You'll have to completely rewrite the code.

See all those delays you have? You need to get rid of those.

What you're doing now is:
Do A
Pause.
Do B.
Pause.
Repeat.

What you need to do is:
Get current time.
Is it time for me to do A? If yes, do A.
Is it time for me to do B? If yes, do B.
Repeat.

This should get you started:

    static unsigned long oldTime;
    static unsigned long timeDelta;
    static float timeDeltaSec;    
   
        
    oldTime = time;                            // Store start time of last update.
    time = millis();                           // Get current system time. 
    timeDelta = time - oldTime;                // Calculate how long last update took, in milliseconds.
    timeDeltaSec = float(timeDelta) / 1000.0;  // Convert last update period into seconds.

Stick that in your main loop and then either add timeDelta to a variable each time through until that variable is greater than however many milliseconds you want to wait before triggering something (and then subtracting that many milliseconds from it before you continue) or record the last time an action occured each time you perform it, then add the time you want to wait between actions to that when you compare it with the current time to see if it is now time to perform the action again... at which point you would again record the time the action took place.