InstrumentPlayHandle.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * InstrumentPlayHandle.h - play-handle for driving an instrument
  3. *
  4. * Copyright (c) 2005-2014 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 INSTRUMENT_PLAY_HANDLE_H
  25. #define INSTRUMENT_PLAY_HANDLE_H
  26. #include "PlayHandle.h"
  27. #include "Instrument.h"
  28. #include "NotePlayHandle.h"
  29. #include "lmms_export.h"
  30. class LMMS_EXPORT InstrumentPlayHandle : public PlayHandle
  31. {
  32. public:
  33. InstrumentPlayHandle( Instrument * instrument, InstrumentTrack* instrumentTrack );
  34. virtual ~InstrumentPlayHandle()
  35. {
  36. }
  37. void play( sampleFrame * _working_buffer ) override
  38. {
  39. // ensure that all our nph's have been processed first
  40. ConstNotePlayHandleList nphv = NotePlayHandle::nphsOfInstrumentTrack( m_instrument->instrumentTrack(), true );
  41. bool nphsLeft;
  42. do
  43. {
  44. nphsLeft = false;
  45. for( const NotePlayHandle * constNotePlayHandle : nphv )
  46. {
  47. NotePlayHandle * notePlayHandle = const_cast<NotePlayHandle *>( constNotePlayHandle );
  48. if( notePlayHandle->state() != ThreadableJob::ProcessingState::Done &&
  49. !notePlayHandle->isFinished())
  50. {
  51. nphsLeft = true;
  52. notePlayHandle->process();
  53. }
  54. }
  55. }
  56. while( nphsLeft );
  57. m_instrument->play( _working_buffer );
  58. }
  59. bool isFinished() const override
  60. {
  61. return false;
  62. }
  63. bool isFromTrack( const Track* _track ) const override
  64. {
  65. return m_instrument->isFromTrack( _track );
  66. }
  67. private:
  68. Instrument* m_instrument;
  69. } ;
  70. #endif