63 setWindowFlags( windowFlags() | Qt::CustomizeWindowHint |
64 Qt::WindowMinMaxButtonsHint );
87 QString newfilename = sSampleFilename.section(
'/', -1 );
94 setWindowTitle ( QString( tr(
"SampleEditor " ) + newfilename) );
105 LoopCountSpinBox->setRange(0, 20000 );
106 StartFrameSpinBox->setRange(0, slframes );
107 LoopFrameSpinBox->setRange(0, slframes );
108 EndFrameSpinBox->setRange(0, slframes );
109 EndFrameSpinBox->setValue( slframes );
110 rubberbandCsettingscomboBox->setCurrentIndex( 4 );
111 rubberComboBox->setCurrentIndex( 0 );
114 pitchdoubleSpinBox->setLocale( QLocale( QLocale::C, QLocale::AnyCountry ) );
121#ifndef H2CORE_HAVE_RUBBERBAND
123 RubberbandCframe->setDisabled (
true );
127 RubberbandCframe->setDisabled (
false );
161 if ( QMessageBox::information(
162 this,
"Hydrogen", pCommonStrings->getUnsavedChanges(),
163 QMessageBox::Ok | QMessageBox::Cancel,
164 QMessageBox::Cancel ) == QMessageBox::Ok ) {
180 if ( pInstrument ==
nullptr ) {
181 ERRORLOG(
"No instrument selected" );
186 if ( pCompo ==
nullptr ) {
193 if ( pLayer ==
nullptr ) {
199 return pLayer->get_sample();
205 if ( pInstrument ==
nullptr ) {
206 ERRORLOG(
"No instrument selected" );
211 if ( pCompo ==
nullptr ) {
218 if ( pLayer ==
nullptr ) {
224 auto pSample = pLayer->get_sample();
225 if ( pSample ==
nullptr ) {
226 ERRORLOG(
"Unable to retrieve sample" );
235 __loops = pSample->get_loops();
240 if (
__loops.start_frame == 0 &&
243 __loops.end_frame = pSample->get_frames();
247 if ( pSample->get_velocity_envelope()->size()==0 ) {
254 for(
auto& pt : *pSample->get_velocity_envelope() ){
259 if ( pSample->get_pan_envelope()->size()==0 ) {
264 for(
auto& pt : *pSample->get_pan_envelope() ){
270 __loops.end_frame = pSample->get_loops().end_frame;
272 ProcessingTypeComboBox->setCurrentIndex ( 0 );
275 ProcessingTypeComboBox->setCurrentIndex ( 1 );
278 ProcessingTypeComboBox->setCurrentIndex ( 2 );
281 StartFrameSpinBox->setValue(
__loops.start_frame );
282 LoopFrameSpinBox->setValue(
__loops.loop_frame );
283 EndFrameSpinBox->setValue(
__loops.end_frame );
284 LoopCountSpinBox->setValue(
__loops.count );
294 rubberComboBox->setCurrentIndex( 0 );
297 rubberbandCsettingscomboBox->setCurrentIndex(
__rubberband.c_settings );
299 rubberbandCsettingscomboBox->setCurrentIndex( 4 );
304 pitchdoubleSpinBox->setValue( 0.0 );
308 rubberComboBox->setCurrentIndex( 1 );
311 rubberComboBox->setCurrentIndex( 2 );
313 rubberComboBox->setCurrentIndex( 3 );
315 rubberComboBox->setCurrentIndex( 4 );
317 rubberComboBox->setCurrentIndex( 5 );
319 rubberComboBox->setCurrentIndex( 6 );
321 rubberComboBox->setCurrentIndex( (
int)(
__rubberband.divider + 6) );
335 connect( rubberComboBox, SIGNAL( currentIndexChanged (
const QString ) ),
this, SLOT(
valueChangedrubberComboBox(
const QString ) ) );
342 __loops.start_frame = StartFrameSpinBox->value();
343 __loops.loop_frame = LoopFrameSpinBox->value();
344 __loops.count = LoopCountSpinBox->value();
345 __loops.end_frame = EndFrameSpinBox->value();
369 if ( QMessageBox::information(
370 this,
"Hydrogen", pCommonStrings->getUnsavedChanges(),
371 QMessageBox::Ok | QMessageBox::Cancel,
372 QMessageBox::Cancel ) == QMessageBox::Ok ) {
389 QApplication::setOverrideCursor(Qt::WaitCursor);
394 QApplication::restoreOverrideCursor();
404 return QMessageBox::information(
405 this,
"Hydrogen", pCommonStrings->getUnsavedChanges(),
406 QMessageBox::Ok | QMessageBox::Cancel,
407 QMessageBox::Cancel ) == QMessageBox::Ok;
417 auto pAudioEngine = pHydrogen->getAudioEngine();
419 if ( pOldSample ==
nullptr ) {
420 ERRORLOG(
"Unable to retrieve sample" );
421 assert( pOldSample );
426 pOldSample->getLicense() );
427 pEditSample->set_loops(
__loops );
432 if( ! pEditSample->load( pAudioEngine->getTransportPosition()->getBpm() ) ){
433 ERRORLOG(
"Unable to load modified sample" );
439 std::shared_ptr<H2Core::Instrument> pInstrument =
nullptr;
440 auto pSong = pHydrogen->getSong();
441 if ( pSong !=
nullptr ) {
442 auto pInstrList = pSong->getInstrumentList();
443 int nInstr = pHydrogen->getSelectedInstrumentNumber();
444 if ( nInstr >=
static_cast<int>(pInstrList->size()) ) {
449 pInstrument =
nullptr;
452 pInstrument = pInstrList->get( nInstr );
456 std::shared_ptr<H2Core::InstrumentLayer> pLayer =
nullptr;
457 if( pInstrument !=
nullptr ) {
461 pLayer->set_sample( pEditSample );
464 pAudioEngine->unlock();
466 if ( pLayer !=
nullptr ) {
491 StartFrameSpinBox->setValue(
__loops.start_frame );
492 LoopFrameSpinBox->setValue(
__loops.loop_frame );
493 EndFrameSpinBox->setValue(
__loops.end_frame );
512 PrevChangesPushButton->setDisabled (
false );
513 PrevChangesPushButton->setFlat (
false );
520 PrevChangesPushButton->setDisabled (
true );
521 PrevChangesPushButton->setFlat (
true );
602 if (PlayPushButton->text() ==
"Stop" ){
610 if ( pSong ==
nullptr ) {
614 if ( pInstr ==
nullptr ) {
618 if ( pCompo ==
nullptr ) {
621 auto pLayer = pCompo->get_layer( selectedLayer );
622 if ( pLayer ==
nullptr ) {
625 Note *pNote =
new Note( pInstr, 0, pLayer->get_end_velocity() - 0.01 );
650 PlayPushButton->setText( QString(
"Stop") );
656 if (PlayOrigPushButton->text() ==
"Stop" ){
661 auto tearDown = [&]() {
663 StartFrameSpinBox->value() /
m_divider + 24 ,
true);
668 pHydrogen->getAudioEngine()->getRealtimeFrame() +
m_nSlframes;
669 PlayOrigPushButton->setText( QString(
"Stop") );
672 auto pSong = pHydrogen->getSong();
673 if ( pSong ==
nullptr ) {
678 const int nSelectedlayer =
680 auto pInstr = pSong->getInstrumentList()->get(
681 pHydrogen->getSelectedInstrumentNumber() );
682 if ( pInstr ==
nullptr ) {
683 DEBUGLOG(
"No instrument selected" );
694 pInstr->get_drumkit_path(), pInstr->get_name() );
695 if ( pTmpInstrument ==
nullptr ) {
696 ERRORLOG( QString(
"Unable to load instrument [%1] from [%2]" )
697 .arg( pInstr->get_name() ).arg( pInstr->get_drumkit_path() ) );
702 ->get_layer( nSelectedlayer )->get_sample()->get_filepath();
704 if ( pNewSample ==
nullptr ) {
705 ERRORLOG( QString(
"Unable to load sample from [%1]" )
706 .arg( sSamplePath ) );
710 const int nLength = ( pNewSample->get_frames() /
711 pNewSample->get_sample_rate() + 1 ) * 100;
712 pHydrogen->getAudioEngine()->getSampler()->preview_instrument( pTmpInstrument );
713 pHydrogen->getAudioEngine()->getSampler()->preview_sample( pNewSample, nLength );
736 PlayPushButton->setText( pCommonString->getButtonPlay() );
737 PlayOrigPushButton->setText( pCommonString->getButtonPlayOriginalSample() );
745 unsigned targetSampleLength;
760 PlayPushButton->setText( pCommonString->getButtonPlay() );
761 PlayOrigPushButton->setText( pCommonString->getButtonPlayOriginalSample() );
772 unsigned oneSampleLength =
__loops.end_frame -
__loops.start_frame;
774 unsigned repeatsLength = loopLength *
__loops.count;
775 unsigned newLength = 0;
776 if (oneSampleLength == loopLength){
777 newLength = oneSampleLength + oneSampleLength *
__loops.count ;
780 newLength =oneSampleLength + repeatsLength;
785 unsigned * normalFrames =
new unsigned[ normalLength ];
786 unsigned * tempFrames =
new unsigned[ newLength ];
787 unsigned * loopFrames =
new unsigned[ loopLength ];
789 for (
unsigned i = 0; i < normalLength; i++ ) {
794 long int z =
__loops.loop_frame;
795 long int y =
__loops.start_frame;
797 for (
unsigned i = 0; i < newLength; i++){
801 for (
unsigned i = 0; i < oneSampleLength; i++, y++){
803 tempFrames[i] = normalFrames[y];
806 for (
unsigned i = 0; i < loopLength; i++, z++){
808 loopFrames[i] = normalFrames[z];
812 std::reverse(loopFrames, loopFrames + loopLength);
816 std::reverse( tempFrames, tempFrames + oneSampleLength );
820 std::reverse(loopFrames, loopFrames + loopLength);
823 for (
int i = 0; i<
__loops.count ;i++){
824 unsigned tempdataend = oneSampleLength + ( loopLength * i );
826 std::copy( loopFrames, loopFrames+loopLength ,tempFrames+ tempdataend );
829 std::reverse(loopFrames, loopFrames + loopLength);
832 std::copy( loopFrames, loopFrames+loopLength ,tempFrames+ tempdataend );
838 std::reverse( tempFrames +
__loops.loop_frame, tempFrames + newLength);
849 delete[] normalFrames;
857 unsigned oneSampleLength =
__loops.end_frame -
__loops.start_frame;
859 unsigned repeatsLength = loopLength *
__loops.count;
860 unsigned newLength = 0;
862 if ( oneSampleLength == loopLength ){
863 newLength = oneSampleLength + oneSampleLength *
__loops.count ;
865 newLength =oneSampleLength + repeatsLength;
869 newlengthLabel->setText(QString( tr(
"new sample length" ) )
870 .append( QString(
": %1 " ).arg(newLength) )
871 .append( tr(
"frames" )));
880 int count = LoopCountSpinBox->value();
888 const auto pAudioDriver = pHydrogen->getAudioOutput();
889 if ( pAudioDriver ==
nullptr ) {
890 ERRORLOG(
"AudioDriver is not ready!" );
894 if (
m_nSlframes > pAudioDriver->getSampleRate() * 60 ){
895 pHydrogen->getAudioEngine()->getSampler()->stopPlayingNotes();
903 if (
m_nSlframes > pAudioDriver->getSampleRate() * 60 * 30){
904 LoopCountSpinBox->setMaximum(LoopCountSpinBox->value() -1);
913 int new_settings = rubberbandCsettingscomboBox->currentIndex();
926 double new_value = pitchdoubleSpinBox->value();
927 if (std::abs(new_value -
__rubberband.pitch) < 0.0001) {
939 if( rubberComboBox->currentText() !=
"off" ){
948 switch ( rubberComboBox->currentIndex() ){
974 __rubberband.divider = (float)rubberComboBox->currentIndex() - 6.0;
990 if (induration != 0.0)
m_fRatio = durationtime / induration;
1002 rubberComboBox->setStyleSheet(
"QComboBox { background-color: green; }");
1006 rubberComboBox->setStyleSheet(
"QComboBox { background-color: yellow; }");
1010 rubberComboBox->setStyleSheet(
"QComboBox { background-color: red; }");
1012 QString text = QString( tr(
" RB-Ratio" ) )
1013 .append( QString(
" %1" ).arg(
m_fRatio ) );
1014 ratiolabel->setText( text );
1018 rubberComboBox->setStyleSheet(
"QComboBox { background-color: 58, 62, 72; }");
1019 ratiolabel->setText(
"" );
1026 switch ( ProcessingTypeComboBox->currentIndex() ){
1060 StartFrameSpinBox->setValue(
__loops.start_frame );
1061 LoopFrameSpinBox->setValue(
__loops.loop_frame );
1062 EndFrameSpinBox->setValue(
__loops.end_frame );
1075 PlayPushButton->setText( pCommonString->getButtonPlay() );
1076 PlayOrigPushButton->setText( pCommonString->getButtonPlayOriginalSample() );
#define RIGHT_HERE
Macro intended to be used for the logging of the locking of the H2Core::AudioEngine.
Sampler * getSampler() const
const std::shared_ptr< TransportPosition > getTransportPosition() const
long long getRealtimeFrame() const
A container for a sample, being able to apply modifications on it.
static bool file_executable(const QString &path, bool silent=false)
returns true if the given path is an existing executable regular file
std::shared_ptr< Song > getSong() const
Get the current song.
static Hydrogen * get_instance()
Returns the current Hydrogen instance __instance.
AudioEngine * getAudioEngine() const
std::shared_ptr< Instrument > getSelectedInstrument() const
void setIsModified(bool bIsModified)
Wrapper around Song::setIsModified() that checks whether a song is set.
static std::shared_ptr< Instrument > load_instrument(const QString &drumkit_path, const QString &instrument_name)
creates a new Instrument, loads samples from a given instrument within a given drumkit
A note plays an associated instrument with a velocity left and right pan.
void set_specific_compo_id(int value)
__specific_compo_id setter
static Preferences * get_instance()
Returns a pointer to the current Preferences singleton stored in __instance.
LoopMode
possible sample editing loop mode
static std::shared_ptr< Sample > load(const QString &filepath, const License &license=License())
void noteOn(Note *pNote)
Start playing a note.
void stopPlayingNotes(std::shared_ptr< Instrument > pInstr=nullptr)
static HydrogenApp * get_instance()
Returns the instance of HydrogenApp class.
std::shared_ptr< CommonStrings > getCommonStrings()
static InstrumentEditorPanel * get_instance()
void updateTargetsamplePositionRuler()
void updateMainsamplePositionRuler()
MainSampleWaveDisplay * m_pMainSampleWaveDisplay
bool returnAllMainWaveDisplayValues()
unsigned * m_pPositionsRulerPath
std::shared_ptr< H2Core::Sample > m_pSampleFromFile
void valueChangedLoopFrameSpinBox(int)
void getAllLocalFrameInfos()
std::shared_ptr< H2Core::Sample > retrieveSample() const
void returnAllTargetDisplayValues()
void createPositionsRulerPath()
H2Core::Sample::Loops __loops
unsigned long m_nRealtimeFrameEndForTarget
void valueChangedProcessingTypeComboBox(const QString)
QTimer * m_pTargetDisplayTimer
bool m_bSampleEditorClean
void setSamplelengthFrames()
bool m_bSampleIsModified
true if sample is modified
void valueChangedrubberComboBox(const QString)
virtual void closeEvent(QCloseEvent *event) override
void on_PrevChangesPushButton_clicked()
void on_PlayPushButton_clicked()
H2Core::Sample::Rubberband __rubberband
void valueChangedrubberbandCsettingscomboBox(const QString)
virtual void mouseReleaseEvent(QMouseEvent *ev) override
TargetWaveDisplay * m_pTargetSampleView
void checkRatioSettings()
SampleEditor(QWidget *pParent, int nSelectedComponent, int nSelectedLayer, QString nSampleFilename)
void valueChangedEndFrameSpinBox(int)
void testPositionsSpinBoxes()
void on_verticalzoomSlider_valueChanged(int value)
void valueChangedStartFrameSpinBox(int)
void on_ClosePushButton_clicked()
void valueChangedpitchdoubleSpinBox(double)
void on_PlayOrigPushButton_clicked()
void valueChangedLoopCountSpinBox(int)
DetailWaveDisplay * m_pSampleAdjustView
unsigned long m_nRealtimeFrameEnd