@@ -693,27 +693,35 @@ static void *thread_callback(void *prjm) {
693693 return index;
694694 }
695695
696- void projectM::selectPreset ( unsigned int index, bool hardCut)
696+ void projectM::selectPreset ( unsigned int index, bool hardCut)
697697 {
698698
699699 if (m_presetChooser->empty ())
700700 return ;
701701
702- if (!hardCut) {
703- timeKeeper->StartSmoothing ();
704- }
705702
706703 *m_presetPos = m_presetChooser->begin (index);
704+ switchPreset (hardCut);
705+ }
707706
707+ void projectM::switchPreset (const bool hardCut) {
708+ std::string result;
708709 if (!hardCut) {
709- switchPreset (m_activePreset2);
710+ result = switchPreset (m_activePreset2);
710711 } else {
711- switchPreset (m_activePreset);
712- timeKeeper->StartPreset ();
712+ result = switchPreset (m_activePreset);
713+ if (result.empty ())
714+ timeKeeper->StartPreset ();
713715 }
714716
715- presetSwitchedEvent (hardCut, **m_presetPos);
717+ if (result.empty () && !hardCut) {
718+ timeKeeper->StartSmoothing ();
719+ }
716720
721+ if (result.empty ())
722+ presetSwitchedEvent (hardCut, **m_presetPos);
723+ else
724+ presetSwitchFailedEvent (hardCut, **m_presetPos, result);
717725}
718726
719727
@@ -722,20 +730,9 @@ void projectM::selectRandom(const bool hardCut) {
722730 if (m_presetChooser->empty ())
723731 return ;
724732
725- if (!hardCut) {
726- timeKeeper->StartSmoothing ();
727- }
728-
729733 *m_presetPos = m_presetChooser->weightedRandom (hardCut);
730734
731- if (!hardCut) {
732- switchPreset (m_activePreset2);
733- } else {
734- switchPreset (m_activePreset);
735- timeKeeper->StartPreset ();
736- }
737-
738- presetSwitchedEvent (hardCut, **m_presetPos);
735+ switchPreset (hardCut);
739736
740737}
741738
@@ -744,72 +741,51 @@ void projectM::selectPrevious(const bool hardCut) {
744741 if (m_presetChooser->empty ())
745742 return ;
746743
747- if (!hardCut) {
748- timeKeeper->StartSmoothing ();
749- }
750744
751745 m_presetChooser->previousPreset (*m_presetPos);
752746
753- if (!hardCut) {
754- switchPreset (m_activePreset2);
755- } else {
756- switchPreset (m_activePreset);
757- timeKeeper->StartPreset ();
758- }
759-
760- presetSwitchedEvent (hardCut, **m_presetPos);
761-
762- // m_activePreset = m_presetPos->allocate();
763- // renderer->SetPipeline(m_activePreset->pipeline());
764- // renderer->setPresetName(m_activePreset->name());
765-
766- // timeKeeper->StartPreset();
767-
747+ switchPreset (hardCut);
768748}
769749
770750void projectM::selectNext (const bool hardCut) {
771751
772752 if (m_presetChooser->empty ())
773753 return ;
774754
775- if (!hardCut) {
776- timeKeeper->StartSmoothing ();
777- std::cout << " start smoothing" << std::endl;
778- }
779-
780755 m_presetChooser->nextPreset (*m_presetPos);
781756
782- if (!hardCut) {
783- switchPreset (m_activePreset2);
784- } else {
785- switchPreset (m_activePreset);
786- timeKeeper->StartPreset ();
787- }
788- presetSwitchedEvent (hardCut, **m_presetPos);
789-
790-
757+ switchPreset (hardCut);
791758}
792759
793760/* *
794- *
795- * @param targetPreset
796- */
797- void projectM::switchPreset (std::auto_ptr<Preset> & targetPreset) {
761+ * Switches to the target preset.
762+ * @param targetPreset
763+ * @return a message indicating an error, empty otherwise.
764+ */
765+ std::string projectM::switchPreset (std::auto_ptr<Preset> & targetPreset) {
798766
799767 #ifdef SYNC_PRESET_SWITCHES
800768 pthread_mutex_lock (&preset_mutex);
801769 #endif
802-
770+ try {
803771 targetPreset = m_presetPos->allocate ();
804-
772+ } catch (const PresetFactoryException & e) {
773+ #ifdef SYNC_PRESET_SWITCHES
774+ pthread_mutex_unlock (&preset_mutex);
775+ #endif
776+ std::cerr << " problem allocating target preset: " << e.message () << std::endl;
777+ return e.message ();
778+ }
805779 // Set preset name here- event is not done because at the moment this function is oblivious to smooth/hard switches
806780 renderer->setPresetName (targetPreset->name ());
807781 renderer->SetPipeline (targetPreset->pipeline ());
808782
809783 #ifdef SYNC_PRESET_SWITCHES
810784 pthread_mutex_unlock (&preset_mutex);
811785 #endif
812- }
786+
787+ return std::string ();
788+ }
813789
814790 void projectM::setPresetLock ( bool isLocked )
815791 {
0 commit comments