uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
|
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"
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_PATTERNS] | EEMEM |
static struct sequencer_channel * | channels [SEQUENCER_CHANNELS] = {0,} |
Internal array of sequencer channels. More... | |
Sequencer module implementation.
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.
channel | the sequencer channel to adjust |
difference | an offset from the currently stored pattern |
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].
channel | the sequencer channel to adjust |
difference | an offset from the current speed |
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.
number | the sequencer channel slot to use |
channel | the sequencer channel |
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.
source | number of the pattern to copy |
destination | number of the pattern to overwrite |
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.
number | number of the pattern to export |
uint8_t get_pattern_length | ( | enum sequencer_pattern_number | pattern | ) |
Reads a sequencer pattern's length.
pattern | number of the pattern |
struct sequencer_step get_pattern_step | ( | enum sequencer_pattern_number | pattern, |
uint8_t | index | ||
) |
Reads step from a sequencer pattern.
pattern | number of the sequencer pattern containing the step to read |
index | the index of the step within the 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!
number | number of the pattern to overwrite |
data | the new pattern to store as a string of hexadecimal digits |
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.
factory_patterns | a pointer to a list of "factory"-default patterns |
number_of_patterns | number of "factory" patterns |
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.
number | number of the pattern to overwrite |
pattern | the new pattern to store |
void set_pattern_length | ( | enum sequencer_pattern_number | pattern, |
uint8_t | length | ||
) |
Sets a sequencer pattern's length.
Overwrites stored data!
pattern | number of the sequencer pattern to modify |
length | the new pattern length |
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!
pattern | number of the sequencer pattern containing the step to modify |
index | the index of the step in the pattern to update |
step | the new sequencer step |
void set_sequencer_pattern | ( | struct sequencer_channel * | channel, |
enum sequencer_pattern_number | pattern | ||
) |
Selects a sequencer channel's pattern.
channel | the sequencer channel to adjust |
pattern | the index of the new sequencer pattern |
void set_sequencer_speed | ( | struct sequencer_channel * | channel, |
midi_value_t | speed | ||
) |
Sets a sequencer channel's speed.
channel | the sequencer channel to adjust |
speed | the new speed |
void start_sequencer | ( | struct sequencer_channel * | channel | ) |
Starts a sequencer channel.
If the channel is already running, it is restarted.
channel | the sequencer channel to (re-)start |
void stop_sequencer | ( | struct sequencer_channel * | channel | ) |
Stops a sequencer channel.
channel | the sequencer channel to stop |
bool toggle_sequencer | ( | struct sequencer_channel * | channel | ) |
Starts or stops a sequencer channel.
channel | the sequencer channel to toggle |
true
if the channel was activated; false
if it was deactivated 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.
void wipe_pattern | ( | enum sequencer_pattern_number | number | ) |
Wipes a sequencer pattern.
Zeroes out memory at the given sequencer pattern index.
number | number of the pattern to wipe |
|
static |
Internal array of sequencer channels.
|
static |