3. DONE Step Data

CLOSED: [2019-02-24 Sun 14:16]

3.1. DONE Step Data Contents

CLOSED: [2019-02-24 Sun 14:16]

3.1.1. DONE Step Monome State Data

CLOSED: [2019-02-16 Sat 20:09] The current monome state is maintained in a monome state data flag called mstate.

<<step_contents>>=
monolith_page_mstate *mstate;
<<step_init>>=
monolith_page_mstate_new(pg, &s->mstate);
<<step_cleanup>>=
monolith_page_mstate_free(&s->mstate);

3.1.2. DONE Step Playhead Position

CLOSED: [2019-02-16 Sat 20:03] The playhead position is a integer variable which holds the position in the pattern. It is updated everytime the clock happens.

<<step_contents>>=
int playpos;
<<step_init>>=
page_step_playpos_set(s, 0);

The playhead position can be retrieved using the function page_step_playpos_get.

<<step_function_declarations>>=
static int page_step_playpos_get(page_step_d *step);
<<step_functions>>=
static int page_step_playpos_get(page_step_d *step)
{
    return step->playpos;
}

The playhead can be set using the function page_step_playpos_set. This function may update the playhead position when called. If JAM mode is disabled, the edit position is set here as well.

<<step_function_declarations>>=
static void page_step_playpos_set(page_step_d *step, int playpos);
<<step_functions>>=
static void page_step_playpos_set(page_step_d *step, int playpos)
{
    step->playpos = playpos;
    if(!page_step_jam_mode(step)) {
        step->editpos = playpos;
    }
}

3.1.3. DONE Step Edit Position

CLOSED: [2019-02-24 Sun 15:31] The edit position inidicates the currently edited note. Normally, this is identical to the playhead position, unless Jam Mode is turned on. The edit position is saved as a variable editpos.

<<step_contents>>=
int editpos;
<<step_init>>=
s->editpos = 0;

The edit position is handled using the functions page_step_editpos_get and page_step_editpos_set.

<<step_function_declarations>>=
static int page_step_editpos_get(page_step_d *step);
static void page_step_editpos_set(page_step_d *step, int pos);

TODO: make sure draw_playhead is only called in editpos_set or playhead_set.

<<step_functions>>=
static int page_step_editpos_get(page_step_d *step)
{
    return step->editpos;
}

static void page_step_editpos_set(page_step_d *step, int pos)
{
    step->editpos = pos;
    if(!page_step_jam_mode(step)) {
        step->playpos = pos;
    }
    /* page_step_draw_playhead(step); */
    /* page_step_draw_current_note(step); */
}

3.1.4. DONE Jam Mode Flag

CLOSED: [2019-02-24 Sun 15:31] Jam Mode allows a sequence to be edited while it is playing. Turning this mode on will decouple the edit and playhead position. Jam mode is disabled by default.

<<step_contents>>=
int jam_mode;
<<step_init>>=
s->jam_mode = 0;

To check of jam mode is on, the function page_step_jam_mode, and page_step_jam_mode_get.

<<step_function_declarations>>=
static int page_step_jam_mode(page_step_d *step);
static int page_step_jam_mode_get(page_step_d *step);
<<step_functions>>=
static int page_step_jam_mode_get(page_step_d *step)
{
    return step->jam_mode;
}
static int page_step_jam_mode(page_step_d *step)
{
    return page_step_jam_mode_get(step);
}

3.1.5. TODO Latch Mode Flag

When Latch Mode is enabled, the sequencer will save the last selected or edited note. When a new note is create with the gate flag, it will set that note to that edited note.

<<step_contents>>=
int latch_mode;
<<step_init>>=
s->latch_mode = 0;

Latch mode is checked with page_step_latch_mode.

<<step_function_declarations>>=
static int page_step_latch_mode(page_step_d *step);
<<step_functions>>=
static int page_step_latch_mode(page_step_d *step)
{
    return step->latch_mode;
}

3.1.6. TODO Last Note

The last edited or selected note is stored in a variable called last_note. This value is used in Latch Mode.

<<step_contents>>=
signed char last_note;
<<step_init>>=
s->last_note = 0;

3.1.7. DONE Step Current Pattern

CLOSED: [2019-02-16 Sat 20:03] The currently selected pattern displayed is stored in an integer called curpat. By default, it is set to be at pattern 0, the first pattern.

<<step_contents>>=
int curpat;
<<step_init>>=
s->curpat = 0;

3.1.8. DONE Step Pattern Bank

CLOSED: [2019-02-16 Sat 20:03] The step page has a pre-allocated set of patterns, for sequencing long-form songs. This maximum is defined by MAXPAT, which is currently set to be 64.

