uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
Functions | Variables
sequencer.c File Reference

Sequencer module implementation. More...

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <avr/eeprom.h>
#include <avr/wdt.h>
#include "gpio.h"
#include "math.h"
#include "midi.h"
#include "sequencer.h"
#include "wave.h"
Include dependency graph for sequencer.c:

Functions

enum sequencer_pattern_number adjust_sequencer_pattern (struct sequencer_channel *const channel, const int8_t difference)
 Increments or decrements a sequencer channel's pattern index. More...
 
midi_value_t adjust_sequencer_speed (struct sequencer_channel *const channel, const int8_t difference)
 Increments or decrements a sequencer channel's speed. More...
 
void configure_sequencer_channel (const enum sequencer_channel_number number, struct sequencer_channel *const channel)
 Configures a sequencer channel. More...
 
void copy_pattern (const enum sequencer_pattern_number source, const enum sequencer_pattern_number destination)
 Copies a sequencer pattern. More...
 
char * export_pattern (const enum sequencer_pattern_number pattern_index)
 Dumps a sequencer pattern. More...
 
uint8_t get_pattern_length (const enum sequencer_pattern_number pattern_index)
 Reads a sequencer pattern's length. More...
 
struct sequencer_step get_pattern_step (const enum sequencer_pattern_number pattern_index, const uint8_t step_index)
 Reads step from a sequencer pattern. More...
 
void import_pattern (const enum sequencer_pattern_number pattern_index, const char *data)
 Stores a pattern given as a hex-string at the specified location. More...
 
void init_sequencer_patterns (const struct sequencer_pattern *const factory_patterns, const uint8_t number_of_patterns)
 Initializes / Restores "factory-default" patterns. More...
 
void overwrite_pattern (const enum sequencer_pattern_number pattern_index, const struct sequencer_pattern *const pattern)
 Stores a given pattern at the specified location. More...
 
void set_pattern_length (const enum sequencer_pattern_number pattern_index, const uint8_t length)
 Sets a sequencer pattern's length. More...
 
void set_pattern_step (const enum sequencer_pattern_number pattern_index, const uint8_t step_index, const struct sequencer_step *const step)
 Modifies a single step in a sequencer pattern. More...
 
void set_sequencer_pattern (struct sequencer_channel *const channel, const enum sequencer_pattern_number pattern)
 Selects a sequencer channel's pattern. More...
 
void set_sequencer_speed (struct sequencer_channel *const channel, const midi_value_t speed)
 Sets a sequencer channel's speed. More...
 
void start_sequencer (struct sequencer_channel *const channel)
 Starts a sequencer channel. More...
 
void stop_sequencer (struct sequencer_channel *const channel)
 Stops a sequencer channel. More...
 
bool toggle_sequencer (struct sequencer_channel *const channel)
 Starts or stops a sequencer channel. More...
 
void update_sequencer (void)
 Main background task for the sequencer module. More...
 
void wipe_pattern (const enum sequencer_pattern_number pattern_index)
 Wipes a sequencer pattern. More...
 

Variables

