Example #1
0
void FormatWidget::loadFormat()
{
    FormatsDialog fd(this->_hexedit->data()->length(), (this->_hexedit->selectionLength() ? this->_hexedit->cursorPos() : 0), this->topLevelWidget());
    int res = fd.exec();

    if(res == FormatsDialog::Accepted)
    {
        this->_formatview = nullptr;
        this->_logwidget->clear();
        this->_formatdefinition = fd.selectedFormat();

        Logger* logger = new Logger(this->_logwidget);
        bool validated = this->_formatdefinition->callValidate(this->_hexedit->data(), logger, fd.offset());

        if(!validated)
        {
            emit parsingFailed();
            logger->deleteLater();
            return;
        }

        this->_worker = new FormatWorker(this->_formatdefinition, logger, this->_hexedit->data(), fd.offset(), this);
        connect(this->_worker, SIGNAL(started()), this, SIGNAL(workStarted()));
        connect(this->_worker, SIGNAL(started()), this, SIGNAL(parsingStarted()));
        connect(this->_worker, SIGNAL(finished()), this, SIGNAL(workFinished()));
        connect(this->_worker, SIGNAL(finished()), this, SIGNAL(parsingCompleted()));
        connect(this->_worker, SIGNAL(parsingFailed()), this, SIGNAL(parsingFailed()));
        connect(this->_worker, SIGNAL(parsingCompleted()), this, SLOT(onParseCompleted()));
        this->_worker->start();
    }
}
Example #2
0
File: vim.cpp Project: Emm/Vee
bool Vim::parse(QString command) {
    bool result;
    qDebug() << "Parsing " << command;
    if (!command.startsWith(":")) {
        emit prefixMissing(command);
        result = false;
    }
    else {
        const QString & realCommand = QString(command).remove(0, 1).trimmed();
        if (realCommand.startsWith("open ") || realCommand.startsWith("o ")) {
            emit openCommand(realCommand.section(' ', 1).trimmed());
            result = true;
        }
        else if (realCommand.startsWith("tab ") || realCommand.startsWith("t ")) {
            emit openInNewTabCommand(realCommand.section(' ', 1).trimmed());
            result = true;
        }
        else if (realCommand == "quit" || realCommand == "q") {
            emit closeTabCommand();
            result = true;
        }
        else {
            emit parsingFailed(command);
            result = false;
        }
    }
    return result;
}
void CommunicationDescriptionGateway::requestReceived(QByteArray response) {
    if(networkRequest == NULL) {
        WLog("Response recieved, but request is already deleted! Cannot parse the response! This should never happen.");
        return;
    }

    Q_EMIT _receivedResponseData(response);

    networkResponse = networkRequest->getResponseParser();
    if (!networkResponse) {
        QList<BaseNetworkEntity*> emptyList;
        Q_EMIT this->finished(emptyList);
        _finishedWithCommunicationStep();
        return;
    }


    connect(networkResponse, SIGNAL(finished()), this, SLOT(responseFinished()));
    connect(networkResponse, SIGNAL(parsingFinished(QList<BaseNetworkEntity*>)), this, SIGNAL(finished(QList<BaseNetworkEntity*>)));
    connect(networkResponse, SIGNAL(parsingFailed(QString)), this, SIGNAL(failedToRetrieveDescription(QString)));

    //
    // parse in background
    QThreadPool::globalInstance()->start(networkResponse);
}
Example #4
0
bool AudioFileWriter::convertMIDIFiles(QString useOutFileName, QStringList midiFileNameList, QString synthProfileName, unsigned int useBufferSize) {
	if (useOutFileName.isEmpty() || midiFileNameList.isEmpty()) return false;
	delete[] parsers;
	parsersCount = midiFileNameList.size();
	parsers = new MidiParser[parsersCount];
	for (uint i = 0; i < parsersCount; i++) {
		if (!parsers[i].parse(midiFileNameList.at(i))) {
			qDebug() << "AudioFileWriter: Error parsing MIDI files";
			const QMidiEventList &midiEvents = parsers[i].getMIDIEvents();
			if (midiEvents.count() == 0) {
				QMessageBox::critical(NULL, "Error", "Error occured while parsing MIDI files. No MIDI events to process.");
				delete[] parsers;
				parsers = NULL;
				return false;
			}
			emit parsingFailed("Warning", "Error occured while parsing MIDI files. Processing available MIDI events.");
		}
	}
	parsers[parsersCount - 1].addChannelsReset();
	if (synth != NULL) {
		synth->close();
		delete synth;
	}
	synth = new QSynth(this);
	if (!synth->open(0, SampleRateConverter::SRC_BEST, synthProfileName)) {
		synth->close();
		delete synth;
		synth = NULL;
		delete[] parsers;
		parsers = NULL;
		qDebug() << "AudioFileWriter: Can't open synth";
		QMessageBox::critical(NULL, "Error", "Failed to open synth");
		return false;
	}
	Master::getInstance()->setAudioFileWriterSynth(synth);
	sampleRate = synth->getSynthSampleRate();
	bufferSize = useBufferSize;
	outFileName = useOutFileName;
	realtimeMode = false;
	stopProcessing = false;
	delete[] buffer;
	buffer = new qint16[2 * bufferSize];
	QThread::start();
	return true;
}
void QWaveDecoder::handleData()
{
    // As a special "state", if we have junk to skip, we do
    if (junkToSkip > 0) {
        discardBytes(junkToSkip); // this also updates junkToSkip

        // If we couldn't skip all the junk, return
        if (junkToSkip > 0) {
            // We might have run out
            if (source->atEnd())
                parsingFailed();
            return;
        }
    }

    if (state == QWaveDecoder::InitialState) {
        if (source->bytesAvailable() < qint64(sizeof(RIFFHeader)))
            return;

        RIFFHeader riff;
        source->read(reinterpret_cast<char *>(&riff), sizeof(RIFFHeader));

        // RIFF = little endian RIFF, RIFX = big endian RIFF
        if (((qstrncmp(riff.descriptor.id, "RIFF", 4) != 0) && (qstrncmp(riff.descriptor.id, "RIFX", 4) != 0))
                || qstrncmp(riff.type, "WAVE", 4) != 0) {
            parsingFailed();
            return;
        } else {
            state = QWaveDecoder::WaitingForFormatState;
            if (qstrncmp(riff.descriptor.id, "RIFX", 4) == 0)
                bigEndian = true;
            else
                bigEndian = false;
        }
    }

    if (state == QWaveDecoder::WaitingForFormatState) {
        if (findChunk("fmt ")) {
            chunk descriptor;
            peekChunk(&descriptor);

            quint32 rawChunkSize = descriptor.size + sizeof(chunk);
            if (source->bytesAvailable() < qint64(rawChunkSize))
                return;

            WAVEHeader wave;
            source->read(reinterpret_cast<char *>(&wave), sizeof(WAVEHeader));

            if (rawChunkSize > sizeof(WAVEHeader))
                discardBytes(rawChunkSize - sizeof(WAVEHeader));

            // Swizzle this
            if (bigEndian) {
                wave.audioFormat = qFromBigEndian<quint16>(wave.audioFormat);
            } else {
                wave.audioFormat = qFromLittleEndian<quint16>(wave.audioFormat);
            }

            if (wave.audioFormat != 0 && wave.audioFormat != 1) {
                // 32bit wave files have format == 0xFFFE (WAVE_FORMAT_EXTENSIBLE).
                // but don't support them at the moment.
                parsingFailed();
                return;
            } else {
                format.setCodec(QLatin1String("audio/pcm"));

                if (bigEndian) {
                    int bps = qFromBigEndian<quint16>(wave.bitsPerSample);

                    format.setSampleType(bps == 8 ? QAudioFormat::UnSignedInt : QAudioFormat::SignedInt);
                    format.setByteOrder(QAudioFormat::BigEndian);
                    format.setSampleRate(qFromBigEndian<quint32>(wave.sampleRate));
                    format.setSampleSize(bps);
                    format.setChannelCount(qFromBigEndian<quint16>(wave.numChannels));
                } else {
                    int bps = qFromLittleEndian<quint16>(wave.bitsPerSample);

                    format.setSampleType(bps == 8 ? QAudioFormat::UnSignedInt : QAudioFormat::SignedInt);
                    format.setByteOrder(QAudioFormat::LittleEndian);
                    format.setSampleRate(qFromLittleEndian<quint32>(wave.sampleRate));
                    format.setSampleSize(bps);
                    format.setChannelCount(qFromLittleEndian<quint16>(wave.numChannels));
                }

                state = QWaveDecoder::WaitingForDataState;
            }
        }
    }

    if (state == QWaveDecoder::WaitingForDataState) {
        if (findChunk("data")) {
            source->disconnect(SIGNAL(readyRead()), this, SLOT(handleData()));

            chunk descriptor;
            source->read(reinterpret_cast<char *>(&descriptor), sizeof(chunk));
            if (bigEndian)
                descriptor.size = qFromBigEndian<quint32>(descriptor.size);
            else
                descriptor.size = qFromLittleEndian<quint32>(descriptor.size);

            dataSize = descriptor.size;

            haveFormat = true;
            connect(source, SIGNAL(readyRead()), SIGNAL(readyRead()));
            emit formatKnown();

            return;
        }
    }

    // If we hit the end without finding data, it's a parsing error
    if (source->atEnd()) {
        parsingFailed();
    }
}