Skip to content

Commit 14bf564

Browse files
committed
ListView experiment and other bits.
1 parent 4ec6575 commit 14bf564

9 files changed

Lines changed: 466 additions & 11 deletions

File tree

demo/SquarePineDemo.jucer

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
file="source/demos/EffectChainDemo.h"/>
9797
<FILE id="brHreQ" name="iCUESDKDemo.h" compile="0" resource="0" file="source/demos/iCUESDKDemo.h"/>
9898
<FILE id="vSHEQC" name="ImageDemo.h" compile="0" resource="0" file="source/demos/ImageDemo.h"/>
99+
<FILE id="Hzxday" name="ListViewDemo.h" compile="0" resource="0" file="source/demos/ListViewDemo.h"/>
99100
<FILE id="uzQ1sq" name="MarkdownDemo.h" compile="0" resource="0" file="source/demos/MarkdownDemo.h"/>
100101
<FILE id="S1SGkR" name="MediaDeviceListerDemo.h" compile="0" resource="0"
101102
file="source/demos/MediaDeviceListerDemo.h"/>

demo/source/MainModule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "demos/EasingsDemo.h"
2828
#include "demos/EffectChainDemo.h"
2929
#include "demos/ImageDemo.h"
30+
#include "demos/ListViewDemo.h"
3031
#include "demos/MarkdownDemo.h"
3132
#include "demos/MediaDeviceListerDemo.h"
3233
#include "demos/OpenGLDetailsDemo.h"

demo/source/demos/ListViewDemo.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/** A general demonstration of a highly flexible list view system. */
2+
class ListViewDemo final : public DemoBase
3+
{
4+
public:
5+
ListViewDemo (SharedObjects& sharedObjs) :
6+
DemoBase (sharedObjs, NEEDS_TRANS ("ListView"))
7+
{
8+
scrollView = makeListView();
9+
scrollView->setModel (&demoListModel);
10+
addAndMakeVisible (scrollView.get());
11+
12+
updateWithNewTranslations();
13+
}
14+
15+
~ListViewDemo() override
16+
{
17+
scrollView->setModel (nullptr);
18+
}
19+
20+
//==============================================================================
21+
void updateWithNewTranslations() override
22+
{
23+
SQUAREPINE_CRASH_TRACER
24+
repaint();
25+
}
26+
27+
void resized() override
28+
{
29+
auto b = getLocalBounds().reduced (margin);
30+
31+
{
32+
auto top = b.removeFromTop (margin * 4);
33+
}
34+
35+
b.removeFromTop (margin);
36+
scrollView->setBounds (b);
37+
}
38+
39+
private:
40+
//===============================4===============================================
41+
enum { margin = 8 };
42+
43+
class DemoListModel final : public ListModel
44+
{
45+
public:
46+
DemoListModel() = default;
47+
48+
int getNumItems() const override { return 1000; }
49+
50+
Component* getItemComponent (int index) override
51+
{
52+
auto* label = new Label();
53+
label->setColour (Label::ColourIds::backgroundColourId, Colours::red);
54+
label->setText ("Item " + String(index), dontSendNotification);
55+
return label;
56+
}
57+
};
58+
59+
DemoListModel demoListModel;
60+
std::unique_ptr<ScrollView> scrollView;
61+
62+
//==============================================================================
63+
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ListViewDemo)
64+
};

demo/source/main/MainComponent.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ MainComponent::MainComponent (SharedObjects& sharedObjs) :
2525
demos.add (comp);
2626
};
2727

28+
addDemo (new ListViewDemo (sharedObjs));
2829
addDemo (new EffectChainDemo (sharedObjs));
29-
addDemo (new MarkdownDemo (sharedObjs));
30+
// addDemo (new MarkdownDemo (sharedObjs));
3031
addDemo (new CRCDemo (sharedObjs));
3132
addDemo (new EaseListComponent (sharedObjs));
3233
addDemo (new ImageDemo (sharedObjs));

modules/squarepine_audio/core/squarepine_AudioUtilities.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,16 +329,12 @@ template<typename Type>
329329
[[nodiscard]] inline double pitchRatioToSemitones (Type pitchRatio) noexcept { return pitchRatioToSemitones (static_cast<double> (pitchRatio)); }
330330

331331
//============================================================================
332-
/** @returns a MIDI note converted from a frequency (in Hz). */
332+
/** @returns a MIDI note converted from a frequency (in Hz).
333+
334+
@see juce::MidiMessage::getMidiNoteInHertz for the other way around.
335+
*/
333336
[[nodiscard]] inline int frequencyToMIDINote (double frequencyHz) noexcept
334337
{
335338
const auto pitchRatio = std::max (0.0, frequencyHz / 440.0);
336339
return roundToInt (69.0 + pitchRatioToSemitones (pitchRatio));
337340
}
338-
339-
/** @returns a frequency (in Hz) converted from a MIDI note. */
340-
[[nodiscard]] inline double midiNoteToFrequency (int midiNoteNumber) noexcept
341-
{
342-
const auto semitones = std::max (0, midiNoteNumber);
343-
return 440.0 * semitonesToPitchRatio (static_cast<double> (semitones) - 69.0);
344-
}

modules/squarepine_audio/music/squarepine_Pitch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Pitch final
2828

2929
//==============================================================================
3030
/** Creates a pitch from a given MIDI note number e.g. 69. */
31-
static Pitch fromMIDINote (int midiNote) noexcept { return midiNoteToFrequency (midiNote); }
31+
static Pitch fromMIDINote (int midiNote) noexcept { return MidiMessage::getMidiNoteInHertz (midiNote); }
3232

3333
/** Creates a pitch from a given note name e.g. A#3.
3434

modules/squarepine_cryptography/rng/squarepine_Xorshift.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class Xorshift64 final
7373

7474
//==============================================================================
7575
/** */
76-
void setAlgorithm (Algorithm newAlgorithmToChoose);
76+
void setAlgorithm (Algorithm);
7777
/** */
7878
[[nodiscard]] Algorithm getAlgorithm() const noexcept { return algorithm; }
7979

0 commit comments

Comments
 (0)