static struct sequencer_pattern patterns [SEQUENCER_PATTERNSEEMEM
 
static struct sequencer_channelchannels [SEQUENCER_CHANNELS] = {0,}
 Internal array of sequencer channels. More...
 

Detailed Description

Sequencer module implementation.

Function Documentation

◆ adjust_sequencer_pattern()

enum sequencer_pattern_number adjust_sequencer_pattern ( struct sequencer_channel channel,
int8_t  difference 
)

Increments or decrements a sequencer channel's pattern index.

Rotates the pattern index, for example: If the resulting pattern index is greater than the number of patterns, counting restarts at the first pattern.

Parameters
channelthe sequencer channel to adjust
differencean offset from the currently stored pattern
Returns
the set pattern

◆ adjust_sequencer_speed()

midi_value_t adjust_sequencer_speed ( struct sequencer_channel channel,
int8_t  difference 
)

Increments or decrements a sequencer channel's speed.

Cyclically rotates the speed in the range of a MIDI value [0 .. 127].

Parameters
channelthe sequencer channel to adjust
differencean offset from the current speed
Returns
the newly set speed

◆ configure_sequencer_channel()

void configure_sequencer_channel ( enum sequencer_channel_number  number,
struct sequencer_channel channel 
)

Configures a sequencer channel.

This function also registers the channel's wave with the tap tempo function.

Parameters
numberthe sequencer channel slot to use
channelthe sequencer channel
See also
sequencer_channel
register_tap

◆ copy_pattern()

void copy_pattern ( enum sequencer_pattern_number  source,
enum sequencer_pattern_number  destination 
)

Copies a sequencer pattern.

Duplicates the pattern at the source index and overwrites the pattern at the destination index with it.

Parameters
sourcenumber of the pattern to copy
destinationnumber of the pattern to overwrite

◆ export_pattern()

char* export_pattern ( enum sequencer_pattern_number  number)

Dumps a sequencer pattern.

Reads the data from EEPROM and converts it to a string of hexadecimal digits.

Parameters
numbernumber of the pattern to export
Returns
the pattern stored in EEPROM as a hex-string

◆ get_pattern_length()

uint8_t get_pattern_length ( enum sequencer_pattern_number  pattern)

Reads a sequencer pattern's length.

Parameters
patternnumber of the pattern
Returns
the selected pattern's length

◆ get_pattern_step()

struct sequencer_step get_pattern_step ( enum sequencer_pattern_number  pattern,
uint8_t  index 
)

Reads step from a sequencer pattern.

Parameters
patternnumber of the sequencer pattern containing the step to read
indexthe index of the step within the pattern
Returns
the requested sequencer step

◆ import_pattern()

void import_pattern ( enum sequencer_pattern_number  number,
const char *  data 
)

Stores a pattern given as a hex-string at the specified location.

Overwrites stored data!

Parameters
numbernumber of the pattern to overwrite
datathe new pattern to store as a string of hexadecimal digits

◆ init_sequencer_patterns()

void init_sequencer_patterns ( const struct sequencer_pattern factory_patterns,
uint8_t  number_of_patterns 
)

Initializes / Restores "factory-default" patterns.

Copies a list of patterns to the start of the EEPROM pattern storage.

Parameters
factory_patternsa pointer to a list of "factory"-default patterns
number_of_patternsnumber of "factory" patterns

◆ overwrite_pattern()

void overwrite_pattern ( enum sequencer_pattern_number  number,
const struct sequencer_pattern pattern 
)

Stores a given pattern at the specified location.

Overwrites stored data! Checks if the data actually changed before writing to save EEPROM write cycles.

Parameters
numbernumber of the pattern to overwrite
patternthe new pattern to store

◆ set_pattern_length()

void set_pattern_length ( enum sequencer_pattern_number  pattern,
uint8_t  length 
)

Sets a sequencer pattern's length.

Overwrites stored data!

Parameters
patternnumber of the sequencer pattern to modify
lengththe new pattern length

◆ set_pattern_step()

void set_pattern_step ( enum sequencer_pattern_number  pattern,
uint8_t  index,
const struct sequencer_step step 
)

Modifies a single step in a sequencer pattern.

Overwrites stored data!

Parameters
patternnumber of the sequencer pattern containing the step to modify
indexthe index of the step in the pattern to update
stepthe new sequencer step

◆ set_sequencer_pattern()

void set_sequencer_pattern ( struct sequencer_channel channel,
enum sequencer_pattern_number  pattern 
)

Selects a sequencer channel's pattern.

Parameters
channelthe sequencer channel to adjust
patternthe index of the new sequencer pattern

◆ set_sequencer_speed()

void set_sequencer_speed ( struct sequencer_channel channel,
midi_value_t  speed 
)

Sets a sequencer channel's speed.

Parameters
channelthe sequencer channel to adjust
speedthe new speed

◆ start_sequencer()

void start_sequencer ( struct sequencer_channel channel)

Starts a sequencer channel.

If the channel is already running, it is restarted.

Parameters
channelthe sequencer channel to (re-)start

◆ stop_sequencer()

void stop_sequencer ( struct sequencer_channel channel)

Stops a sequencer channel.

Parameters
channelthe sequencer channel to stop

◆ toggle_sequencer()

bool toggle_sequencer ( struct sequencer_channel channel)

Starts or stops a sequencer channel.

Parameters
channelthe sequencer channel to toggle
Returns
true if the channel was activated; false if it was deactivated

◆ update_sequencer()

void update_sequencer ( void  )

Main background task for the sequencer module.

This task plays active (-> started) sequencer channels. It uses the wave module as an internal clock source, so it must be registered as a fast background task.

See also
update_wave

◆ wipe_pattern()

void wipe_pattern ( enum sequencer_pattern_number  number)

Wipes a sequencer pattern.

Zeroes out memory at the given sequencer pattern index.

Parameters
numbernumber of the pattern to wipe

Variable Documentation

◆ channels

struct sequencer_channel* channels[SEQUENCER_CHANNELS] = {0,}
static

Internal array of sequencer channels.

◆ EEMEM

struct sequencer_pattern patterns [SEQUENCER_PATTERNS] EEMEM
static