void SoundSourceProxy::initSoundSource() { DEBUG_ASSERT(m_pSoundSource.isNull()); DEBUG_ASSERT(m_pAudioSource.isNull()); while (m_pSoundSource.isNull()) { Mixxx::SoundSourceProviderPointer pProvider(getSoundSourceProvider()); if (pProvider.isNull()) { qWarning() << "No SoundSourceProvider for file" << getUrl(); // Failure return; } m_pSoundSource = pProvider->newSoundSource(m_url); if (m_pSoundSource.isNull()) { qWarning() << "SoundSourceProvider" << pProvider->getName() << "failed to create a SoundSource for file" << getUrl(); // Switch to next provider... nextSoundSourceProvider(); // ...and continue loop DEBUG_ASSERT(m_pSoundSource.isNull()); } else { QString trackType(m_pSoundSource->getType()); qDebug() << "SoundSourceProvider" << pProvider->getName() << "created a SoundSource for file" << getUrl() << "of type" << trackType; if (!m_pTrack.isNull()) { m_pTrack->setType(trackType); } } } }
// Adjust clip length to (new) selected file. void qtractorClipForm::fileChanged ( const QString& sFilename, unsigned short iTrackChannel ) { if (m_iDirtySetup > 0) return; qtractorSession *pSession = qtractorSession::getInstance(); if (pSession == NULL) return; // Do nothing else if file is invalid... QFileInfo fi(sFilename); if (!fi.exists()) { changed(); return; } // Give as clip name hint if blank or new... if (m_ui.ClipNameLineEdit->text().isEmpty() || m_bClipNew) m_ui.ClipNameLineEdit->setText(fi.baseName()); // Depending on the clip/track type, // set clip length to the file length (in frames)... unsigned long iClipLength = 0; switch (trackType()) { case qtractorTrack::Midi: { qtractorMidiFile file; if (file.open(sFilename)) { const unsigned short p = pSession->ticksPerBeat(); const unsigned short q = file.ticksPerBeat(); const unsigned long iTrackDuration = file.readTrackDuration(iTrackChannel); if (iTrackDuration > 0) { const unsigned long duration = uint64_t(iTrackDuration * p) / q; iClipLength = pSession->frameFromTick(duration); } file.close(); } break; } case qtractorTrack::Audio: { qtractorAudioFile *pFile = qtractorAudioFileFactory::createAudioFile(sFilename); if (pFile) { if (pFile->open(sFilename)) { iClipLength = pFile->frames(); if (pFile->sampleRate() > 0 && pFile->sampleRate() != pSession->sampleRate()) { iClipLength = (unsigned long) (iClipLength * float(pSession->sampleRate()) / float(pFile->sampleRate())); } pFile->close(); } delete pFile; } break; } case qtractorTrack::None: default: break; } // Done. m_ui.ClipOffsetSpinBox->setValue(0); m_ui.ClipLengthSpinBox->setValue(iClipLength); changed(); }
// Browse for audio clip filename. void qtractorClipForm::browseFilename (void) { QString sType; QString sExt; QString sFilter; qtractorTrack::TrackType clipType = trackType(); switch (clipType) { case qtractorTrack::Audio: sType = tr("Audio"); sExt = qtractorAudioFileFactory::defaultExt(); sFilter = qtractorAudioFileFactory::filters(); break; case qtractorTrack::Midi: sType = tr("MIDI"); sExt = "mid"; sFilter = tr("MIDI files (*.%1 *.smf *.midi)").arg(sExt); break; case qtractorTrack::None: default: return; } // Browse for file... QString sFilename; const QString& sTitle = tr("%1 Clip File").arg(sType) + " - " QTRACTOR_TITLE; #if 1//QT_VERSION < 0x040400 QFileDialog::Options options = 0; qtractorOptions *pOptions = qtractorOptions::getInstance(); if (pOptions && pOptions->bDontUseNativeDialogs) options |= QFileDialog::DontUseNativeDialog; sFilename = QFileDialog::getOpenFileName(this, sTitle, m_ui.FilenameComboBox->currentText(), sFilter, NULL, options); #else QFileDialog fileDialog(this, sTitle, m_ui.FilenameComboBox->currentText(), sFilter); // Set proper open-file modes... fileDialog.setAcceptMode(QFileDialog::AcceptOpen); fileDialog.setFileMode(QFileDialog::ExistingFile); fileDialog.setDefaultSuffix(sExt); // Stuff sidebar... qtractorOptions *pOptions = qtractorOptions::getInstance(); if (pOptions) { QList<QUrl> urls(fileDialog.sidebarUrls()); urls.append(QUrl::fromLocalFile(pOptions->sSessionDir)); switch (clipType) { case qtractorTrack::Audio: urls.append(QUrl::fromLocalFile(pOptions->sAudioDir)); break; case qtractorTrack::Midi: urls.append(QUrl::fromLocalFile(pOptions->sMidiDir)); break; case qtractorTrack::None: default: break; } fileDialog.setSidebarUrls(urls); if (pOptions->bDontUseNativeDialogs) fileDialog.setOptions(QFileDialog::DontUseNativeDialog); } // Show dialog... if (fileDialog.exec()) sFilename = fileDialog.selectedFiles().first(); #endif if (!sFilename.isEmpty()) { m_ui.FilenameComboBox->setEditText(sFilename); m_ui.FilenameComboBox->setFocus(); // changed(); } }
// Accept settings (OK button slot). void qtractorClipForm::accept (void) { // Sanity check... if (m_pClip == NULL) return; if (!m_pClip->queryEditor()) return; qtractorSession *pSession = qtractorSession::getInstance(); if (pSession == NULL) return; // Save settings... if (m_iDirtyCount > 0) { // Cache the changed settings (if any)... qtractorClipCommand *pClipCommand = NULL; qtractorTrack::TrackType clipType = trackType(); const QString& sFilename = m_ui.FilenameComboBox->currentText(); const unsigned short iTrackChannel = m_ui.TrackChannelSpinBox->value(); const QString& sClipName = m_ui.ClipNameLineEdit->text(); float fClipGain = 1.0f; float fTimeStretch = 0.0f; float fPitchShift = 0.0f; switch (clipType) { case qtractorTrack::Audio: fClipGain = pow10f2(m_ui.ClipGainSpinBox->value()); fTimeStretch = 0.01f * m_ui.TimeStretchSpinBox->value(); fPitchShift = ::powf(2.0f, m_ui.PitchShiftSpinBox->value() / 12.0f); break; case qtractorTrack::Midi: fClipGain = 0.01f * m_ui.ClipGainSpinBox->value(); break; default: break; } const unsigned long iClipStart = m_ui.ClipStartSpinBox->value(); const unsigned long iClipOffset = m_ui.ClipOffsetSpinBox->value(); const unsigned long iClipLength = m_ui.ClipLengthSpinBox->value(); const unsigned long iFadeInLength = m_ui.FadeInLengthSpinBox->value(); qtractorClip::FadeType fadeInType = fadeTypeFromIndex(m_ui.FadeInTypeComboBox->currentIndex()); const unsigned long iFadeOutLength = m_ui.FadeOutLengthSpinBox->value(); qtractorClip::FadeType fadeOutType = fadeTypeFromIndex(m_ui.FadeOutTypeComboBox->currentIndex()); int iFileChange = 0; // It depends whether we're adding a new clip or not... if (m_bClipNew) { // Just set new clip properties... pClipCommand = new qtractorClipCommand(tr("new clip")); m_pClip->setClipName(sClipName); // Filename... m_pClip->setFilename(sFilename); // Track-channel and time-stretching... switch (clipType) { case qtractorTrack::Audio: { qtractorAudioClip *pAudioClip = static_cast<qtractorAudioClip *> (m_pClip); if (pAudioClip) { pAudioClip->setTimeStretch(fTimeStretch); pAudioClip->setPitchShift(fPitchShift); ++iFileChange; } break; } case qtractorTrack::Midi: { qtractorMidiClip *pMidiClip = static_cast<qtractorMidiClip *> (m_pClip); if (pMidiClip) { pMidiClip->setTrackChannel(iTrackChannel); ++iFileChange; } break; } case qtractorTrack::None: default: break; } // Gain/volume... m_pClip->setClipGain(fClipGain); // Parameters... m_pClip->setClipStart(iClipStart); m_pClip->setClipOffset(iClipOffset); m_pClip->setClipLength(iClipLength); // Fade in... m_pClip->setFadeInLength(iFadeInLength); m_pClip->setFadeInType(fadeInType); // Fade out... m_pClip->setFadeOutLength(iFadeOutLength); m_pClip->setFadeOutType(fadeOutType); // Ready it... pClipCommand->addClip(m_pClip, m_pClip->track()); // Ready new. } else { // Make changes (incrementally) undoable... pClipCommand = new qtractorClipCommand(tr("edit clip")); pClipCommand->renameClip(m_pClip, sClipName); // Filename changes... if (sFilename != m_pClip->filename()) ++iFileChange; // Track-channel and time-stretch issues... switch (clipType) { case qtractorTrack::Audio: { qtractorAudioClip *pAudioClip = static_cast<qtractorAudioClip *> (m_pClip); if (pAudioClip) { if (::fabsf(fTimeStretch - pAudioClip->timeStretch()) < 0.001f) fTimeStretch = 0.0f; if (::fabsf(fPitchShift - pAudioClip->pitchShift()) < 0.001f) fPitchShift = 0.0f; } break; } case qtractorTrack::Midi: { qtractorMidiClip *pMidiClip = static_cast<qtractorMidiClip *> (m_pClip); if (pMidiClip) { if (iTrackChannel != pMidiClip->trackChannel()) ++iFileChange; } break; } case qtractorTrack::None: default: break; } // Filename and/or track-channel changes... if (iFileChange > 0) pClipCommand->fileClip(m_pClip, sFilename, iTrackChannel); // Gain/volume... if (::fabsf(fClipGain - m_pClip->clipGain()) > 0.001f) pClipCommand->gainClip(m_pClip, fClipGain); // Parameters and/or time-stretching changes... if (iClipStart != m_pClip->clipStart() || iClipOffset != m_pClip->clipOffset() || iClipLength != m_pClip->clipLength() || fTimeStretch > 0.0f || fPitchShift > 0.0f) { pClipCommand->resizeClip(m_pClip, iClipStart, iClipOffset, iClipLength, fTimeStretch, fPitchShift); } // Fade in changes... if (iFadeInLength != m_pClip->fadeInLength() || fadeInType != m_pClip->fadeInType()) pClipCommand->fadeInClip(m_pClip, iFadeInLength, fadeInType); // Fade out changes... if (iFadeOutLength != m_pClip->fadeOutLength() || fadeOutType != m_pClip->fadeOutType()) pClipCommand->fadeOutClip(m_pClip, iFadeOutLength, fadeOutType); // Ready edit. } // Do it (by making it undoable)... if (pClipCommand) pSession->execute(pClipCommand); // Account for a new file in game... qtractorMainForm *pMainForm = qtractorMainForm::getInstance(); if (iFileChange > 0 && pMainForm) { switch (clipType) { case qtractorTrack::Audio: pMainForm->addAudioFile(sFilename); break; case qtractorTrack::Midi: pMainForm->addMidiFile(sFilename); break; case qtractorTrack::None: default: break; } // Save history conveniency options... qtractorOptions *pOptions = qtractorOptions::getInstance(); if (pOptions) pOptions->saveComboBoxHistory(m_ui.FilenameComboBox); } // Reset dirty flag. m_iDirtyCount = 0; } // Just go with dialog acceptance. QDialog::accept(); }
// Populate (setup) dialog controls from settings descriptors. void qtractorClipForm::setClip ( qtractorClip *pClip, bool bClipNew ) { // Initialize conveniency options... qtractorSession *pSession = qtractorSession::getInstance(); if (pSession == NULL) return; // Mark that we're changing thing's here... ++m_iDirtySetup; // Clip properties cloning... m_pClip = pClip; m_bClipNew = bClipNew; // Why not change the dialog icon accordingly? if (m_bClipNew) QDialog::setWindowIcon(QIcon(":/images/editClipNew.png")); // Copy from global time-scale instance... if (m_pTimeScale) delete m_pTimeScale; m_pTimeScale = new qtractorTimeScale(*pSession->timeScale()); m_ui.ClipStartSpinBox->setTimeScale(m_pTimeScale); m_ui.ClipOffsetSpinBox->setTimeScale(m_pTimeScale); m_ui.ClipLengthSpinBox->setTimeScale(m_pTimeScale); m_ui.FadeInLengthSpinBox->setTimeScale(m_pTimeScale); m_ui.FadeOutLengthSpinBox->setTimeScale(m_pTimeScale); // These have special delta formats... clipStartChanged(m_pClip->clipStart()); // Initialize dialog widgets... m_ui.ClipNameLineEdit->setText(m_pClip->clipName()); // Parameters... m_ui.ClipStartSpinBox->setValue(m_pClip->clipStart()); m_ui.ClipOffsetSpinBox->setValue(m_pClip->clipOffset()); m_ui.ClipLengthSpinBox->setValue(m_pClip->clipLength()); // Fade In/Out... m_ui.FadeInLengthSpinBox->setValue(m_pClip->fadeInLength()); m_ui.FadeInTypeComboBox->setCurrentIndex( indexFromFadeType(m_pClip->fadeInType())); m_ui.FadeOutLengthSpinBox->setValue(m_pClip->fadeOutLength()); m_ui.FadeOutTypeComboBox->setCurrentIndex( indexFromFadeType(m_pClip->fadeOutType())); // Set proper time scales display format... m_ui.FormatComboBox->setCurrentIndex( int(m_pTimeScale->displayFormat())); // Now those things specific on track type... const QString sSuffix = m_ui.FilenameComboBox->objectName(); switch (trackType()) { case qtractorTrack::Audio: { m_ui.FilenameComboBox->setObjectName("Audio" + sSuffix); m_ui.GainVolumeGroupBox->setTitle(tr("&Gain:")); m_ui.ClipGainSpinBox->setSuffix(tr(" dB")); m_ui.ClipGainSpinBox->setRange(-60.0f, +24.0f); m_ui.ClipGainSpinBox->setValue(log10f2(m_pClip->clipGain())); qtractorAudioClip *pAudioClip = static_cast<qtractorAudioClip *> (m_pClip); if (pAudioClip) { m_ui.TimeStretchSpinBox->setValue( 100.0f * pAudioClip->timeStretch()); m_ui.PitchShiftSpinBox->setValue( 12.0f * ::logf(pAudioClip->pitchShift()) / M_LN2); } m_ui.TrackChannelTextLabel->setVisible(false); m_ui.TrackChannelSpinBox->setVisible(false); m_ui.AudioClipGroupBox->setVisible(true); #ifndef CONFIG_LIBRUBBERBAND m_ui.PitchShiftTextLabel->setEnabled(false); m_ui.PitchShiftSpinBox->setEnabled(false); #endif break; } case qtractorTrack::Midi: { m_ui.FilenameComboBox->setObjectName("Midi" + sSuffix); m_ui.GainVolumeGroupBox->setTitle(tr("&Volume:")); m_ui.ClipGainSpinBox->setSuffix(tr(" %")); m_ui.ClipGainSpinBox->setRange(0.0f, 1200.0f); m_ui.ClipGainSpinBox->setValue(100.0f * m_pClip->clipGain()); qtractorMidiClip *pMidiClip = static_cast<qtractorMidiClip *> (m_pClip); if (pMidiClip) m_ui.TrackChannelSpinBox->setValue(pMidiClip->trackChannel()); m_ui.TrackChannelTextLabel->setVisible(true); m_ui.TrackChannelSpinBox->setVisible(true); m_ui.AudioClipGroupBox->setVisible(false); break; } case qtractorTrack::None: default: m_ui.TrackChannelTextLabel->setVisible(false); m_ui.TrackChannelSpinBox->setVisible(false); m_ui.AudioClipGroupBox->setVisible(false); break; } qtractorOptions *pOptions = qtractorOptions::getInstance(); if (pOptions) pOptions->loadComboBoxHistory(m_ui.FilenameComboBox); // Finally set clip filename... m_ui.FilenameComboBox->setEditText(m_pClip->filename()); // Shake it a little bit first, but // make it as tight as possible... // resize(width() - 1, height() - 1); adjustSize(); // Backup clean. --m_iDirtySetup; m_iDirtyCount = 0; // Done. stabilizeForm(); }