It is accomplished ...
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef _MIDI_H_
|
||||
#define _MIDI_H_
|
||||
|
||||
#include <MidiDefs.h>
|
||||
#include <OS.h>
|
||||
|
||||
class BMidiEvent;
|
||||
class BList;
|
||||
|
||||
class BMidi {
|
||||
public:
|
||||
BMidi();
|
||||
virtual ~BMidi();
|
||||
|
||||
virtual void NoteOff(uchar channel, uchar note,
|
||||
uchar velocity, uint32 time = B_NOW);
|
||||
virtual void NoteOn(uchar channel, uchar note,
|
||||
uchar velocity, uint32 time = B_NOW);
|
||||
virtual void KeyPressure(uchar channel, uchar note,
|
||||
uchar pressure, uint32 time = B_NOW);
|
||||
virtual void ControlChange(uchar channel, uchar control_number,
|
||||
uchar control_value, uint32 time = B_NOW);
|
||||
virtual void ProgramChange(uchar channel, uchar program_number,
|
||||
uint32 time = B_NOW);
|
||||
virtual void ChannelPressure(uchar channel, uchar pressure,
|
||||
uint32 time = B_NOW);
|
||||
virtual void PitchBend(uchar channel, uchar lsb,
|
||||
uchar msb, uint32 time = B_NOW);
|
||||
virtual void SystemExclusive(void * data, size_t data_length,
|
||||
uint32 time = B_NOW);
|
||||
virtual void SystemCommon(uchar status_byte, uchar data1,
|
||||
uchar data2, uint32 time = B_NOW);
|
||||
virtual void SystemRealTime(uchar status_byte, uint32 time = B_NOW);
|
||||
virtual void TempoChange(int32 beats_per_minute, uint32 time = B_NOW);
|
||||
virtual void AllNotesOff(bool just_channel = true, uint32 time = B_NOW);
|
||||
|
||||
virtual status_t Start();
|
||||
virtual void Stop();
|
||||
|
||||
bool IsRunning() const;
|
||||
void Connect(BMidi * to_object);
|
||||
void Disconnect(BMidi * from_object);
|
||||
bool IsConnected(BMidi * to_object) const;
|
||||
BList * Connections() const;
|
||||
void SnoozeUntil(uint32 time) const;
|
||||
|
||||
protected:
|
||||
void SprayNoteOff(uchar channel, uchar note,
|
||||
uchar velocity, uint32 time) const;
|
||||
void SprayNoteOn(uchar channel, uchar note,
|
||||
uchar velocity, uint32 time) const;
|
||||
void SprayKeyPressure(uchar channel, uchar note,
|
||||
uchar pressure, uint32 time) const;
|
||||
void SprayControlChange(uchar channel, uchar control_number,
|
||||
uchar control_value, uint32 time) const;
|
||||
void SprayProgramChange(uchar channel, uchar program_number,
|
||||
uint32 time) const;
|
||||
void SprayChannelPressure(uchar channel, uchar pressure,
|
||||
uint32 time) const;
|
||||
void SprayPitchBend(uchar channel, uchar lsb,
|
||||
uchar msb, uint32 time) const;
|
||||
void SpraySystemExclusive(void * data, size_t data_length,
|
||||
uint32 time) const;
|
||||
void SpraySystemCommon(uchar status_byte, uchar data1,
|
||||
uchar data2, uint32 time) const;
|
||||
void SpraySystemRealTime(uchar status_byte, uint32 time) const;
|
||||
void SprayTempoChange(int32 beats_per_minute, uint32 time) const;
|
||||
|
||||
bool KeepRunning();
|
||||
|
||||
private:
|
||||
virtual void Run();
|
||||
void _Inflow();
|
||||
void _SprayEvent(BMidiEvent *) const;
|
||||
static int32 _RunThread(void * data);
|
||||
static int32 _InflowThread(void * data);
|
||||
|
||||
private:
|
||||
BList * _con_list;
|
||||
thread_id _run_thread_id;
|
||||
thread_id _inflow_thread_id;
|
||||
port_id _inflow_port;
|
||||
bool _is_running;
|
||||
bool _is_inflowing;
|
||||
bool _keep_running;
|
||||
};
|
||||
|
||||
#endif //_MIDI_H_
|
||||
@@ -0,0 +1,248 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef _MIDI_DEFS_H_
|
||||
#define _MIDI_DEFS_H_
|
||||
|
||||
#include <OS.h>
|
||||
#include <Errors.h>
|
||||
|
||||
#define B_NOW ((uint32)(system_time()/1000))
|
||||
|
||||
#define B_SYNTH_DIRECTORY B_BEOS_ETC_DIRECTORY
|
||||
#define B_BIG_SYNTH_FILE "synth/big_synth.sy"
|
||||
#define B_LITTLE_SYNTH_FILE "synth/little_synth.sy"
|
||||
|
||||
typedef enum synth_mode {
|
||||
B_NO_SYNTH,
|
||||
B_BIG_SYNTH,
|
||||
B_LITTLE_SYNTH,
|
||||
B_DEFAULT_SYNTH,
|
||||
B_SAMPLES_ONLY,
|
||||
} synth_mode;
|
||||
|
||||
enum {
|
||||
B_BAD_INSTRUMENT = B_MIDI_ERROR_BASE + 0x100,
|
||||
B_BAD_MIDI_DATA,
|
||||
B_ALREADY_PAUSED,
|
||||
B_ALREADY_RESUMED,
|
||||
B_NO_SONG_PLAYING,
|
||||
B_TOO_MANY_SONGS_PLAYING,
|
||||
};
|
||||
|
||||
#ifndef uchar
|
||||
typedef unsigned char uchar;
|
||||
#endif
|
||||
|
||||
#ifndef _MIDI_CONSTANTS_
|
||||
#define _MIDI_CONSTANTS_
|
||||
|
||||
const uchar B_NOTE_OFF = 0x80;
|
||||
const uchar B_NOTE_ON = 0x90;
|
||||
const uchar B_KEY_PRESSURE = 0xa0;
|
||||
const uchar B_CONTROL_CHANGE = 0xb0;
|
||||
const uchar B_PROGRAM_CHANGE = 0xc0;
|
||||
const uchar B_CHANNEL_PRESSURE = 0xd0;
|
||||
const uchar B_PITCH_BEND = 0xe0;
|
||||
|
||||
const uchar B_SYS_EX_START = 0xf0;
|
||||
const uchar B_MIDI_TIME_CODE = 0xf1;
|
||||
const uchar B_SONG_POSITION = 0xf2;
|
||||
const uchar B_SONG_SELECT = 0xf3;
|
||||
const uchar B_CABLE_MESSAGE = 0xf5;
|
||||
const uchar B_TUNE_REQUEST = 0xf6;
|
||||
const uchar B_SYS_EX_END = 0xf7;
|
||||
const uchar B_TIMING_CLOCK = 0xf8;
|
||||
const uchar B_START = 0xfa;
|
||||
const uchar B_CONTINUE = 0xfb;
|
||||
const uchar B_STOP = 0xfc;
|
||||
const uchar B_ACTIVE_SENSING = 0xfe;
|
||||
const uchar B_SYSTEM_RESET = 0xff;
|
||||
|
||||
const uchar B_MODULATION = 0x01;
|
||||
const uchar B_BREATH_CONTROLLER = 0x02;
|
||||
const uchar B_FOOT_CONTROLLER = 0x04;
|
||||
const uchar B_PORTAMENTO_TIME = 0x05;
|
||||
const uchar B_DATA_ENTRY = 0x06;
|
||||
const uchar B_MAIN_VOLUME = 0x07;
|
||||
const uchar B_MIDI_BALANCE = 0x08;
|
||||
const uchar B_PAN = 0x0a;
|
||||
const uchar B_EXPRESSION_CTRL = 0x0b;
|
||||
const uchar B_GENERAL_CTRL_1 = 0x10;
|
||||
const uchar B_GENERAL_CTRL_2 = 0x11;
|
||||
const uchar B_GENERAL_CTRL_3 = 0x12;
|
||||
const uchar B_GENERAL_CTRL_4 = 0x13;
|
||||
const uchar B_SUSTAIN_PEDAL = 0x40;
|
||||
const uchar B_PORTAMENTO = 0x41;
|
||||
const uchar B_SOSTENUTO = 0x42;
|
||||
const uchar B_SOFT_PEDAL = 0x43;
|
||||
const uchar B_HOLD_2 = 0x45;
|
||||
const uchar B_GENERAL_CTRL_5 = 0x50;
|
||||
const uchar B_GENERAL_CTRL_6 = 0x51;
|
||||
const uchar B_GENERAL_CTRL_7 = 0x52;
|
||||
const uchar B_GENERAL_CTRL_8 = 0x53;
|
||||
const uchar B_EFFECTS_DEPTH = 0x5b;
|
||||
const uchar B_TREMOLO_DEPTH = 0x5c;
|
||||
const uchar B_CHORUS_DEPTH = 0x5d;
|
||||
const uchar B_CELESTE_DEPTH = 0x5e;
|
||||
const uchar B_PHASER_DEPTH = 0x5f;
|
||||
const uchar B_DATA_INCREMENT = 0x60;
|
||||
const uchar B_DATA_DECREMENT = 0x61;
|
||||
const uchar B_RESET_ALL_CONTROLLERS = 0x79;
|
||||
const uchar B_LOCAL_CONTROL = 0x7a;
|
||||
const uchar B_ALL_NOTES_OFF = 0x7b;
|
||||
const uchar B_OMNI_MODE_OFF = 0x7c;
|
||||
const uchar B_OMNI_MODE_ON = 0x7d;
|
||||
const uchar B_MONO_MODE_ON = 0x7e;
|
||||
const uchar B_POLY_MODE_ON = 0x7f;
|
||||
|
||||
const uchar B_TEMPO_CHANGE = 0x51;
|
||||
|
||||
#endif
|
||||
|
||||
typedef enum midi_axe {
|
||||
B_ACOUSTIC_GRAND=0,
|
||||
B_BRIGHT_GRAND,
|
||||
B_ELECTRIC_GRAND,
|
||||
B_HONKY_TONK,
|
||||
B_ELECTRIC_PIANO_1,
|
||||
B_ELECTRIC_PIANO_2,
|
||||
B_HARPSICHORD,
|
||||
B_CLAVICHORD,
|
||||
B_CELESTA,
|
||||
B_GLOCKENSPIEL,
|
||||
B_MUSIC_BOX,
|
||||
B_VIBRAPHONE,
|
||||
B_MARIMBA,
|
||||
B_XYLOPHONE,
|
||||
B_TUBULAR_BELLS,
|
||||
B_DULCIMER,
|
||||
B_DRAWBAR_ORGAN,
|
||||
B_PERCUSSIVE_ORGAN,
|
||||
B_ROCK_ORGAN,
|
||||
B_CHURCH_ORGAN,
|
||||
B_REED_ORGAN,
|
||||
B_ACCORDION,
|
||||
B_HARMONICA,
|
||||
B_TANGO_ACCORDION,
|
||||
B_ACOUSTIC_GUITAR_NYLON,
|
||||
B_ACOUSTIC_GUITAR_STEEL,
|
||||
B_ELECTRIC_GUITAR_JAZZ,
|
||||
B_ELECTRIC_GUITAR_CLEAN,
|
||||
B_ELECTRIC_GUITAR_MUTED,
|
||||
B_OVERDRIVEN_GUITAR,
|
||||
B_DISTORTION_GUITAR,
|
||||
B_GUITAR_HARMONICS,
|
||||
B_ACOUSTIC_BASS,
|
||||
B_ELECTRIC_BASS_FINGER,
|
||||
B_ELECTRIC_BASS_PICK,
|
||||
B_FRETLESS_BASS,
|
||||
B_SLAP_BASS_1,
|
||||
B_SLAP_BASS_2,
|
||||
B_SYNTH_BASS_1,
|
||||
B_SYNTH_BASS_2,
|
||||
B_VIOLIN,
|
||||
B_VIOLA,
|
||||
B_CELLO,
|
||||
B_CONTRABASS,
|
||||
B_TREMOLO_STRINGS,
|
||||
B_PIZZICATO_STRINGS,
|
||||
B_ORCHESTRAL_STRINGS,
|
||||
B_TIMPANI,
|
||||
B_STRING_ENSEMBLE_1,
|
||||
B_STRING_ENSEMBLE_2,
|
||||
B_SYNTH_STRINGS_1,
|
||||
B_SYNTH_STRINGS_2,
|
||||
B_VOICE_AAH,
|
||||
B_VOICE_OOH,
|
||||
B_SYNTH_VOICE,
|
||||
B_ORCHESTRA_HIT,
|
||||
B_TRUMPET,
|
||||
B_TROMBONE,
|
||||
B_TUBA,
|
||||
B_MUTED_TRUMPET,
|
||||
B_FRENCH_HORN,
|
||||
B_BRASS_SECTION,
|
||||
B_SYNTH_BRASS_1,
|
||||
B_SYNTH_BRASS_2,
|
||||
B_SOPRANO_SAX,
|
||||
B_ALTO_SAX,
|
||||
B_TENOR_SAX,
|
||||
B_BARITONE_SAX,
|
||||
B_OBOE,
|
||||
B_ENGLISH_HORN,
|
||||
B_BASSOON,
|
||||
B_CLARINET,
|
||||
B_PICCOLO,
|
||||
B_FLUTE,
|
||||
B_RECORDER,
|
||||
B_PAN_FLUTE,
|
||||
B_BLOWN_BOTTLE,
|
||||
B_SHAKUHACHI,
|
||||
B_WHISTLE,
|
||||
B_OCARINA,
|
||||
B_LEAD_1,
|
||||
B_SQUARE_WAVE = B_LEAD_1,
|
||||
B_LEAD_2,
|
||||
B_SAWTOOTH_WAVE = B_LEAD_2,
|
||||
B_LEAD_3,
|
||||
B_CALLIOPE = B_LEAD_3,
|
||||
B_LEAD_4,
|
||||
B_CHIFF = B_LEAD_4,
|
||||
B_LEAD_5,
|
||||
B_CHARANG = B_LEAD_5,
|
||||
B_LEAD_6,
|
||||
B_VOICE = B_LEAD_6,
|
||||
B_LEAD_7,
|
||||
B_FIFTHS = B_LEAD_7,
|
||||
B_LEAD_8,
|
||||
B_BASS_LEAD = B_LEAD_8,
|
||||
B_PAD_1,
|
||||
B_NEW_AGE = B_PAD_1,
|
||||
B_PAD_2,
|
||||
B_WARM = B_PAD_2,
|
||||
B_PAD_3,
|
||||
B_POLYSYNTH = B_PAD_3,
|
||||
B_PAD_4,
|
||||
B_CHOIR = B_PAD_4,
|
||||
B_PAD_5,
|
||||
B_BOWED = B_PAD_5,
|
||||
B_PAD_6,
|
||||
B_METALLIC = B_PAD_6,
|
||||
B_PAD_7,
|
||||
B_HALO = B_PAD_7,
|
||||
B_PAD_8,
|
||||
B_SWEEP = B_PAD_8,
|
||||
B_FX_1,
|
||||
B_FX_2,
|
||||
B_FX_3,
|
||||
B_FX_4,
|
||||
B_FX_5,
|
||||
B_FX_6,
|
||||
B_FX_7,
|
||||
B_FX_8,
|
||||
B_SITAR,
|
||||
B_BANJO,
|
||||
B_SHAMISEN,
|
||||
B_KOTO,
|
||||
B_KALIMBA,
|
||||
B_BAGPIPE,
|
||||
B_FIDDLE,
|
||||
B_SHANAI,
|
||||
B_TINKLE_BELL,
|
||||
B_AGOGO,
|
||||
B_STEEL_DRUMS,
|
||||
B_WOODBLOCK,
|
||||
B_TAIKO_DRUMS,
|
||||
B_MELODIC_TOM,
|
||||
B_SYNTH_DRUM,
|
||||
B_REVERSE_CYMBAL,
|
||||
B_FRET_NOISE,
|
||||
B_BREATH_NOISE,
|
||||
B_SEASHORE,
|
||||
B_BIRD_TWEET,
|
||||
B_TELEPHONE,
|
||||
B_HELICOPTER,
|
||||
B_APPLAUSE,
|
||||
B_GUNSHOT
|
||||
} midi_axe;
|
||||
|
||||
#endif //_MIDI_DEFS_H_
|
||||
@@ -0,0 +1,76 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef _MIDI_STORE_H_
|
||||
#define _MIDI_STORE_H_
|
||||
|
||||
#include <Midi.h>
|
||||
#include <List.h>
|
||||
|
||||
struct entry_ref;
|
||||
class BMidiEvent;
|
||||
class BFile;
|
||||
|
||||
class BMidiStore : public BMidi {
|
||||
public:
|
||||
BMidiStore();
|
||||
virtual ~BMidiStore();
|
||||
|
||||
virtual void NoteOff(uchar channel, uchar note,
|
||||
uchar velocity, uint32 time = B_NOW);
|
||||
virtual void NoteOn(uchar channel, uchar note,
|
||||
uchar velocity, uint32 time = B_NOW);
|
||||
virtual void KeyPressure(uchar channel, uchar note,
|
||||
uchar pressure, uint32 time = B_NOW);
|
||||
virtual void ControlChange(uchar channel, uchar control_number,
|
||||
uchar control_value, uint32 time = B_NOW);
|
||||
virtual void ProgramChange(uchar channel, uchar program_number,
|
||||
uint32 time = B_NOW);
|
||||
virtual void ChannelPressure(uchar channel, uchar pressure,
|
||||
uint32 time = B_NOW);
|
||||
virtual void PitchBend(uchar channel, uchar lsb,
|
||||
uchar msb, uint32 time = B_NOW);
|
||||
virtual void SystemExclusive(void * data, size_t data_length,
|
||||
uint32 time = B_NOW);
|
||||
virtual void SystemCommon(uchar status_byte, uchar data1,
|
||||
uchar data2, uint32 time = B_NOW);
|
||||
virtual void SystemRealTime(uchar status_byte, uint32 time = B_NOW);
|
||||
virtual void TempoChange(int32 beats_per_minute, uint32 time = B_NOW);
|
||||
virtual void AllNotesOff(bool just_channel = true, uint32 time = B_NOW);
|
||||
|
||||
status_t Import(const entry_ref * ref);
|
||||
status_t Export(const entry_ref * ref, int32 format);
|
||||
|
||||
void SortEvents(bool force = false);
|
||||
uint32 CountEvents() const;
|
||||
uint32 CurrentEvent() const;
|
||||
void SetCurrentEvent(uint32 event_number);
|
||||
uint32 DeltaOfEvent(uint32 event_number) const;
|
||||
uint32 EventAtDelta(uint32 time) const;
|
||||
uint32 BeginTime() const;
|
||||
void SetTempo(int32 beats_per_minute);
|
||||
int32 Tempo() const;
|
||||
|
||||
private:
|
||||
virtual void Run();
|
||||
void _RunThread();
|
||||
uint8* _DecodeTrack(uint8 *);
|
||||
void _DecodeFormat0Tracks(uint8 *, uint16, uint32);
|
||||
void _DecodeFormat1Tracks(uint8 *, uint16, uint32);
|
||||
void _DecodeFormat2Tracks(uint8 *, uint16, uint32);
|
||||
void _EncodeFormat0Tracks(uint8 *);
|
||||
void _EncodeFormat1Tracks(uint8 *);
|
||||
void _EncodeFormat2Tracks(uint8 *);
|
||||
void _ReadEvent(uint8, uint8 **, uint8 *, BMidiEvent *);
|
||||
void _WriteEvent(BMidiEvent *);
|
||||
uint32 _ReadVarLength(uint8 **, uint8 *);
|
||||
void _WriteVarLength(uint32);
|
||||
static int _CompareEvents(const void *, const void *);
|
||||
|
||||
private:
|
||||
BList * _evt_list;
|
||||
uint32 _tempo;
|
||||
uint32 _cur_evt;
|
||||
uint32 _start_time;
|
||||
uint32 _ticks_per_beat;
|
||||
};
|
||||
|
||||
#endif _MIDI_STORE_H_
|
||||
@@ -0,0 +1,43 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef _MIDI_TEXT_H_
|
||||
#define _MIDI_TEXT_H_
|
||||
|
||||
#include <Midi.h>
|
||||
|
||||
class BMidiText : public BMidi {
|
||||
public:
|
||||
BMidiText();
|
||||
virtual ~BMidiText();
|
||||
|
||||
virtual void NoteOff(uchar channel, uchar note,
|
||||
uchar velocity, uint32 time = B_NOW);
|
||||
virtual void NoteOn(uchar channel, uchar note,
|
||||
uchar velocity, uint32 time = B_NOW);
|
||||
virtual void KeyPressure(uchar channel, uchar note,
|
||||
uchar pressure, uint32 time = B_NOW);
|
||||
virtual void ControlChange(uchar channel, uchar control_number,
|
||||
uchar control_value, uint32 time = B_NOW);
|
||||
virtual void ProgramChange(uchar channel, uchar program_number,
|
||||
uint32 time = B_NOW);
|
||||
virtual void ChannelPressure(uchar channel, uchar pressure,
|
||||
uint32 time = B_NOW);
|
||||
virtual void PitchBend(uchar channel, uchar lsb,
|
||||
uchar msb, uint32 time = B_NOW);
|
||||
virtual void SystemExclusive(void * data, size_t data_length,
|
||||
uint32 time = B_NOW);
|
||||
virtual void SystemCommon(uchar status_byte, uchar data1,
|
||||
uchar data2, uint32 time = B_NOW);
|
||||
virtual void SystemRealTime(uchar status_byte, uint32 time = B_NOW);
|
||||
virtual void TempoChange(int32 beats_per_minute, uint32 time = B_NOW);
|
||||
virtual void AllNotesOff(bool just_channel = true, uint32 time = B_NOW);
|
||||
|
||||
void ResetTimer(bool start = false);
|
||||
|
||||
private:
|
||||
int32 _start_time;
|
||||
|
||||
private:
|
||||
void _PrintTime();
|
||||
};
|
||||
|
||||
#endif _MIDI_TEXT_H_
|
||||
Reference in New Issue
Block a user