65 , __sound_library_tree( nullptr )
66 , __drumkit_menu( nullptr )
67 , __song_menu( nullptr )
68 , __pattern_menu( nullptr )
69 , __pattern_menu_list( nullptr )
70 , m_pTreeSystemDrumkitsItem( nullptr )
71 , m_pTreeUserDrumkitsItem( nullptr )
72 , m_pTreeSessionDrumkitsItem( nullptr )
73 , __song_item( nullptr )
74 , __pattern_item( nullptr )
75 , __pattern_item_list( nullptr )
76 , m_bInItsOwnDialog( bInItsOwnDialog )
117 QVBoxLayout *pVBox =
new QVBoxLayout();
118 pVBox->setSpacing( 0 );
119 pVBox->setMargin( 0 );
124 this->setLayout( pVBox );
141 pH2App->removeEventListener(
this );
151 auto pSoundLibraryDatabase = pHydrogen->getSoundLibraryDatabase();
156 QFont boldFont( pPref->getApplicationFontFamily(),
getPointSize( pPref->getFontSize() ) );
157 boldFont.setBold(
true );
159 QFont childFont( pPref->getLevel2FontFamily(),
getPointSize( pPref->getFontSize() ) );
160 setFont( childFont );
167 QList<QTreeWidgetItem*> drumkitItems;
172 for (
const auto& pDrumkitEntry : pSoundLibraryDatabase->getDrumkitDatabase() ) {
173 auto pDrumkit = pDrumkitEntry.second;
174 if ( pDrumkit !=
nullptr ) {
175 QString sItemLabel = pDrumkit->get_name();
179 QTreeWidgetItem* pDrumkitItem;
180 if ( drumkitType == Filesystem::DrumkitType::System ) {
188 sItemLabel.append( QString(
" (%1)" )
189 .arg( pCommonStrings->getSoundLibrarySystemSuffix() ) );
191 else if ( drumkitType == Filesystem::DrumkitType::User ) {
206 sItemLabel.append( QString(
" (%1)" )
207 .arg( pCommonStrings->getSoundLibrarySessionSuffix() ) );
214 sItemLabel = QString(
"%1 (%2)" )
215 .arg( pDrumkit->get_name() ).arg( nCount );
222 pDrumkitItem->setText( 0, sItemLabel );
223 pDrumkitItem->setToolTip( 0, pDrumkitEntry.first );
225 auto pInstrList = pDrumkit->get_instruments();
226 for (
const auto& pInstrument : *pDrumkit->get_instruments() ) {
227 if ( pInstrument !=
nullptr ) {
228 QTreeWidgetItem* pInstrumentItem =
new QTreeWidgetItem( pDrumkitItem );
229 pInstrumentItem->setText( 0, QString(
"[%1] %2" )
230 .arg( pInstrument->get_id() )
231 .arg( pInstrument->get_name() ) );
232 pInstrumentItem->setToolTip( 0, pInstrument->get_name() );
267 if ( songs.size() > 0 ) {
270 __song_item->setToolTip( 0, tr(
"Double click to expand the list") );
273 for (uint i = 0; i < songs.size(); i++) {
274 QTreeWidgetItem* pSongItem =
new QTreeWidgetItem(
__song_item );
275 QString song = songs[i];
276 pSongItem->setText( 0 , song.left( song.indexOf(
".")) );
277 pSongItem->setToolTip( 0, song );
284 if ( patternDirList.size() > 0 ) {
288 __pattern_item->setToolTip( 0, tr(
"Double click to expand the list") );
292 auto patternInfoVector = pSoundLibraryDatabase->getPatternInfoVector();
293 QStringList patternCategories =
294 pSoundLibraryDatabase->getPatternCategories();
301 QString sPatternTooltip = tr(
"Created for drumkit" );
302 for (
const auto& categoryName : patternCategories ) {
304 QTreeWidgetItem* pCategoryItem =
new QTreeWidgetItem(
__pattern_item );
305 pCategoryItem->setText( 0, categoryName );
307 for (
const auto& pInfo : patternInfoVector ) {
308 QString patternCategory = pInfo->getCategory();
309 if ( ( patternCategory == categoryName ) ||
310 ( patternCategory.isEmpty() && categoryName ==
"No category" ) ){
311 QTreeWidgetItem* pPatternItem =
new QTreeWidgetItem( pCategoryItem );
312 pPatternItem->setText( 0, pInfo->getName());
313 pPatternItem->setText( 1, pInfo->getPath() );
314 pPatternItem->setToolTip( 0, QString(
"%1 [%2]" )
315 .arg( sPatternTooltip )
316 .arg( pInfo->getDrumkitName() ) );
332 if( current ==
nullptr ){
381 QString sSelectedName = item->text(0);
383 QString sInstrName = sSelectedName.remove( 0, sSelectedName.indexOf(
"] " ) + 2 );
384 QString sDrumkitName = item->parent()->text(0);
386 INFOLOG( QString(
"Loading instrument [%1] from drumkit [%2] located in [%3]" )
387 .arg( sInstrName ).arg( sDrumkitName ).arg( sDrumkitPath ) );
391 if ( pInstrument ==
nullptr ) {
392 ERRORLOG(
"Unable to load instrument. Abort" );
396 pInstrument->set_muted(
false );
447 if ( drumkitType == Filesystem::DrumkitType::SessionReadOnly ) {
467 if (! ( event->buttons() & Qt::LeftButton ) ) {
471 if ( ( event->pos() -
__start_drag_position ).manhattanLength() < QApplication::startDragDistance() ) {
516 QString dragtype =
"drag pattern";
517 QString sText = dragtype +
"::" + sPatternPath;
519 QDrag *pDrag =
new QDrag(
this);
520 QMimeData *pMimeData =
new QMimeData;
522 pMimeData->setText( sText );
523 pDrag->setMimeData( pMimeData);
524 pDrag->exec( Qt::CopyAction | Qt::MoveAction );
533 const QString sText =
"importInstrument:" + sDrumkitPath +
"::" + sInstrumentName;
535 QDrag *pDrag =
new QDrag(
this);
536 QMimeData *pMimeData =
new QMimeData;
538 pMimeData->setText( sText );
539 pDrag->setMimeData( pMimeData);
541 pDrag->exec( Qt::CopyAction | Qt::MoveAction );
554 pHydrogen->getSoundLibraryDatabase()->getDrumkit( sDrumkitPath );
556 if ( pDrumkit ==
nullptr ) {
557 ERRORLOG( QString(
"Unable to find drumkit [%1] (mapped to path [%2]" )
558 .arg( sDrumkitName ).arg( sDrumkitPath ) );
562 auto pSongInstrList = pHydrogen->getSong()->getInstrumentList();
563 auto pDrumkitInstrList = pDrumkit->get_instruments();
565 int oldCount = pSongInstrList->size();
566 int newCount = pDrumkitInstrList->size();
568 bool conditionalLoad =
false;
569 bool hasNotes =
false;
571 INFOLOG(
"Old kit has " + QString::number( oldCount ) +
" instruments, new one has " + QString::number( newCount ) );
573 if ( newCount < oldCount )
576 for (
int i = 0; i < pSongInstrList->size(); i++)
580 INFOLOG(
"Checking if Instrument " + QString::number( i ) +
" has notes..." );
582 if ( pHydrogen->instrumentHasNotes( pSongInstrList->get( i ) ) )
585 INFOLOG(
"Instrument " + QString::number( i ) +
" has notes" );
594 msgBox.setWindowTitle(
"Hydrogen");
595 msgBox.setIcon( QMessageBox::Warning );
596 msgBox.setText( tr(
"The existing kit has %1 instruments but the new one only has %2.\nThe first %2 instruments will be replaced with the new instruments and will keep their notes, but some of the remaining instruments have notes.\nWould you like to keep or discard the remaining instruments and notes?\n").arg( QString::number( oldCount ),QString::number( newCount ) ) );
598 msgBox.setStandardButtons( QMessageBox::Save | QMessageBox::Discard |
599 QMessageBox::Cancel );
600 msgBox.setButtonText(QMessageBox::Save, tr(
"Keep"));
601 msgBox.setButtonText(QMessageBox::Discard,
602 pCommonStrings->getButtonDiscard() );
603 msgBox.setButtonText(QMessageBox::Cancel,
604 pCommonStrings->getButtonCancel());
605 msgBox.setDefaultButton(QMessageBox::Cancel);
607 switch ( msgBox.exec() )
609 case QMessageBox::Save:
611 conditionalLoad =
true;
614 case QMessageBox::Discard:
616 conditionalLoad =
false;
619 case QMessageBox::Cancel:
628 QApplication::setOverrideCursor(Qt::WaitCursor);
630 pHydrogen->getCoreActionController()->setDrumkit( pDrumkit, conditionalLoad );
632 QApplication::restoreOverrideCursor();
675 if ( entry.second == sDrumkitPath ) {
689 if ( pSelectedInstrument ==
nullptr ) {
690 DEBUGLOG(
"No instrument selected" );
693 QString sDrumkitPath = pSelectedInstrument->get_drumkit_path();
696 if ( sDrumkitLabel.isEmpty() ) {
697 ERRORLOG( QString(
"Unable to find label corresponding to drumkit [%1]. No highlighting applied" )
698 .arg( sDrumkitPath ) );
735 const QString sDrumkitName = pItem->text(0);
743 drumkitType == Filesystem::DrumkitType::SessionReadOnly ) ) {
744 QMessageBox::warning(
this,
"Hydrogen", QString(
"\"%1\" " )
746 .append( tr(
"is a read-only drumkit and can't be deleted.") ) );
752 QMessageBox::warning(
this,
"Hydrogen", tr(
"It is not possible to delete the currently loaded drumkit: \n \"%1\".\nTo delete this drumkit first load another drumkit.").arg(sDrumkitName) );
756 int res = QMessageBox::warning(
this,
"Hydrogen",
757 tr(
"Warning, the \"%1\" drumkit will be deleted from disk.\nAre you sure?").arg(sDrumkitName),
758 pCommonStrings->getButtonOk(),
759 pCommonStrings->getButtonCancel(),
765 QApplication::setOverrideCursor(Qt::WaitCursor);
767 QApplication::restoreOverrideCursor();
769 QMessageBox::warning(
this,
"Hydrogen", tr(
"Drumkit deletion failed.") );
777 auto pSoundLibraryDatabase =
782 auto pDrumkit = pSoundLibraryDatabase->getDrumkit( sDrumkitPath );
793 auto pSoundLibraryDatabase = pHydrogen->getSoundLibraryDatabase();
797 auto pDrumkit = pSoundLibraryDatabase->getDrumkit( sDrumkitPath );
799 if ( pDrumkit ==
nullptr ) {
800 ERRORLOG( QString(
"Unable to find drumkit [%1] (mapped to path [%2]" )
801 .arg( sDrumkitName ).arg( sDrumkitPath ) );
808 auto pNewDrumkit = std::make_shared<Drumkit>( pDrumkit );
837 int res = QMessageBox::information(
this,
"Hydrogen",
838 tr(
"Warning, the selected pattern will be deleted from disk.\nAre you sure?"),
839 pCommonStrings->getButtonOk(),
840 pCommonStrings->getButtonCancel(),
846 QFile rmfile( patternPath );
847 bool err = rmfile.remove();
848 if ( err ==
false ) {
849 ERRORLOG(
"Error removing the pattern" );
883 QFont font( pPref->getLevel2FontFamily(),
getPointSize( pPref->getFontSize() ) );
884 QFont boldFont( pPref->getApplicationFontFamily(),
getPointSize( pPref->getFontSize() ) );
885 boldFont.setBold(
true );
888 QTreeWidgetItem* childNode;
893 childNode->setFont( 0, font );
894 for ( jj = 0; jj < childNode->childCount(); jj++ ) {
895 childNode->child( jj )->setFont( 0, font );
904 childNode->setFont( 0, font );
905 for ( jj = 0; jj < childNode->childCount(); jj++ ) {
906 childNode->child( jj )->setFont( 0, font );
915 childNode->setFont( 0, font );
916 for ( jj = 0; jj < childNode->childCount(); jj++ ) {
917 childNode->child( jj )->setFont( 0, font );
924 for ( ii = 0; ii <
__song_item->childCount(); ii++ ){
934 childNode->setFont( 0, font );
935 for ( jj = 0; jj < childNode->childCount(); jj++ ) {
936 childNode->child( jj )->setFont( 0, font );
Sampler * getSampler() const
bool openPattern(const QString &sPath, int nPatternNumber=-1)
Opens a pattern from disk and adds it to the pattern list.
static bool remove(const QString &sDrumkitDir)
remove a drumkit from the disk
static QString song_path(const QString &sg_name)
returns user song path, add file extension
static DrumkitType determineDrumkitType(const QString &sPath)
static QStringList song_list_cleared()
returns a list of existing songs, excluding the autosaved one
static QStringList pattern_drumkits()
returns a list of existing drumkit sub dir into the patterns directory
static QString pattern_path(const QString &dk_name, const QString &p_name)
returns user patterns path, add file extension
static Hydrogen * get_instance()
Returns the current Hydrogen instance __instance.
AudioEngine * getAudioEngine() const
std::shared_ptr< Instrument > getSelectedInstrument() const
SoundLibraryDatabase * getSoundLibraryDatabase() const
QString getLastLoadedDrumkitName() const
CoreActionController * getCoreActionController() const
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
static Preferences * get_instance()
Returns a pointer to the current Preferences singleton stored in __instance.
Changes
Bitwise or-able options showing which part of the Preferences were altered using the PreferencesDialo...
@ Font
Either the font size or font family have changed.
void preview_instrument(std::shared_ptr< Instrument > pInstr)
void updatePatterns(bool bTriggerEvent=true)
void addEventListener(EventListener *pListener)
static HydrogenApp * get_instance()
Returns the instance of HydrogenApp class.
std::shared_ptr< CommonStrings > getCommonStrings()
static bool openSong(QString sFilename)
void preferencesChanged(H2Core::Preferences::Changes changes)
Propagates a change in the Preferences through the GUI.
std::map< QString, QString > m_drumkitRegister
Used to uniquely identify the drumkit corresponding to an item in the tree.
QString getDrumkitLabel(const QString &sDrumkitPath) const
QTreeWidgetItem * m_pTreeSessionDrumkitsItem
void on_DrumkitList_ItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
void update_background_color()
QMenu * __pattern_menu_list
QMenu * __drumkit_menu_system
SoundLibraryPanel(QWidget *parent, bool bInItsOwnDialog)
void on_DrumkitList_leftClicked(QPoint pos)
QTreeWidgetItem * __pattern_item
void on_drumkitLoadAction()
void restore_background_color()
void on_drumkitDeleteAction()
void on_drumkitPropertiesAction()
void onPreferencesChanged(H2Core::Preferences::Changes changes)
void change_background_color()
virtual void updateSongEvent(int nValue) override
virtual void soundLibraryChangedEvent() override
virtual void drumkitLoadedEvent() override
QPoint __start_drag_position
QTreeWidgetItem * __pattern_item_list
bool m_bInItsOwnDialog
Whether the dialog was constructed via a click in the MainForm or as part of the GUI.
QStringList m_drumkitLabels
List of all labels used for drumkits in the tree.
void item_changed(bool bDrumkitSelected)
QString getDrumkitPath(const QString &sDrumkitLabel) const
SoundLibraryTree * __sound_library_tree
virtual void selectedInstrumentChangedEvent() override
void test_expandedItems()
QTreeWidgetItem * m_pTreeSystemDrumkitsItem
void on_patternLoadAction()
bool __expand_pattern_list
QTreeWidgetItem * __song_item
void on_patternDeleteAction()
void on_DrumkitList_mouseMove(QMouseEvent *event)
void on_DrumkitList_itemActivated(QTreeWidgetItem *item, int column)
QTreeWidgetItem * m_pTreeUserDrumkitsItem
void on_DrumkitList_rightClicked(QPoint pos)
void on_drumkitExportAction()