InlineAutomation.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 "AutomationNode.h"
  27. #include "AutomationClip.h"
  28. #include "shared_object.h"
  29. class InlineAutomation : public FloatModel, public sharedObject
  30. {
  31. public:
  32. InlineAutomation() :
  33. FloatModel(),
  34. sharedObject(),
  35. m_autoClip( nullptr )
  36. {
  37. }
  38. virtual ~InlineAutomation()
  39. {
  40. if( m_autoClip )
  41. {
  42. delete m_autoClip;
  43. }
  44. }
  45. virtual float defaultValue() const = 0;
  46. bool hasAutomation() const
  47. {
  48. if( m_autoClip != nullptr && m_autoClip->getTimeMap().isEmpty() == false )
  49. {
  50. // Prevent saving inline automation if there's just one node at the beginning of
  51. // the clip, which has a InValue equal to the value of model (which is going
  52. // to be saved anyways) and no offset between the InValue and OutValue
  53. AutomationClip::timeMap::const_iterator firstNode =
  54. m_autoClip->getTimeMap().begin();
  55. if (isAtInitValue()
  56. && m_autoClip->getTimeMap().size() == 1
  57. && POS(firstNode) == 0
  58. && INVAL(firstNode) == value()
  59. && OFFSET(firstNode) == 0)
  60. {
  61. return false;
  62. }
  63. return true;
  64. }
  65. return false;
  66. }
  67. AutomationClip * automationClip()
  68. {
  69. if( m_autoClip == nullptr )
  70. {
  71. m_autoClip = new AutomationClip( nullptr );
  72. m_autoClip->addObject( this );
  73. }
  74. return m_autoClip;
  75. }
  76. void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
  77. void loadSettings( const QDomElement & _this ) override;
  78. private:
  79. AutomationClip * m_autoClip;
  80. } ;
  81. #endif