Yes I have, someone helped me with it:
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
sf::Sound Piano[100];
sf::SoundBuffer PianoSound;
void PlayPiano(float pitch);
int width = sf::VideoMode::GetMode(0).Width;
int height = sf::VideoMode::GetMode(0).Height;
int main()
{
PianoSound.LoadFromFile( "piano.wav");
//I know I shouldnt be doing this, but I dont know of any other way, Im still learning
for (int i = 0;i < 100; i++){
Piano[i].SetBuffer(PianoSound);
}
// Create the main window
sf::RenderWindow App(sf::VideoMode::GetMode(0), "Piano!", sf::Style::Fullscreen);
// Piano picture
sf::Image pianopic;
pianopic.LoadFromFile("PianoPic.tga");
sf::Sprite PianoSprite;
PianoSprite.SetImage(pianopic);
PianoSprite.SetPosition(0,0);
PianoSprite.SetCenter(0, 0);
PianoSprite.Resize(width, height);
App.Clear(sf::Color(0, 100, 0));
App.Draw(PianoSprite);
App.Display();
sf::Event PressKey;
std::cout << "Start playing the piano!"<<std::endl << "Press escape to quit!" << std::endl;
// Start main loopv
bool running = true;
while (running){
while(App.GetEvent(PressKey)){
if (PressKey.Type == sf::Event::KeyPressed) {
//Toets ingedrukt
switch(PressKey.Key.Code){
// insert cases here.
case (sf::Key::Escape):
App.Close();
running = false;
break;
default:
break;
}
}
}
}
return EXIT_SUCCESS;
}
void PlayPiano(float pitch){
for (int i = 0; i < 100; i++){
if (Piano[i].GetStatus() != Piano[i].Playing){
Piano[i].Stop();
Piano[i].SetPitch (pitch);
Piano[i].Play();
break;
}
}
}