Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnfrishert committed Sep 15, 2018
2 parents cf06e62 + 8fc434c commit 8e26aa8
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 59 deletions.
1 change: 1 addition & 0 deletions common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*/

#include <algorithm>
#include <iostream>

#include "common.hpp"
Expand Down
64 changes: 56 additions & 8 deletions liblsdj/instrument.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,36 @@ void read_wave_instrument(lsdj_vio_t* vio, unsigned char version, lsdj_instrumen
vio->read(&byte, 1, vio->user_data);
instrument->wave.playback = parsePlaybackMode(byte);

vio->seek(4, SEEK_CUR, vio->user_data); // Bytes 10-13 are empty
// WAVE length and speed changed in version 6
if (version >= 7)
{
vio->read(&byte, 1, vio->user_data); // Byte 10
instrument->wave.length = 0xF - (byte & 0xF);

vio->read(&byte, 1, vio->user_data); // Byte 11
instrument->wave.speed = byte + 4;
}
else if (version == 6)
{
vio->read(&byte, 1, vio->user_data); // Byte 10
instrument->wave.length = (byte & 0xF);

vio->read(&byte, 1, vio->user_data); // Byte 11
instrument->wave.speed = byte + 1;
} else {
vio->seek(2, SEEK_CUR, vio->user_data); // Bytes 12-13 are empty
}

vio->seek(2, SEEK_CUR, vio->user_data); // Bytes 10-13 are empty

vio->read(&byte, 1, vio->user_data);
instrument->wave.length = ((byte >> 4) & 0xF);
instrument->wave.speed = (byte & 0xF);

// WAVE length and speed changed in version 6
if (version < 6)
{
instrument->wave.length = ((byte >> 4) & 0xF);
instrument->wave.speed = (byte & 0xF) + 1;
}

vio->seek(1, SEEK_CUR, vio->user_data); // Byte 15 is empty
}
Expand Down Expand Up @@ -695,16 +720,39 @@ void write_wave_instrument(const lsdj_instrument_t* instrument, unsigned char ve
byte = createPlaybackModeByte(instrument->wave.playback);
vio->write(&byte, 1, vio->user_data);

byte = 0xD0;
vio->write(&byte, 1, vio->user_data); // Byte 10 is empty
if (version >= 7)
{
byte = 0xF - (instrument->wave.length & 0xF);
vio->write(&byte, 1, vio->user_data);

byte = instrument->wave.speed - 4;
vio->write(&byte, 1, vio->user_data);
}
else if (version == 6)
{
byte = (instrument->wave.length & 0xF);
vio->write(&byte, 1, vio->user_data);

byte = instrument->wave.speed - 1;
vio->write(&byte, 1, vio->user_data);
} else {
byte = 0;
vio->write(&byte, 1, vio->user_data); // Byte 10 is empty
vio->write(&byte, 1, vio->user_data); // Byte 11 is empty
}

byte = 0;
vio->write(&byte, 1, vio->user_data); // Byte 11 is empty
vio->write(&byte, 1, vio->user_data); // Byte 12 is empty
vio->write(&byte, 1, vio->user_data); // Byte 13 is empty

byte = (unsigned char)(((instrument->wave.length & 0xF) << 4) | (instrument->wave.speed & 0xF));
vio->write(&byte, 1, vio->user_data);
if (version < 6)
{
byte = (unsigned char)(((instrument->wave.length & 0xF) << 4) | ((instrument->wave.speed - 1) & 0xF));
vio->write(&byte, 1, vio->user_data);
} else {
byte = 0;
vio->write(&byte, 1, vio->user_data); // Byte 14 is empty
}

byte = 0;
vio->write(&byte, 1, vio->user_data); // Byte 15 is empty
Expand Down
6 changes: 3 additions & 3 deletions liblsdj/instrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ typedef enum
LSDJ_INSTR_NOISE
} instrument_type;

static const unsigned char LSDJ_NO_TABLE = 0x20;
static const unsigned char LSDJ_INSTRUMENT_UNLIMITED_LENGTH = 0x40;
static const unsigned char LSDJ_KIT_LENGTH_AUTO = 0x0;
#define LSDJ_NO_TABLE (0x20)
#define LSDJ_INSTRUMENT_UNLIMITED_LENGTH (0x40)
#define LSDJ_KIT_LENGTH_AUTO (0x0)

typedef struct lsdj_instrument_t lsdj_instrument_t;