<<step_macros>>=
#define MAXPAT 64
<<step_contents>>=
step_pattern pat[MAXPAT];
<<step_init>>=
for(i = 0; i < MAXPAT; i++) step_pattern_init(&s->pat[i]);
<<first_pattern_active>>

By default, the first pattern is set to be active. This could change, when patterns and sequences start being used.

<<first_pattern_active>>=
step_pattern_active_set(&s->pat[0], 1);

3.1.9. TODO Step Number of Active Patterns

3.1.10. DONE Step Song Pattern Map

CLOSED: [2019-02-16 Sat 19:56] A "song" is a sequence of patterns. The step song map is an array of integers, each corresponding to a pattern number. The maximum song length is indidcated with MAXSONGLEN to be 128.

<<step_macros>>=
#define MAXSONGLEN 128
<<step_contents>>=
int songmap[MAXSONGLEN];
<<step_init>>=
for(i = 0; i < MAXSONGLEN; i++) s->songmap[i] = 0;

3.1.11. DONE Step Song Length (number of patterns)

CLOSED: [2019-02-16 Sat 19:58] The length indicates how long the song is (aka how many song patterns to read).

<<step_contents>>=
int song_len;
<<step_init>>=
s->song_len = 1;

3.1.12. DONE Step Playing Flag

CLOSED: [2019-02-16 Sat 20:02] The playing flag is used to indicate whether or not the sequence is actually playing. This is just a 1 or 0 operation.

<<step_contents>>=
int playing;
<<step_init>>=
page_step_playing_set(s, 1);

The playing variable is acessed with the function page_step_playing_set, page_step_playing_get, and page_step_is_playing.

<<step_function_declarations>>=
void page_step_playing_set(page_step_d *step, int s);
int page_step_playing_get(page_step_d *step);
int page_step_is_playing(page_step_d *step);
<<step_functions>>=
void page_step_playing_set(page_step_d *step, int s)
{
    step->playing = s;
    page_step_draw_toolbar(step, 0, s);
}

int page_step_playing_get(page_step_d *step)
{
    return step->playing;
}

int page_step_is_playing(page_step_d *step)
{
    return page_step_playing_get(step);
}

3.1.13. TODO Step size

This variable indicates how much to jump. If negative, it will go backwards.

<<step_contents>>=
int step;
<<step_init>>=
page_step_step_set(s, 1);
<<step_function_declarations>>=
void page_step_step_set(page_step_d *step, int s);
<<step_functions>>=
void page_step_step_set(page_step_d *step, int s)
{
    step->step = s;
}

3.1.14. DONE Wait and reset flag

CLOSED: [2019-12-04 Wed 09:49] This flag is used with the wait and reset functionality.

<<step_contents>>=
int wait_and_reset;
<<step_init>>=
s->wait_and_reset = 0;

3.2. Step Typedef Declaration

The top-level data struct for the step page is called page_step_d.

<<step_typedefs>>=
typedef struct page_step_d page_step_d;
<<step_structs>>=
<<step_pattern_struct>>
struct page_step_d {
<<step_contents>>
};

3.3. DONE Step Data Allocation/Initialization

CLOSED: [2019-02-16 Sat 19:36] Step data is allocated and initialized with the function page_step_create.

<<step_function_declarations>>=
void page_step_create(monolith_page *pg, page_step_d **step);
<<step_functions>>=
void page_step_create(monolith_page *pg, page_step_d **step)
{
    page_step_d *s;
    int i;
    s = calloc(1, sizeof(page_step_d));
    *step = s;
    /* TODO: implement */
<<step_init>>
    page_step_draw_playhead(*step);
    page_step_draw_current_note(*step);
}

3.4. DONE Step Data Cleanup

CLOSED: [2019-02-16 Sat 19:37] Data is freed with the function page_step_destroy.

<<step_function_declarations>>=
void page_step_destroy(page_step_d **step);
<<step_functions>>=
void page_step_destroy(page_step_d **step)
{
    page_step_d *s;
    s = *step;
<<step_cleanup>>
    free(*step);
}

3.5. DONE Step Pattern

CLOSED: [2019-02-16 Sat 20:10]

3.5.1. DONE Step Pattern Struct Declaration

CLOSED: [2019-02-16 Sat 20:09] Data for a pattern sequenced with step is wrapped inside of a struct called step_pattern. This is done so that multiple patterns can be sequenced inside of a single instance of step.

<<step_typedefs>>=
typedef struct step_pattern step_pattern;
<<step_pattern_struct>>=
struct step_pattern {
<<step_pattern_contents>>
};

