Class Grid
Grid
is a class that structures a continously increasing beat count into a temporal grid by
generating repeating events.
the class can, for example, be used to create an event every quarter note. this behavior is usually achieved via the
beat(int)
method:
public void beat(int beat) {
if (mNoteEvents.event(beat, QUARTER_NOTE)) {
// do something every quarter note
}
}
the class uses the concept of *Pulses per Quarter Note* (PPQN) ( as used e.g in MIDI clock @see Pulses per Quarter Note @ Wikipedia ). PPQN is the number of pulses that make up a quarter note. the default value is 24 which results into a quarter note being occuring every 24 pulese ( or beats ).
the schematic drawing below shows events counted quarter, half, whole, etcetera notes:
WHOLE : |0-----------------------|------------------------|------------------------|------------------------
HALF : |0-----------------------|------------------------|1-----------------------|------------------------
QUARTER : |0-----------------------|1-----------------------|2-----------------------|3-----------------------
EIGHTH : |0-----------1-----------|2-----------3-----------|4-----------5-----------|6-----------7-----------
SIXTEENTH : |0-----1-----2-----3-----|4-----5-----6-----7-----|8-----9-----0-----1-----|2-----3-----4-----5-----
THIRTYSEC : |0--1--2--3--4--5--6--7--|8--9--0--1--2--3--4--5--|6--7--8--9--0--1--2--3--|4--5--6--7--8--9--0--1--
( PPQN 24 )
note, that the |
is generated every quarter note to make the events more visible.
the schematic drawing below shows events generated based on pulses ( or beats ). the approach is somewhat more raw and ignores the concept of PPQN. it however is usefull when more fine grained grids are required ( e.g when implementing quarter triplets in this case with a phase of 8 ). it can also apply an offset to the beat count.
PHASE 3 : |0--1--2--3--4--5--6--7--|8--9--0--1--2--3--4--5--|6--7--8--9--0--1--2--3--|4--5--6--7--8--9--0--1--
PHASE 5 : |0----1----2----3----4---|-5----6----7----8----9--|--0----1----2----3----4-|---5----6----7----8----9
PHASE 7 : |0------1------2------3--|----4------5------6-----|-7------8------9------0-|-----1------2------3----
PHASE 8 : |0-------1-------2-------|3-------4-------5-------|6-------7-------8-------|9-------0-------1-------
PHASE 24>1: |-0----------------------|-1----------------------|-2----------------------|-3----------------------
( PPQN 24 )
See also Loop
and Pattern
for related classes implementing a related concept.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
event
(int beat, float note) int
event_count
(int beat, float note) boolean
event_phase
(int beat, int phase, int offset) int
event_phase_count
(int beat, int phase, int offset) int
get_PPQN()
boolean
is_eighth
(int beat) boolean
is_half
(int beat) boolean
is_quarter
(int beat) boolean
is_sixteenth
(int beat) boolean
is_whole
(int beat) static void
void
set_PPQN
(int PPQN) set the *pulses per quarter note* (PPQN) value.
-
Constructor Details
-
Grid
public Grid(int PPQN) -
Grid
public Grid()
-
-
Method Details
-
get_PPQN
public int get_PPQN()- Returns:
- the number of beats per quarter note.
-
set_PPQN
public void set_PPQN(int PPQN) set the *pulses per quarter note* (PPQN) value. the default value is 24 which means that a *quarter note event* occurs every 24 beats e.g at 24, 48, 72, ...- Parameters:
PPQN
- *pulses per quarter note* (PPQN) value
-
event_phase
public boolean event_phase(int beat, int phase, int offset) -
event
public boolean event(int beat, float note) -
is_whole
public boolean is_whole(int beat) -
is_half
public boolean is_half(int beat) -
is_quarter
public boolean is_quarter(int beat) -
is_eighth
public boolean is_eighth(int beat) -
is_sixteenth
public boolean is_sixteenth(int beat) -
event_count
public int event_count(int beat, float note) -
event_phase_count
public int event_phase_count(int beat, int phase, int offset) -
main
-