The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
6.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the juce_core module of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. or without fee is hereby granted, provided that the above copyright notice and this
  7. permission notice appear in all copies.
  8. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  9. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  10. NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  11. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  12. IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. ------------------------------------------------------------------------------
  15. NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
  16. All other JUCE modules are covered by a dual GPL/commercial license, so if you are
  17. using any other modules, be sure to check that you also comply with their license.
  18. For more details, visit www.juce.com
  19. ==============================================================================
  20. */
  21. #ifndef OSCLOGLISTBOX_H_INCLUDED
  22. #define OSCLOGLISTBOX_H_INCLUDED
  23. #include "../JuceLibraryCode/JuceHeader.h"
  24. //==============================================================================
  25. class OSCLogListBox : public ListBox, private ListBoxModel, private AsyncUpdater
  26. {
  27. public:
  28. //==============================================================================
  29. OSCLogListBox()
  30. {
  31. setModel (this);
  32. }
  33. //==============================================================================
  34. ~OSCLogListBox()
  35. {
  36. }
  37. //==============================================================================
  38. int getNumRows() override
  39. {
  40. return oscLogList.size();
  41. }
  42. //==============================================================================
  43. void paintListBoxItem (int row, Graphics& g, int width, int height, bool rowIsSelected) override
  44. {
  45. ignoreUnused (rowIsSelected);
  46. if (isPositiveAndBelow (row, oscLogList.size()))
  47. {
  48. g.setColour (Colours::black);
  49. g.drawText (oscLogList[row],
  50. Rectangle<int> (width, height).reduced (4, 0),
  51. Justification::centredLeft, true);
  52. }
  53. }
  54. //==============================================================================
  55. void addOSCMessage (const OSCMessage& message, int level = 0)
  56. {
  57. oscLogList.add (getIndentationString (level)
  58. + "- osc message, address = '"
  59. + message.getAddressPattern().toString()
  60. + "', "
  61. + String (message.size())
  62. + " argument(s)");
  63. if (! message.isEmpty())
  64. {
  65. for (OSCArgument* arg = message.begin(); arg != message.end(); ++arg)
  66. addOSCMessageArgument (*arg, level + 1);
  67. }
  68. triggerAsyncUpdate();
  69. }
  70. //==============================================================================
  71. void addOSCBundle (const OSCBundle& bundle, int level = 0)
  72. {
  73. OSCTimeTag timeTag = bundle.getTimeTag();
  74. oscLogList.add (getIndentationString (level)
  75. + "- osc bundle, time tag = "
  76. + timeTag.toTime().toString (true, true, true, true));
  77. for (OSCBundle::Element* element = bundle.begin(); element != bundle.end(); ++element)
  78. {
  79. if (element->isMessage())
  80. addOSCMessage (element->getMessage(), level + 1);
  81. else if (element->isBundle())
  82. addOSCBundle (element->getBundle(), level + 1);
  83. }
  84. triggerAsyncUpdate();
  85. }
  86. //==============================================================================
  87. void addOSCMessageArgument (const OSCArgument& arg, int level)
  88. {
  89. String typeAsString;
  90. String valueAsString;
  91. if (arg.isFloat32())
  92. {
  93. typeAsString = "float32";
  94. valueAsString = String (arg.getFloat32());
  95. }
  96. else if (arg.isInt32())
  97. {
  98. typeAsString = "int32";
  99. valueAsString = String (arg.getInt32());
  100. }
  101. else if (arg.isString())
  102. {
  103. typeAsString = "string";
  104. valueAsString = arg.getString();
  105. }
  106. else if (arg.isBlob())
  107. {
  108. typeAsString = "blob";
  109. const MemoryBlock& blob = arg.getBlob();
  110. valueAsString = String::fromUTF8( (const char*)blob.getData(), blob.getSize());
  111. }
  112. else
  113. {
  114. typeAsString = "(unknown)";
  115. valueAsString = "";
  116. }
  117. oscLogList.add (getIndentationString (level + 1) + "- " + typeAsString.paddedRight(' ', 12) + valueAsString);
  118. }
  119. //==============================================================================
  120. void addInvalidOSCPacket (const char* /* data */, int dataSize)
  121. {
  122. oscLogList.add ("- (" + String(dataSize) + "bytes with invalid format)");
  123. }
  124. //==============================================================================
  125. void clear()
  126. {
  127. oscLogList.clear();
  128. triggerAsyncUpdate();
  129. }
  130. //==============================================================================
  131. void handleAsyncUpdate() override
  132. {
  133. updateContent();
  134. scrollToEnsureRowIsOnscreen (oscLogList.size() - 1);
  135. repaint();
  136. }
  137. private:
  138. //==============================================================================
  139. String getIndentationString (int level)
  140. {
  141. return String().paddedRight (' ', 2 * level);
  142. }
  143. //==============================================================================
  144. StringArray oscLogList;
  145. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OSCLogListBox)
  146. };
  147. #endif // OSCLOGLISTBOX_H_INCLUDED