3.5.2. DONE Step Pattern Initialization

CLOSED: [2019-02-16 Sat 20:08] A step pattern is initialized with the function step_pattern_init.

<<step_function_declarations>>=
void step_pattern_init(step_pattern *pat);
<<step_functions>>=
void step_pattern_init(step_pattern *pat)
{
    int i;
<<step_pattern_init>>
}

3.5.3. DONE Step Pattern Size

CLOSED: [2019-02-16 Sat 19:46] The size of the pattern is stored as an integer value. At the moment, this value is set to be 32, which, for now, is also the maximum size MAXSIZE.

<<step_pattern_contents>>=
int size;
<<step_macros>>=
#define MAXSIZE 32
<<step_pattern_init>>=
pat->size = MAXSIZE;

The pattern size can be retrieved with the function step_pattern_size_get.

<<step_function_declarations>>=
static int step_pattern_size_get(step_pattern *pat);
<<step_functions>>=
static int step_pattern_size_get(step_pattern *pat)
{
    return pat->size;
}

3.5.4. DONE Step Active Flag

CLOSED: [2019-04-07 Sun 22:12] A pattern has an internal active flag to inidicate if it is being used or not. This is specifically used so that when the page state is saved to disk, it only writes the used patterns.

<<step_pattern_contents>>=
int active;
<<step_pattern_init>>=
pat->active = 0;

The active flag can be manipulated with the function step_pattern_active_setand checked with step_pattern_active.

<<step_function_declarations>>=
static void step_pattern_active_set(step_pattern *pat, int active);
static int step_pattern_active(step_pattern *pat);
<<step_functions>>=
static void step_pattern_active_set(step_pattern *pat, int active)
{
    pat->active = active;
}
static int step_pattern_active(step_pattern *pat)
{
    return pat->active;
}

3.5.5. DONE Step Note Data

CLOSED: [2019-02-16 Sat 19:46] Note data holds the relative pitch values. Nothing more than array here. Since they are expected to be in the range of -12 to 24, 8-bit signed char values are good enough.

<<step_pattern_contents>>=
signed char notes[MAXSIZE];
<<step_pattern_init>>=
for(i = 0; i < MAXSIZE; i++) pat->notes[i] = 0;

A note can be retrieved using the function step_pattern_note_get.

<<step_function_declarations>>=
static signed char step_pattern_note_get(step_pattern *step, int pos);
<<step_functions>>=
static signed char step_pattern_note_get(step_pattern *step, int pos)
{
    if(pos < 0 || pos >= MAXSIZE) return 0;
    if(step == NULL) return 0;
    return step->notes[pos];
}

A note can be set using the function step_pattern_note_set. This will automatically truncate anything out of range of (-12, 25).

<<step_function_declarations>>=
static void step_pattern_note_set(step_pattern *step,
                                  int pos,
                                  signed char note);
<<step_functions>>=
static void step_pattern_note_set(step_pattern *step,
                                  int pos,
                                  signed char note)
{
    if(pos < 0 || pos >= MAXSIZE) return;
    if(step == NULL) return;
    if(note < -12) note = -12;
    if(note > 35) note = 35;
    step->notes[pos] = note;
}

3.5.6. DONE Step Gate Data

CLOSED: [2019-02-16 Sat 20:08] The gate determines the state of the note. 0 is off, 1 is on, and 2 might be a holdover value for long note values (aka this data could potentially instruct whether or not to (re)trigger values).

<<step_pattern_contents>>=
signed char gates[MAXSIZE];
<<step_pattern_init>>=
for(i = 0; i < MAXSIZE; i++) pat->gates[i] = 0;

The value of a gate can be retrieved using the function step_pattern_gate_get.

<<step_function_declarations>>=
static unsigned int step_pattern_gate_get(step_pattern *pat, int pos);
<<step_functions>>=
static unsigned int step_pattern_gate_get(step_pattern *pat, int pos)
{
    if(pos < 0) pos = 0;
    if(pos >= MAXSIZE) pos = MAXSIZE - 1;

    return pat->gates[pos];
}

The value of a gate can be set with the function step_pattern_gate_set.

<<step_function_declarations>>=
static void step_pattern_gate_set(step_pattern *pat, int pos, unsigned char g);
<<step_functions>>=
static void step_pattern_gate_set(step_pattern *pat, int pos, unsigned char g)
{
    if(pat == NULL) return;
    if(pos < 0) pos = 0;
    if(pos >= MAXSIZE) pos = MAXSIZE - 1;
    pat->gates[pos] = g;
}



prev | home | next