Expand Down
16 changes: 8 additions & 8 deletions liblsdj/instrument_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ extern "C" {
#endif

typedef unsigned char lsdj_plvib_speed;
static const lsdj_plvib_speed LSDJ_PLVIB_FAST = 0;
static const lsdj_plvib_speed LSDJ_PLVIB_TICK = 1;
static const lsdj_plvib_speed LSDJ_PLVIB_STEP = 2;
#define LSDJ_PLVIB_FAST (0)
#define LSDJ_PLVIB_TICK (1)
#define LSDJ_PLVIB_STEP (2)

typedef unsigned char lsdj_vib_shape;
#define LSDJ_VIB_TRIANGLE 0
#define LSDJ_VIB_SAWTOOTH 1
#define LSDJ_VIB_SQUARE 2
#define LSDJ_VIB_TRIANGLE (0)
#define LSDJ_VIB_SAWTOOTH (1)
#define LSDJ_VIB_SQUARE (2)

typedef unsigned char lsdj_vib_direction;
static const lsdj_vib_direction LSDJ_VIB_UP = 0;
static const lsdj_vib_direction LSDJ_VIB_DOWN = 1;
#define LSDJ_VIB_UP (0)
#define LSDJ_VIB_DOWN (1)

#ifdef __cplusplus
}
Expand Down
20 changes: 10 additions & 10 deletions liblsdj/instrument_kit.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ extern "C" {
#include "instrument_constants.h"

typedef unsigned char lsdj_kit_loop_mode;
static const lsdj_kit_loop_mode LSDJ_KIT_LOOP_OFF = 0;
static const lsdj_kit_loop_mode LSDJ_KIT_LOOP_ON = 1;
static const lsdj_kit_loop_mode LSDJ_KIT_LOOP_ATTACK = 2;
#define LSDJ_KIT_LOOP_OFF (0)
#define LSDJ_KIT_LOOP_ON (1)
#define LSDJ_KIT_LOOP_ATTACK (2)

typedef unsigned char lsdj_kit_distortion;
static const lsdj_kit_distortion LSDJ_KIT_DIST_CLIP = 0xD0;
static const lsdj_kit_distortion LSDJ_KIT_DIST_SHAPE = 0xD1;
static const lsdj_kit_distortion LSDJ_KIT_DIST_SHAPE2 = 0xD2;
static const lsdj_kit_distortion LSDJ_KIT_DIST_WRAP = 0xD3;
#define LSDJ_KIT_DIST_CLIP (0xD0)
#define LSDJ_KIT_DIST_SHAPE (0xD1)
#define LSDJ_KIT_DIST_SHAPE2 (0xD2)
#define LSDJ_KIT_DIST_WRAP (0xD3)

typedef unsigned char lsdj_kit_pspeed;
static const lsdj_kit_pspeed LSDJ_KIT_PSPEED_FAST = 0;
static const lsdj_kit_pspeed LSDJ_KIT_PSPEED_SLOW = 1;
static const lsdj_kit_pspeed LSDJ_KIT_PSPEED_STEP = 2;
#define LSDJ_KIT_PSPEED_FAST (0)
#define LSDJ_KIT_PSPEED_SLOW (1)
#define LSDJ_KIT_PSPEED_STEP (2)

typedef struct
{
Expand Down
4 changes: 2 additions & 2 deletions liblsdj/instrument_noise.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ extern "C" {
#endif

typedef unsigned char lsdj_scommand_type;
static const lsdj_scommand_type LSDJ_SCOMMAND_FREE = 0;
static const lsdj_scommand_type LSDJ_SCOMMAND_STABLE = 1;
#define LSDJ_SCOMMAND_FREE (0)
#define LSDJ_SCOMMAND_STABLE (1)

typedef struct
{
Expand Down
8 changes: 4 additions & 4 deletions liblsdj/instrument_pulse.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ extern "C" {
#include "instrument_constants.h"

typedef unsigned char lsdj_pulse_wave;
static const lsdj_pulse_wave LSDJ_PULSE_WAVE_PW_125 = 0;
static const lsdj_pulse_wave LSDJ_PULSE_WAVE_PW_25 = 1;
static const lsdj_pulse_wave LSDJ_PULSE_WAVE_PW_50 = 2;
static const lsdj_pulse_wave LSDJ_PULSE_WAVE_PW_75 = 3;
#define LSDJ_PULSE_WAVE_PW_125 (0)
#define LSDJ_PULSE_WAVE_PW_25 (1)
#define LSDJ_PULSE_WAVE_PW_50 (2)
#define LSDJ_PULSE_WAVE_PW_75 (3)

typedef struct
{
Expand Down
8 changes: 4 additions & 4 deletions liblsdj/instrument_wave.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ extern "C" {
#include "instrument_constants.h"

typedef unsigned char lsdj_playback_mode;
static const lsdj_playback_mode LSDJ_PLAY_ONCE = 0;
static const lsdj_playback_mode LSDJ_PLAY_LOOP = 1;
static const lsdj_playback_mode LSDJ_PLAY_PING_PONG = 2;
static const lsdj_playback_mode LSDJ_PLAY_MANUAL = 3;
#define LSDJ_PLAY_ONCE (0)
#define LSDJ_PLAY_LOOP (1)
#define LSDJ_PLAY_PING_PONG (2)
#define LSDJ_PLAY_MANUAL (3)

typedef struct
{
Expand Down
8 changes: 4 additions & 4 deletions liblsdj/panning.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ extern "C" {
#endif

typedef unsigned char lsdj_panning;
static const lsdj_panning LSDJ_PAN_NONE = 0;
static const lsdj_panning LSDJ_PAN_RIGHT = 1;
static const lsdj_panning LSDJ_PAN_LEFT = 2;
static const lsdj_panning LSDJ_PAN_LEFT_RIGHT = 3;
#define LSDJ_PAN_NONE (0)
#define LSDJ_PAN_RIGHT (1)
#define LSDJ_PAN_LEFT (2)
#define LSDJ_PAN_LEFT_RIGHT (3)

#ifdef __cplusplus
}
Expand Down
4 changes: 2 additions & 2 deletions liblsdj/song.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ extern "C" {
#define LSDJ_BOOKMARK_POSITION_COUNT (16)
#define LSDJ_NO_BOOKMARK (0xFF)

static const unsigned char LSDJ_CLONE_DEEP = 0;
static const unsigned char LSDJ_CLONE_SLIM = 1;
#define LSDJ_CLONE_DEEP (0)
#define LSDJ_CLONE_SLIM (1)

// An LSDJ song
typedef struct lsdj_song_t lsdj_song_t;
Expand Down
26 changes: 13 additions & 13 deletions liblsdj/synth.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@
extern "C" {
#endif

static const unsigned char LSDJ_SYNTH_WAVEFORM_SAWTOOTH = 0;
static const unsigned char LSDJ_SYNTH_WAVEFORM_SQUARE = 1;
static const unsigned char LSDJ_SYNTH_WAVEFORM_TRIANGLE = 2;
#define LSDJ_SYNTH_WAVEFORM_SAWTOOTH (0)
#define LSDJ_SYNTH_WAVEFORM_SQUARE (1)
#define LSDJ_SYNTH_WAVEFORM_TRIANGLE (2)

static const unsigned char LSDJ_SYNTH_FILTER_LOW_PASS = 0;
static const unsigned char LSDJ_SYNTH_FILTER_HIGH_PASS = 1;
static const unsigned char LSDJ_SYNTH_FILTER_BAND_PASS = 2;
static const unsigned char LSDJ_SYNTH_FILTER_ALL_PASS = 3;
#define LSDJ_SYNTH_FILTER_LOW_PASS (0)
#define LSDJ_SYNTH_FILTER_HIGH_PASS (1)
#define LSDJ_SYNTH_FILTER_BAND_PASS (2)
#define LSDJ_SYNTH_FILTER_ALL_PASS (3)

static const unsigned char LSDJ_SYNTH_DISTORTION_CLIP = 0;
static const unsigned char LSDJ_SYNTH_DISTORTION_WRAP = 1;
static const unsigned char LSDJ_SYNTH_DISTORTION_FOLD = 2;
#define LSDJ_SYNTH_DISTORTION_CLIP (0)
#define LSDJ_SYNTH_DISTORTION_WRAP (1)
#define LSDJ_SYNTH_DISTORTION_FOLD (2)

static const unsigned char LSDJ_SYNTH_PHASE_NORMAL = 0;
static const unsigned char LSDJ_SYNTH_PHASE_RESYNC = 1;
static const unsigned char LSDJ_SYNTH_PHASE_RESYNC2 = 2;
#define LSDJ_SYNTH_PHASE_NORMAL (0)
#define LSDJ_SYNTH_PHASE_RESYNC (1)
#define LSDJ_SYNTH_PHASE_RESYNC2 (2)

// Structure representing soft synth data
typedef struct
Expand Down
6 changes: 5 additions & 1 deletion lsdsng_export/exporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,18 @@ namespace lsdj
{
switch (versionStyle)
{
case VersionStyle::NONE: break;
case VersionStyle::NONE:
std::cout << "\t\t";
break;
case VersionStyle::HEX:
std::cout << (lsdj_song_get_file_changed_flag(song) ? "*" : " ") << " \t";
break;
case VersionStyle::DECIMAL:
std::cout << (lsdj_song_get_file_changed_flag(song) ? "*" : " ") << " \t";
break;
}
} else {
std::cout << "\t\t";
}

// Display the format version of the song
Expand Down

0 comments on commit 8e26aa8

Please sign in to comment.