Lv2UridMap.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Lv2UridMap.cpp - Lv2UridMap class
  3. *
  4. * Copyright (c) 2019 Johannes Lorenz <j.git$$$lorenz-ho.me, $$$=@>
  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 LV2URIDMAP_H
  25. #define LV2URIDMAP_H
  26. #include "lmmsconfig.h"
  27. #ifdef LMMS_HAVE_LV2
  28. #include <lv2/lv2plug.in/ns/ext/urid/urid.h>
  29. #include <mutex> // TODO: use semaphore, even though this is not realtime critical
  30. #include <string>
  31. #include <unordered_map>
  32. #include <vector>
  33. /**
  34. * Complete implementation of the Lv2 Urid Map extension
  35. */
  36. class UridMap
  37. {
  38. std::unordered_map<std::string, LV2_URID> m_map;
  39. std::vector<const char*> m_unMap;
  40. //! mutex for both m_map and m_unMap
  41. //! the URID map is global, which is why a mutex is required here
  42. std::mutex m_MapMutex;
  43. LV2_URID_Map m_mapFeature;
  44. LV2_URID_Unmap m_unmapFeature;
  45. LV2_URID m_lastUrid = 0;
  46. public:
  47. //! constructor; will set up the features
  48. UridMap();
  49. //! map feature function
  50. LV2_URID map(const char* uri);
  51. //! unmap feature function
  52. const char* unmap(LV2_URID urid);
  53. // access the features
  54. LV2_URID_Map* mapFeature() { return &m_mapFeature; }
  55. LV2_URID_Unmap* unmapFeature() { return &m_unmapFeature; }
  56. };
  57. #endif // LMMS_HAVE_LV2
  58. #endif // LV2URIDMAP_H