InlineAutomation.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * InlineAutomation.h - class for automating something "inline"
  3. *
  4. * Copyright (c) 2008-2010 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef INLINE_AUTOMATION_H
  25. #define INLINE_AUTOMATION_H
  26. #include "AutomationPattern.h"
  27. #include "shared_object.h"
  28. class InlineAutomation : public FloatModel, public sharedObject
  29. {
  30. public:
  31. InlineAutomation() :
  32. FloatModel(),
  33. sharedObject(),
  34. m_autoPattern( NULL )
  35. {
  36. }
  37. virtual ~InlineAutomation()
  38. {
  39. if( m_autoPattern )
  40. {
  41. delete m_autoPattern;
  42. }
  43. }
  44. virtual float defaultValue() const = 0;
  45. bool hasAutomation() const
  46. {
  47. if( m_autoPattern != NULL && m_autoPattern->getTimeMap().isEmpty() == false )
  48. {
  49. // prevent saving inline automation if there's just one value which equals value
  50. // of model which is going to be saved anyways
  51. if( isAtInitValue() &&
  52. m_autoPattern->getTimeMap().size() == 1 &&
  53. m_autoPattern->getTimeMap().keys().first() == 0 &&
  54. m_autoPattern->getTimeMap().values().first() == value() )
  55. {
  56. return false;
  57. }
  58. return true;
  59. }
  60. return false;
  61. }
  62. AutomationPattern * automationPattern()
  63. {
  64. if( m_autoPattern == NULL )
  65. {
  66. m_autoPattern = new AutomationPattern( NULL );
  67. m_autoPattern->addObject( this );
  68. }
  69. return m_autoPattern;
  70. }
  71. void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
  72. void loadSettings( const QDomElement & _this ) override;
  73. private:
  74. AutomationPattern * m_autoPattern;
  75. } ;
  76. #endif