1 /*
2   ==============================================================================
3 
4    This file is part of the JUCE library.
5    Copyright (c) 2020 - Raw Material Software Limited
6 
7    JUCE is an open source library subject to commercial or open-source
8    licensing.
9 
10    The code included in this file is provided under the terms of the ISC license
11    http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12    To use, copy, modify, and/or distribute this software for any purpose with or
13    without fee is hereby granted provided that the above copyright notice and
14    this permission notice appear in all copies.
15 
16    JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17    EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18    DISCLAIMED.
19 
20   ==============================================================================
21 */
22 
23 namespace juce
24 {
25 
26 /**
27     @tags{Blocks}
28 */
29 struct DrumPadGridProgram  : public Block::Program
30 {
31     DrumPadGridProgram (Block&);
32 
33     //==============================================================================
34     /** These let the program dim pads which aren't having gestures performed on them. */
35 
36     void startTouch (float startX, float startY);
37     void endTouch   (float startX, float startY);
38 
39     /** Creates trail effects similar to the onscreen pad trails. */
40     void sendTouch (float x, float y, float z, LEDColour);
41 
42     //==============================================================================
43     /** Call this to match animations to the project tempo.
44 
45         @param padIdx           The pad to update. 16 animated pads are supported, so 0 - 15.
46         @param loopTimeSecs     The length of time for the pad's animation to loop in seconds. 0 will stop the animation.
47         @param currentProgress  The starting progress of the animation. 0.0 - 1.0.
48     */
49     void setPadAnimationState (uint32 padIdx, double loopTimeSecs, double currentProgress);
50 
51     /** If the app needs to close down or suspend, use these to pause & dim animations. */
52     void suspendAnimations();
53     void resumeAnimations();
54 
55     //==============================================================================
56     /** Set how each pad in the grid looks. */
57     struct GridFill
58     {
59         enum FillType : uint8
60         {
61             gradient            = 0,
62             filled              = 1,
63             hollow              = 2,
64             hollowPlus          = 3,
65 
66             // Animated pads
67             dotPulsing          = 4,
68             dotBlinking         = 5,
69             pizzaFilled         = 6,
70             pizzaHollow         = 7,
71         };
72 
73         LEDColour colour;
74         FillType fillType;
75     };
76 
77     void setGridFills (int numColumns, int numRows,
78                        const Array<GridFill>&);
79 
80     /** Set up a new pad layout, with a slide animation from the old to the new. */
81     enum SlideDirection : uint8
82     {
83         up     = 0,
84         down   = 1,
85         left   = 2,
86         right  = 3,
87 
88         none   = 255
89     };
90 
91     void triggerSlideTransition (int newNumColumns, int newNumRows,
92                                  const Array<GridFill>& newFills, SlideDirection);
93 
94 private:
95     //==============================================================================
96     /** Shared data heap is laid out as below. There is room for two sets of
97         pad layouts, colours and fill types to allow animation between two states. */
98 
99     static constexpr uint32 numColumns0_byte      = 0;    // 1 byte
100     static constexpr uint32 numRows0_byte         = 1;    // 1 byte (ignored for the moment: always square pads to save cycles)
101     static constexpr uint32 colours0_byte         = 2;    // 2 byte x 25  (5:6:5 bits for rgb)
102     static constexpr uint32 fillTypes0_byte       = 52;   // 1 byte x 25
103 
104     static constexpr uint32 numColumns1_byte      = 78;   // 1 byte
105     static constexpr uint32 numRows1_byte         = 79;   // 1 byte
106     static constexpr uint32 colours1_byte         = 80;   // 2 byte x 25  (5:6:5 bits for rgb)
107     static constexpr uint32 fillTypes1_byte       = 130;  // 1 byte x 25
108 
109     static constexpr uint32 visiblePads_byte      = 155;  // 1 byte       (i.e. which set of colours/fills to use, 0 or 1)
110     static constexpr uint32 slideDirection_byte   = 156;  // 1 byte
111     static constexpr uint32 touchedPads_byte      = 158;  // 1 byte x 4   (Zero means empty slot, so stores padIdx + 1)
112     static constexpr uint32 animationTimers_byte  = 162;  // 4 byte x 16  (16:16 bits counter:increment)
113     static constexpr uint32 totalHeapSize         = 226;
114 
115     static constexpr uint32 maxNumPads        = 25;
116     static constexpr uint32 colourSizeBytes   = 2;
117 
118     int getPadIndex (float posX, float posY) const;
119     void setGridFills (int numColumns, int numRows, const Array<GridFill>& fills, uint32 byteOffset);
120 
121     String getLittleFootProgram() override;
122     String getLittleFootProgramPre25() const;
123     String getLittleFootProgramPost25() const;
124 };
125 
126 } // namespace juce
127