void video::startConvert() { this->_progressBar->setMinimum(0); this->_progressBar->setMaximum(0); setToolTip("<strong>" + tr("Converting ...") + "</strong>"); connect(this->_converter, SIGNAL(conversionFinished()), this, SLOT(conversionFinished())); this->_converter->startConversion(this->downloadFile, _targetPath, _supportedQualities.at(_quality).containerName, _metaTitle, _metaArtist,_converterMode); }
void VideoConverter::finished(int /*exitCode*/, QProcess::ExitStatus /*exitStatus*/) { deinitTimer(); if (QFile::exists(videoItem->getVideoFileSavedTo())) { QFile output(videoItem->getVideoFileSavedTo()); // has been converted?! if (output.size() == 0) // no { QFile::remove(videoItem->getVideoFileSavedTo()); videoItem->setVideoFileSavedTo(videoItem->getVideoFile(), this); } else // yes if (deleteOriginalVideo) QFile::remove(videoItem->getVideoFile()); } else videoItem->setVideoFileSavedTo(videoItem->getVideoFile(), this); videoItem->setAsConverted(this); videoItem->unlock(this); emit conversionFinished(videoItem); }
MidiConverterDialog::MidiConverterDialog(Master *master, QWidget *parent) : QDialog(parent), ui(new Ui::MidiConverterDialog), batchMode(false) { ui->setupUi(this); loadProfileCombo(); connect(&converter, SIGNAL(conversionFinished()), SLOT(handleConversionFinished())); connect(&converter, SIGNAL(midiEventProcessed(int, int)), SLOT(updateConversionProgress(int, int))); connect(this, SIGNAL(conversionFinished(const QString &, const QString &)), master, SLOT(showBalloon(const QString &, const QString &))); setAcceptDrops(true); }
void MidiConverterDialog::handleConversionFinished() { if (Master::getInstance()->getSettings()->value("Master/showConnectionBalloons", "1").toBool()) { emit conversionFinished("MIDI file converted", ui->pcmList->currentItem()->text()); } ui->midiList->clear(); delete ui->pcmList->takeItem(ui->pcmList->currentRow()); on_startButton_clicked(); }
void video::handleDownloads() { switch (this->_step) { case 1: { handler->downloads.at(0)->tempFile->close(); handler->downloads.at(0)->tempFile->open(); QByteArray data = handler->downloads.at(0)->tempFile->readAll(); handler->downloads.at(0)->tempFile->close(); QString html = QString::fromUtf8(data, data.size()); handler->clearDownloads(); parseVideo(html); break; } case 3: { if (handler->downloads.size() == 1) { this->downloadFile = handler->downloads.at(0)->tempFile; emit downloadFinished(); } else { this->_step = 4; converter_ffmpeg* ffmpeg = new converter_ffmpeg; QList<QFile*> files; for (int i=0; i < handler->downloads.size(); i++) { files << handler->downloads.at(i)->tempFile; } this->_progressBar->setMinimum(0); this->_progressBar->setMaximum(0); for (int i = 0; i <= 3; i++) { this->_treeItem->setToolTip(i, "<strong>" + tr("Converting ...") + "</strong>"); } this->downloadFile = new QTemporaryFile(QDir::tempPath() + "/clipgrab-concat--XXXXXX"); this->downloadFile->open(QIODevice::ReadOnly); this->downloadFile->close(); qDebug() << this->downloadFile; connect(ffmpeg, SIGNAL(conversionFinished()), this, SLOT(handleDownloads())); ffmpeg->concatenate(files, this->downloadFile); } break; } case 4: { emit downloadFinished(); break; } } }
void VideoConverter::startConversionVideo(VideoItem *videoItem) { if (videoItem == NULL || !canStartConversion() || !ffmpegInstalled()) return; // check if this videoItem has an overrided conversion config if (videoItem->hasOverridedConversion()) { // the user don't want convert it if (!videoItem->getOverridedVideoConversionConfig().convertVideo) { // mark as "converted" videoItem->setAsConverted(NULL); // emit the conversion finished emit conversionFinished(videoItem); return; } else // set the "overrided" conversion config { convConfToUse = videoItem->getOverridedVideoConversionConfig().videoConversionConfig; } } else // set the conversion config stored in options (standard user options) { convConfToUse = convConf; } // assign data this->videoItem = videoItem; videoItem->lock(this); videoItem->setProgress(0, this); // init internal data videoLength = 0; outputAll = ""; // check if the "input" video file exists if (QFile::exists(videoItem->getVideoFile())) { QFile input(videoItem->getVideoFile()); // the video is > than 0kb? if yes, then start the conversion if (input.size() > 0) { lastProgress = 0; // launch the ffmpeg application ffmpegProcess->start(ffmpegApp, getCommandLine()); return; } } // if we are here, then this video is invalid (error) videoItem->setAsError(this); videoItem->unlock(this); emit videoItemUpdated(videoItem); }
void video::conversionFinished() { this->_progressBar->setMaximum(1); this->_progressBar->setValue(1); this->_progressBar->setFormat(tr("Finished")); this->_finished = true; for (int i = 0; i <= 3; i++) { this->_treeItem->setToolTip(i, "<strong>" + tr("Finished!") + "</strong>"); } handler->clearDownloads(); if (this->downloadFile) { this->downloadFile->deleteLater(); } emit conversionFinished(this); }
void video::conversionFinished() { this->_progressBar->setMaximum(1); this->_progressBar->setValue(1); this->_progressBar->setFormat(tr("Finished")); this->_finished = true; if (!this->_converter->target.isEmpty()) { this->_targetPath = this->_converter->target; } setToolTip("<strong>" + tr("Finished!") + "</strong>"); handler->clearDownloads(); if (this->downloadFile) { this->downloadFile->deleteLater(); } emit conversionFinished(this); }
ResultsPage::ResultsPage(QWidget *parent) : QWizardPage(parent), previousMessageHandler(NULL) { setTitle(tr("Processing Training Sessions...")); setSubTitle(tr("Processing will begin in a moment.")); QVBoxLayout * const vBox = new QVBoxLayout; progressBar = new QProgressBar(); vBox->addWidget(progressBar); { QHBoxLayout * const hBox = new QHBoxLayout(); showDetailsButton = new QPushButton(tr("Show details")); hBox->addWidget(showDetailsButton); hBox->addStretch(); vBox->addItem(hBox); } detailsBox = new QTextEdit(); detailsBox->setReadOnly(true); detailsBox->setVisible(false); connect(showDetailsButton, SIGNAL(clicked()), this, SLOT(showDetails())); vBox->addWidget(detailsBox); converter = new ConverterThread; connect(converter, SIGNAL(finished()), this, SLOT(conversionFinished())); connect(converter, SIGNAL(progress(int)), this, SLOT(sessionStarted(int))); connect(converter, SIGNAL(progress(int)), progressBar, SLOT(setValue(int))); connect(converter, SIGNAL(sessionBaseNamesChanged(int)), progressBar, SLOT(setMaximum(int))); connect(converter, SIGNAL(started()), this, SLOT(conversionStarted())); // This signal/slot indirection pipes all log events to the GUI thread. connect(this, SIGNAL(newMessage(QString,QColor)), this, SLOT(appendMessage(QString,QColor)), Qt::QueuedConnection); setLayout(vBox); }
void converter_ffmpeg::emitFinished() { emit conversionFinished(); }
void AudioFileWriter::run() { QFile file(outFileName); bool waveMode = false; if (outFileName.endsWith(".wav")) waveMode = true; if (!file.open(QIODevice::WriteOnly)) { qDebug() << "AudioFileWriter: Can't open file for writing:" << outFileName; synth->close(); return; } if (waveMode) file.seek(44); MasterClockNanos startNanos = MasterClock::getClockNanos(); MasterClockNanos firstSampleNanos = 0; MasterClockNanos midiTick = 0; MasterClockNanos midiNanos = 0; MidiEventList midiEvents; int midiEventIx = 0; uint parserIx = 0; if (realtimeMode) { firstSampleNanos = startNanos; } else { midiEvents = parsers[parserIx].getMIDIEvents(); midiTick = parsers[parserIx].getMidiTick(); } qDebug() << "AudioFileWriter: Rendering started"; while (!stopProcessing) { unsigned int frameCount = 0; if (realtimeMode) { frameCount = sampleRate * (MasterClock::getClockNanos() - firstSampleNanos) / MasterClock::NANOS_PER_SECOND; if (frameCount < bufferSize) { usleep(1000000 * (bufferSize - frameCount) / sampleRate); continue; } else { frameCount = bufferSize; } } else { while (midiEventIx < midiEvents.count()) { const MidiEvent &e = midiEvents.at(midiEventIx); bool eventPushed = true; MasterClockNanos nextEventNanos = midiNanos + e.getTimestamp() * midiTick; frameCount = (uint)(sampleRate * (nextEventNanos - firstSampleNanos) / MasterClock::NANOS_PER_SECOND); if (bufferSize < frameCount) { frameCount = bufferSize; break; } switch (e.getType()) { case SHORT_MESSAGE: eventPushed = synth->pushMIDIShortMessage(e.getShortMessage(), nextEventNanos); break; case SYSEX: eventPushed = synth->pushMIDISysex(e.getSysexData(), e.getSysexLen(), nextEventNanos); break; case SET_TEMPO: midiTick = parsers[parserIx].getMidiTick(e.getShortMessage()); break; default: break; } if (!eventPushed) { qDebug() << "AudioFileWriter: MIDI buffer overflow, midiNanos:" << midiNanos; break; } midiNanos = nextEventNanos; midiEventIx++; emit midiEventProcessed(midiEventIx, midiEvents.count()); } if (midiEvents.count() <= midiEventIx) { if (parserIx < parsersCount - 1) { ++parserIx; midiEventIx = 0; midiEvents = parsers[parserIx].getMIDIEvents(); midiTick = parsers[parserIx].getMidiTick(); continue; } if (!synth->isActive()) break; frameCount += bufferSize; qDebug() << "AudioFileWriter: Rendering after the end of MIDI file, time:" << (double)midiNanos / MasterClock::NANOS_PER_SECOND; } } while (frameCount > 0) { unsigned int framesToRender = qMin(bufferSize, frameCount); unsigned int framesRendered = synth->render(buffer, framesToRender, firstSampleNanos - latency, sampleRate); qint64 bytesToWrite = framesRendered * FRAME_SIZE; char *bufferPos = (char *)buffer; while (bytesToWrite > 0) { qint64 bytesWritten = file.write(bufferPos, bytesToWrite); if (bytesWritten == -1) { qDebug() << "AudioFileWriter: error writing into the audio file:" << file.errorString(); file.close(); return; } bytesToWrite -= bytesWritten; bufferPos += bytesWritten; } firstSampleNanos += MasterClock::NANOS_PER_SECOND * framesRendered / sampleRate; frameCount -= framesRendered; if (!realtimeMode) qDebug() << "AudioFileWriter: Rendering time:" << (double)firstSampleNanos / MasterClock::NANOS_PER_SECOND; } } qDebug() << "AudioFileWriter: Rendering finished"; if (!realtimeMode) qDebug() << "AudioFileWriter: Elapsed seconds: " << 1e-9 * (MasterClock::getClockNanos() - startNanos); if (waveMode) { unsigned char *charBuffer = (unsigned char *)buffer; memcpy(charBuffer, WAVE_HEADER, 44); quint32 fileSize = (quint32)file.size(); qToLittleEndian(fileSize - 8, charBuffer + 4); qToLittleEndian(fileSize - 44, charBuffer + 40); qToLittleEndian(sampleRate, charBuffer + 24); qToLittleEndian(sampleRate * FRAME_SIZE, charBuffer + 28); file.seek(0); file.write((char *)charBuffer, 44); } file.close(); synth->close(); if (!stopProcessing) emit conversionFinished(); }
void AudioFileWriter::run() { QFile file(outFileName); bool waveMode = false; if (outFileName.endsWith(".wav")) waveMode = true; if (!file.open(QIODevice::WriteOnly)) { qDebug() << "AudioFileWriter: Can't open file for writing:" << outFileName; synth->close(); if (!realtimeMode) { Master::getInstance()->setAudioFileWriterSynth(NULL); } return; } if (waveMode) file.seek(44); MasterClockNanos startNanos = MasterClock::getClockNanos(); MasterClockNanos firstSampleNanos = 0; MasterClockNanos midiTick = 0; MasterClockNanos midiNanos = 0; QMidiEventList midiEvents; int midiEventIx = 0; uint parserIx = 0; bool skipSilence = false; if (realtimeMode) { firstSampleNanos = startNanos; } else { midiEvents = parsers[parserIx].getMIDIEvents(); midiTick = parsers[parserIx].getMidiTick(); skipSilence = true; } qDebug() << "AudioFileWriter: Rendering started"; while (!stopProcessing) { uint frameCount = 0; if (realtimeMode) { frameCount = uint((sampleRate * (MasterClock::getClockNanos() - firstSampleNanos)) / MasterClock::NANOS_PER_SECOND); if (frameCount < bufferSize) { usleep(ulong((MasterClock::MICROS_PER_SECOND * (bufferSize - frameCount)) / sampleRate)); continue; } else { frameCount = bufferSize; } } else { while (midiEventIx < midiEvents.count()) { const QMidiEvent &e = midiEvents.at(midiEventIx); bool eventPushed = true; MasterClockNanos nextEventNanos = midiNanos + e.getTimestamp() * midiTick; quint32 nextEventFrames = quint32(((double)sampleRate * nextEventNanos) / MasterClock::NANOS_PER_SECOND); frameCount = uint((sampleRate * (nextEventNanos - firstSampleNanos)) / MasterClock::NANOS_PER_SECOND); if (bufferSize < frameCount) { frameCount = bufferSize; break; } switch (e.getType()) { case SHORT_MESSAGE: eventPushed = synth->playMIDIShortMessage(e.getShortMessage(), nextEventFrames); break; case SYSEX: eventPushed = synth->playMIDISysex(e.getSysexData(), e.getSysexLen(), nextEventFrames); break; case SET_TEMPO: midiTick = parsers[parserIx].getMidiTick(e.getShortMessage()); break; default: break; } if (!eventPushed) { qDebug() << "AudioFileWriter: MIDI buffer overflow, midiNanos:" << midiNanos; break; } midiNanos = nextEventNanos; midiEventIx++; emit midiEventProcessed(midiEventIx, midiEvents.count()); } if (midiEvents.count() <= midiEventIx) { if (parserIx < parsersCount - 1) { ++parserIx; midiEventIx = 0; midiEvents = parsers[parserIx].getMIDIEvents(); midiTick = parsers[parserIx].getMidiTick(); continue; } if (!synth->isActive() && frameCount == 0) break; frameCount += bufferSize; qDebug() << "AudioFileWriter: Rendering after the end of MIDI file, time:" << (double)midiNanos / MasterClock::NANOS_PER_SECOND; } } while (frameCount > 0) { uint framesToRender = qMin(bufferSize, frameCount); synth->render(buffer, framesToRender); // libmt32emu produces samples in native byte order QSynth::convertSamplesFromNativeEndian(buffer, framesToRender << 1, waveMode ? QSysInfo::LittleEndian : QSysInfo::BigEndian); qint64 bytesToWrite = framesToRender * FRAME_SIZE; char *bufferPos = (char *)buffer; if (skipSilence) { qint32 *startPos = (qint32 *)buffer; qint32 *endPos = startPos + framesToRender; bytesToWrite = 0; for (qint32 *p = startPos; p < endPos; p++) { if (*p != 0) { skipSilence = false; bufferPos = (char *)p; bytesToWrite = (char *)endPos - bufferPos; break; } } } while (bytesToWrite > 0) { qint64 bytesWritten = file.write(bufferPos, bytesToWrite); if (bytesWritten == -1) { qDebug() << "AudioFileWriter: error writing into the audio file:" << file.errorString(); file.close(); return; } bytesToWrite -= bytesWritten; bufferPos += bytesWritten; } firstSampleNanos += MasterClock::NANOS_PER_SECOND * framesToRender / sampleRate; frameCount -= framesToRender; if (!realtimeMode) qDebug() << "AudioFileWriter: Rendering time:" << (double)firstSampleNanos / MasterClock::NANOS_PER_SECOND; } } qDebug() << "AudioFileWriter: Rendering finished"; if (!realtimeMode) qDebug() << "AudioFileWriter: Elapsed seconds: " << 1e-9 * (MasterClock::getClockNanos() - startNanos); if (waveMode) { unsigned char *charBuffer = (unsigned char *)buffer; memcpy(charBuffer, WAVE_HEADER, 44); quint32 fileSize = (quint32)file.size(); qToLittleEndian(fileSize - 8, charBuffer + 4); qToLittleEndian(fileSize - 44, charBuffer + 40); qToLittleEndian(sampleRate, charBuffer + 24); qToLittleEndian(sampleRate * FRAME_SIZE, charBuffer + 28); file.seek(0); file.write((char *)charBuffer, 44); } file.close(); synth->close(); if (!realtimeMode) { Master::getInstance()->setAudioFileWriterSynth(NULL); } if (!stopProcessing) emit conversionFinished(); }
void AudioFileRenderer::run() { AudioFileWriter writer(sampleRate, outFileName); if (!writer.open(!realtimeMode)) { synth->close(); if (!realtimeMode) Master::getInstance()->setAudioFileWriterSynth(NULL); emit conversionFinished(); return; } MasterClockNanos startNanos = MasterClock::getClockNanos(); MasterClockNanos firstSampleNanos = 0; MasterClockNanos midiTick = 0; MasterClockNanos midiNanos = 0; QMidiEventList midiEvents; int midiEventIx = 0; uint parserIx = 0; if (realtimeMode) { firstSampleNanos = startNanos; } else { midiEvents = parsers[parserIx].getMIDIEvents(); midiTick = parsers[parserIx].getMidiTick(); } qDebug() << "AudioFileRenderer: Rendering started"; while (!stopProcessing) { uint frameCount = 0; if (realtimeMode) { frameCount = uint((sampleRate * (MasterClock::getClockNanos() - firstSampleNanos)) / MasterClock::NANOS_PER_SECOND); if (frameCount < bufferSize) { usleep(ulong((MasterClock::MICROS_PER_SECOND * (bufferSize - frameCount)) / sampleRate)); continue; } else { frameCount = bufferSize; } } else { while (midiEventIx < midiEvents.count()) { const QMidiEvent &e = midiEvents.at(midiEventIx); bool eventPushed = true; MasterClockNanos nextEventNanos = midiNanos + e.getTimestamp() * midiTick; quint32 nextEventFrames = quint32(((double)sampleRate * nextEventNanos) / MasterClock::NANOS_PER_SECOND); frameCount = uint((sampleRate * (nextEventNanos - firstSampleNanos)) / MasterClock::NANOS_PER_SECOND); if (bufferSize < frameCount) { frameCount = bufferSize; break; } switch (e.getType()) { case SHORT_MESSAGE: eventPushed = synth->playMIDIShortMessage(e.getShortMessage(), nextEventFrames); break; case SYSEX: eventPushed = synth->playMIDISysex(e.getSysexData(), e.getSysexLen(), nextEventFrames); break; case SET_TEMPO: midiTick = parsers[parserIx].getMidiTick(e.getShortMessage()); break; default: break; } if (!eventPushed) { qDebug() << "AudioFileRenderer: MIDI buffer overflow, midiNanos:" << midiNanos; break; } midiNanos = nextEventNanos; midiEventIx++; emit midiEventProcessed(midiEventIx, midiEvents.count()); } if (midiEvents.count() <= midiEventIx) { if (parserIx < parsersCount - 1) { ++parserIx; midiEventIx = 0; midiEvents = parsers[parserIx].getMIDIEvents(); midiTick = parsers[parserIx].getMidiTick(); continue; } if (!synth->isActive() && frameCount == 0) break; frameCount += bufferSize; qDebug() << "AudioFileRenderer: Rendering after the end of MIDI file, time:" << (double)midiNanos / MasterClock::NANOS_PER_SECOND; } } while (frameCount > 0) { uint framesToRender = qMin(bufferSize, frameCount); synth->render(buffer, framesToRender); if (!writer.write(buffer, framesToRender)) { synth->close(); if (!realtimeMode) Master::getInstance()->setAudioFileWriterSynth(NULL); emit conversionFinished(); return; } firstSampleNanos += MasterClock::NANOS_PER_SECOND * framesToRender / sampleRate; frameCount -= framesToRender; if (!realtimeMode) qDebug() << "AudioFileWriter: Rendering time:" << (double)firstSampleNanos / MasterClock::NANOS_PER_SECOND; } } qDebug() << "AudioFileRenderer: Rendering finished"; if (!realtimeMode) qDebug() << "AudioFileRenderer: Elapsed seconds: " << 1e-9 * (MasterClock::getClockNanos() - startNanos); writer.close(); synth->close(); if (!realtimeMode) Master::getInstance()->setAudioFileWriterSynth(NULL); if (!stopProcessing) emit conversionFinished(); }