
Originally Posted by
davidlamhauge
My problem is that my code works the way I want - except from the fact that it crashes the program...
So it doesn't work the way you want 
I don't know how to "schedule" my "sound playback", but maybe it is here that I should use signals and slots?
The simplest way I know is to use QQueue or equivalent. The when you get signalled, check if the user currently presses the key to play the next sound and if so, take the next element from the queue.
And when you write "... start another note", is that a thread? or?
How do I "queue a series of sounds"? I don't use phonon, but maybe it is a possibility anyway...
A lot to think about.
Similar to:
struct MouthEntry {
};
QQueue<MouthEntry> m_mouthQueue;
void enqueueWordToSay
(const QString &word
) { for(int i=0;i<word.size();++i) m_mouthQueue = createEntryFromSound(word.at(i)); // this is oversimplified of course
}
connect(audioOutput, SIGNAL(stateChanged(...)), this, SLOT(maybePlayNextNote()));
void X::maybePlayNextNote() {
if(!iuserWantsNextFrame) { m_playing = false; }
if(m_mouthQueue.isEmpty()) { m_playing = false; }
playNote(m_mouthQueue.dequeue());
}
void X::playNote(MouthEntry entry) {
showMouth(entry.mouthPath);
play(entry.soundPath);
m_playing = true;
}
if(ke->key() == Qt::Key_Right) { userWantsNextFrame = true; maybePlayNextNote(); return; }
}
if(ke->key() == Qt::Key_Right) { userWantsNextFrame = false; return; }
}
struct MouthEntry {
const QString soundPath;
const QString mouthPath;
};
QQueue<MouthEntry> m_mouthQueue;
void enqueueWordToSay(const QString &word) {
for(int i=0;i<word.size();++i) m_mouthQueue = createEntryFromSound(word.at(i)); // this is oversimplified of course
}
connect(audioOutput, SIGNAL(stateChanged(...)), this, SLOT(maybePlayNextNote()));
void X::maybePlayNextNote() {
if(!iuserWantsNextFrame) { m_playing = false; }
if(m_mouthQueue.isEmpty()) { m_playing = false; }
playNote(m_mouthQueue.dequeue());
}
void X::playNote(MouthEntry entry) {
showMouth(entry.mouthPath);
play(entry.soundPath);
m_playing = true;
}
void X::keyPressEvent(QKeyEvent *ke) {
if(ke->key() == Qt::Key_Right) { userWantsNextFrame = true; maybePlayNextNote(); return; }
}
void X::keyReleaseEvent(QKeyEvent *ke) {
if(ke->key() == Qt::Key_Right) { userWantsNextFrame = false; return; }
}
To copy to clipboard, switch view to plain text mode
etc.
Bookmarks