Commit df0624e0 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Add mono (program 1)

parent 16421d9d
PRG = crowbx
OBJ = crowbx.o midi.o dac.o voice.o uart.o gate.o poly.o
OBJ = crowbx.o midi.o dac.o voice.o uart.o gate.o poly.o mono.o
MCU_TARGET = atmega328p
#MCU_TARGET = at90s2313
#MCU_TARGET = at90s2333
......
......@@ -2,9 +2,18 @@
#include <util/delay.h>
#include "dac.h"
#include "gate.h"
#include "midi.h"
#include "voice.h"
#include "poly.h"
#include "mono.h"
enum _programs {
PGM_POLY,
PGM_MONO,
NUM_PGM,
};
uint8_t current_program;
void
io_init(void)
......@@ -19,13 +28,72 @@ io_init(void)
DDRD = _BV(PORTD1) | _BV(PORTD2) | _BV(PORTD3) | _BV(PORTD4) | _BV(PORTD5) | _BV(PORTD6) | _BV(PORTD7);
}
void
program_change(uint8_t pgm)
{
if ((pgm >= NUM_PGM) || (pgm == current_program)) {
return;
}
current_program = pgm;
for (uint8_t v = 0; v < NUM_VOICES; v++) {
gate_off(v);
}
switch (pgm) {
case PGM_POLY:
poly_init();
return;
case PGM_MONO:
mono_init();
return;
}
}
void
note_on(uint8_t note)
{
if (note > 127) {
return;
}
switch (current_program) {
case PGM_POLY:
poly_note_on(note);
return;
case PGM_MONO:
mono_note_on(note);
return;
}
}
void
note_off(uint8_t note)
{
if (note > 127) {
return;
}
switch (current_program) {
case PGM_POLY:
poly_note_off(note);
return;
case PGM_MONO:
mono_note_off(note);
return;
}
}
int
main(void)
{
io_init();
dac_init();
midi_init();
voice_init();
poly_init();
current_program = PGM_POLY;
for (;;) {
if (!midi_read()) {
......@@ -37,13 +105,15 @@ main(void)
uint8_t velocity = midi_data() & 0xff;
if (velocity > 0) {
poly_note_on(note);
note_on(note);
} else {
poly_note_off(note);
note_off(note);
}
} else if (midi_status() == MIDI_NOTE_OFF) {
uint8_t note = midi_data() >> 8;
poly_note_off(note);
note_off(note);
} else if (midi_status() == MIDI_PROGRAM_CHANGE) {
program_change(midi_data() >> 8);
}
}
......
#include "mono.h"
#include "dac.h"
#include "gate.h"
#include "voice.h"
uint8_t current_note;
#define NO_NOTE 255;
void
mono_init(void)
{
current_note = NO_NOTE;
}
void
mono_note_on(uint8_t note)
{
if (note > 127) {
return;
}
current_note = note;
for (uint8_t v = 0; v < NUM_VOICES; v++) {
dac_set_note(v, note);
gate_on(v);
}
}
void
mono_note_off(uint8_t note)
{
if (note > 127) {
return;
}
if (current_note != note) {
return;
}
for (uint8_t v = 0; v < NUM_VOICES; v++) {
gate_off(v);
}
}
#ifndef _mono_h
#define _mono_h
#include <inttypes.h>
void mono_init(void);
void mono_note_on(uint8_t note);
void mono_note_off(uint8_t note);
#endif
......@@ -3,6 +3,12 @@
#include "gate.h"
#include "voice.h"
void
poly_init(void)
{
voice_init();
}
void
poly_note_on(uint8_t note)
{
......
......@@ -3,6 +3,7 @@
#include <inttypes.h>
void poly_init(void);
void poly_note_on(uint8_t note);
void poly_note_off(uint8_t note);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment