GIDForums  

Go Back   GIDForums > Computer Programming Forums > FLTK Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-Sep-2006, 08:56
baard baard is offline
New Member
 
Join Date: Sep 2006
Posts: 13
baard is on a distinguished road

Playing sound in Fltk


Greetings. I am a new member and a beginner. Please help me with the following learner's code. I am using audiere and fltk to play a sound file. I need to play a cat sound file when the sing button is clicked in cat window and a dog sound when a sing button is clicked in a dog widow. I tried to use the sound functions from the callback functions, but it is not working. Please suggest a solution.

CPP / C++ / C Code:
#include <audiere.h>

#include <fltk/run.h>
#include <fltk/Window.h>
#include <fltk/Button.h>
#include <fltk/Widget.h>
#include <fltk/SharedImage.h>

using namespace audiere;
using namespace fltk;

//========================================================
void meaw(Widget* o, void*  ) {
   Button* b=(Button*)o;

b->label("Meaw meaw..."); //redraw not necessary

   b->resize(10,150,140,30); //redraw needed
   b->redraw();
}
//-------------------------------------------------------
void bark(Widget* o, void*  ) {
   Button* b=(Button*)o;
   b->label("Bow wow ..."); //redraw not necessary

   b->resize(10,150,140,30); //redraw needed
   b->redraw();
}

//========================================================


int main(int argc, char **argv) {
//--------------------------------------------------------------------Main

 //we can play the sound without any callback this way. How can I call this from the  callback functions?---------------

   AudioDevicePtr device(OpenDevice());
   OutputStreamPtr sound(OpenSound(device,"b.wav", false));
   sound->play();
//-----------------------------------------------------------------

Window *cat = new Window(30,60,200, 180); 
Window *dog = new Window(240,60,200, 180); 

cat->begin();
cat->image(fltk::pngImage::get("cat.png"));
Button * b = new Button(0,0,70,23,"Sing");
b->callback(meaw);

    
b->labelfont(HELVETICA_BOLD_ITALIC);
b->labelsize(18);
cat->end();
//----------------------------------------------
dog->begin();
dog->image(fltk::pngImage::get("dog.png"));
Button * c = new Button(0,0,70,23,"Sing");
c->labelfont(HELVETICA_BOLD_ITALIC);
c->labelsize(18);
c->callback(bark);
dog->end();
//----------------------------------------------
dog->show();
cat->show();

 return run();

}
Last edited by LuciWiz : 07-Sep-2006 at 09:06. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #2  
Old 09-Sep-2006, 09:40
baard baard is offline
New Member
 
Join Date: Sep 2006
Posts: 13
baard is on a distinguished road

Re: Playing sound in Fltk


No response
OK. I have solved the problem. I created a derived window class and wrapped the sound function inside. Now it is working. I am posting the code, if anybody is interested. It uses the ripping of a simple wrapping example from fltk site.
Code:
#include <audiere.h> #include <fltk/run.h> #include <fltk/Window.h> #include <fltk/Button.h> #include <fltk/Widget.h> #include <fltk/SharedImage.h> #include <fltk/ask.h> // fltk::alert() using namespace audiere; using namespace fltk; class LabelWindow : public Window { Widget labExample; // NOTE: I am using fltk::Widget as label! Button butExit; OutputStreamPtr mysound; inline void ButExitCB_i() { this->playsound(); //fltk::alert("You clicked me, now I'll quit!"); //this->hide(); } static void ButExitCB(Widget*, void* v) { ((LabelWindow*)v)->ButExitCB_i(); } public: void setsound(OutputStreamPtr mysounda){ mysound=mysounda; } void playsound(){ if (mysound) mysound->play(); } // LabelWindow constructor LabelWindow(const char* label=0) : //Window(USEDEFAULT,USEDEFAULT,320,90,label,true), Window(100,100,256,256,label,true), labExample(10,10,200,20,"I can sing!"), butExit(0,0,60,32,"&Sing") { // Here we set callbacks butExit.callback(ButExitCB, this); // and some properties for those objects we have on our Window butExit.box(fltk::PLASTIC_DOWN_BOX); labExample.box(fltk::NO_BOX); // this is a label - we do not want a box end(); } // Destructor ~LabelWindow() {} }; // LabelWindow class //void playsound(OutputStreamPtr mysound); int main(int argc, char ** argv) { AudioDevicePtr device(OpenDevice()); OutputStreamPtr sound(OpenSound(device,"a.wav", false)); OutputStreamPtr soundb(OpenSound(device,"b.wav", false)); LabelWindow Cat("Example of simple, clickable label."); Cat.setsound(soundb); Cat.image(fltk::pngImage::get("cat.png")); LabelWindow dog("singg"); dog.position(370,100); dog.setsound(sound); dog.image(fltk::pngImage::get("dog.png")); dog.show(argc, argv); Cat.show(argc, argv); return run(); }
 
 

Recent GIDBlogVista ?Widgets? on Windows XP by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] GUI programming with FLTK dsmith FLTK Forum 10 03-Oct-2005 15:41
Re: Derived FLTK Classes cable_guy_67 FLTK Forum 0 26-Jun-2005 20:07
FLTK with GLUT usmsci FLTK Forum 4 26-Nov-2004 16:21
fltk and ncurses podarok FLTK Forum 2 08-Nov-2004 07:45
Welcome to the FLTK Forums dsmith FLTK Forum 0 08-Sep-2004 06:58

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 09:51.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.