# NOTESTACK

## Functions
s32 | NOTESTACK_Init (notestack_t *n, notestack_mode_t mode, notestack_item_t *note_items, u8 size)
s32 | NOTESTACK_Push (notestack_t *n, u8 new_note, u8 tag)
s32 | NOTESTACK_Pop (notestack_t *n, u8 old_note)
s32 | NOTESTACK_CountActiveNotes (notestack_t *n)
s32 | NOTESTACK_RemoveNonActiveNotes (notestack_t *n)
s32 | NOTESTACK_Clear (notestack_t *n)
s32 | NOTESTACK_SendDebugMessage (notestack_t *n)

## Detailed Description

Generic Notestack Module

Usage Examples: $MIOS32_PATH/apps/tutorial/016_aout $MIOS32_PATH/apps/tutorial/017_sequencer $MIOS32_PATH/apps/tutorial/018_arpeggiator $MIOS32_PATH/apps/sequencers/midibox_seq_v4/core/seq_midi_in.c

## Function Documentation

s32 NOTESTACK_Clear | ( | notestack_t * | n | ) |

Clears the note stack

Parameters:

  `[in]` | *n | pointer to notestack structure

Returns:
  < 0 on errors

s32 NOTESTACK_CountActiveNotes | ( | notestack_t * | n | ) |

Counts all active notes in notestack

Parameters:

  `[in]` | *n | pointer to notestack structure

Returns:
  < 0 on errors
  0 if no active note
  > 0 if active notes have been found

s32 NOTESTACK_Init | ( | notestack_t * | n,
|  | notestack_mode_t | mode,
|  | notestack_item_t * | note_items,
|  | u8 | size |
| ) |  |  |

Initializes a Notestack

Has to be called before NOTESTACK_Push/Pop/Clear functions are used!

Parameters:

  `[in]` | *n | pointer to notestack structure
  `[in]` | mode | one of following modes: NOTESTACK_MODE_PUSH_TOP: new notes are added to the top of the note stack NOTESTACK_MODE_PUSH_BOTTOM: new notes are added to the bottom of the note stack NOTESTACK_MODE_PUSH_TOP_HOLD: same like above, but notes won't be removed so long there is a free item in note stack. Instead, they will be marked with .depressed=1 NOTESTACK_MODE_PUSH_BOTTOM_HOLD,: same like above, but new notes will be added to the bottom of the note stack NOTESTACK_MODE_SORT: Notes will be sorted NOTESTACK_MODE_SORT_HOLD: Like above, but notes won't be removed so long there is a free item in note stack. Instead, they will be marked with .depressed=1
  `[in]` | *note_items | pointer to notestack_item_t array which stores the notes and related informations
  `[in]` | size | number of note items stored in the array

Returns:
  < 0 if initialisation failed

Here is the call graph for this function:

s32 NOTESTACK_Pop | ( | notestack_t * | n,
|  | u8 | old_note |
| ) |  |  |

Removes a note from the stack

Parameters:

  `[in]` | *n | pointer to notestack structure
  `[in]` | old_note | the note number which should be removed (1..127)

Returns:
  < 0 on errors
  0 if note hasn't been found
  1 if note has been found and removed from stack (in hold mode: marked as depressed)
  2 only in hold mode: if all notes are depressed now

s32 NOTESTACK_Push | ( | notestack_t * | n,
|  | u8 | new_note,
|  | u8 | tag |
| ) |  |  |

Pushes a new note, bundled with a tag, to the note stack

Parameters:

  `[in]` | *n | pointer to notestack structure
  `[in]` | new_note | the note number which should be added (1..127)
  `[in]` | tag | an optional tag which is bundled with the note. It can contain a voice number, the velocity, or...

Returns:
  < 0 on errors

Here is the call graph for this function:

s32 NOTESTACK_RemoveNonActiveNotes | ( | notestack_t * | n | ) |

Removes all non-active notes from notestack

Parameters:

  `[in]` | *n | pointer to notestack structure

Returns:
  < 0 on errors

s32 NOTESTACK_SendDebugMessage | ( | notestack_t * | n | ) |

Sends the content of the Notestack to the MIOS Terminal

Parameters:

  `[in]` | *n | pointer to notestack structure

Returns:
  < 0 on errors

Here is the call graph for this function: