Results 1 to 2 of 2

Thread: Problem emitting a signal

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem emitting a signal

    Hi to all,
    in my application (an audio editor) I have a callback that emit a signal when a sound stop playing so:
    Qt Code:
    1. //! Executed when a sound finish playing
    2. FMOD_RESULT F_CALLBACK endCallback(FMOD_CHANNEL *channel, FMOD_CHANNEL_CALLBACKTYPE type,
    3. unsigned int commanddata1, unsigned int commanddata2)
    4. {
    5. (void)commanddata1; // Unused (to avoid warnings)
    6. (void)commanddata2; // Unused (to avoid warnings)
    7.  
    8. SoundData* currentSound;
    9.  
    10. switch(type)
    11. {
    12. case FMOD_CHANNEL_CALLBACKTYPE_END:
    13. {
    14. FMOD_RESULT result;
    15. FMOD::Channel *currentChannel = (FMOD::Channel *)channel;
    16.  
    17. void *ud = NULL;
    18. result = currentChannel->getUserData( &ud );
    19.  
    20. /* inform that sound stopped */
    21. emit AudioDevice::getInstance()->soundStopped();
    22. break;
    23. }
    24. default:
    25. break;
    26. }
    27.  
    28. return FMOD_OK;
    29. }
    To copy to clipboard, switch view to plain text mode 
    in the application I have 2 WaveWidgets ( waveform display ) having a slot connected to the signal emitted from the callback so:
    Qt Code:
    1. /************************************************************************/
    2. /* Constructor */
    3. /************************************************************************/
    4. WaveWidget::WaveWidget( QWidget* parent /* = 0 */ )
    5. : QWidget( parent ),
    6. m_wave( 0 ),
    7. rb( 0 ),
    8. m_CurrentTimePosition( 0 )
    9. {
    10. setFocusPolicy( Qt::TabFocus );
    11. timer = new QTimer();
    12.  
    13. connect( timer, SIGNAL( timeout() ), this, SLOT( setCurrentTimePosition() ) );
    14. connect( AudioDevice::getInstance(), SIGNAL( soundStopped() ), this, SLOT( stopTimer() ), Qt::QueuedConnection );
    15. }
    To copy to clipboard, switch view to plain text mode 

    The stopTimer slot of the WaveWidget reset the timeLine to position 0 so:
    Qt Code:
    1. /************************************************************************/
    2. /* stopTimer */
    3. /************************************************************************/
    4. void WaveWidget::stopTimer()
    5. {
    6. timer->stop();
    7. qDebug() << "Timer stopped";
    8. resetTimeline();
    9. }
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. /************************************************************************/
    2. /* resetTimeline */
    3. /************************************************************************/
    4. void WaveWidget::resetTimeline()
    5. {
    6. int h = height();
    7. QRect r = QRect( 0 , 0, m_CurrentTimePosition + 1, h );
    8. // reset timeline
    9. update( r );
    10. // reset current value
    11. m_CurrentTimePosition = 0;
    12. // delete rubberband if one
    13. if( rb )
    14. {
    15. delete rb;
    16. rb = 0;
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 
    The problem is that when 1 of the 2 playing sounds stop playing ALL WaveWidget are informed of that and ALL reset their timeLine to 0 instead of only the right WaveWidget that efectively has its sound stopped.
    How can I solve this problem?

    I hope to get help.
    Best Regards,
    Franco
    Franco Amato

  2. #2
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem emitting a signal [SOLVED]

    I solved it calling a method of the "userdata" object instead of emitting a signal so:

    Qt Code:
    1. //! Executed when a sound finish playing
    2. FMOD_RESULT F_CALLBACK endCallback(FMOD_CHANNEL *channel, FMOD_CHANNEL_CALLBACKTYPE type,
    3. unsigned int commanddata1, unsigned int commanddata2)
    4. {
    5. (void)commanddata1; // Unused (to avoid warnings)
    6. (void)commanddata2; // Unused (to avoid warnings)
    7.  
    8. WaveWidget* wave;
    9.  
    10. switch(type)
    11. {
    12. case FMOD_CHANNEL_CALLBACKTYPE_END:
    13. {
    14. FMOD_RESULT result;
    15. FMOD::Channel *currentChannel = (FMOD::Channel *)channel;
    16.  
    17. void *ud = NULL;
    18. result = currentChannel->getUserData( &ud ); // Here I get the userdata
    19.  
    20. wave = (WaveWidget*)ud; // I cast it
    21. wave->stopTimer(); // Call userdata method
    22.  
    23. //emit AudioDevice::getInstance()->soundStopped(); //inform that sound is stopped
    24. break;
    25. }
    26. default:
    27. break;
    28. }
    29.  
    30. return FMOD_OK;
    31. }
    To copy to clipboard, switch view to plain text mode 

    Bye
    Franco Amato

Similar Threads

  1. Replies: 6
    Last Post: 7th November 2012, 05:13
  2. signal / slot problem
    By franco.amato in forum Newbie
    Replies: 13
    Last Post: 8th December 2009, 18:10
  3. problem with emiting a signal
    By msmihai in forum Newbie
    Replies: 2
    Last Post: 3rd January 2009, 14:32
  4. cost of emitting signal
    By quickNitin in forum Newbie
    Replies: 1
    Last Post: 29th November 2006, 08:53
  5. Problem with Signal and Slots
    By Kapil in forum Installation and Deployment
    Replies: 2
    Last Post: 10th February 2006, 08:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.