Skip to content

Commit

Permalink
Merge pull request #29 from stijnfrishert/develop
Browse files Browse the repository at this point in the history
v1.1.1
  • Loading branch information
stijnfrishert authored Aug 6, 2018
2 parents a0a2d5d + 0eec046 commit cf06e62
Show file tree
Hide file tree
Showing 39 changed files with 1,229 additions and 528 deletions.
76 changes: 76 additions & 0 deletions common/common.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
This file is a part of liblsdj, a C library for managing everything
that has to do with LSDJ, software for writing music (chiptune) with
your gameboy. For more information, see:
* https://github.com/stijnfrishert/liblsdj
* http://www.littlesounddj.com
--------------------------------------------------------------------------------
MIT License
Copyright (c) 2018 Stijn Frishert
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#include <iostream>

#include "common.hpp"

namespace lsdj
{
int handle_error(lsdj_error_t* error)
{
std::cerr << "ERROR: " << lsdj_error_get_c_str(error) << std::endl;
lsdj_error_free(error);
return 1;
}

bool compareCaseInsensitive(std::string str1, std::string str2)
{
std::transform(str1.begin(), str1.end(), str1.begin(), ::tolower);
std::transform(str2.begin(), str2.end(), str2.begin(), ::tolower);
return str1 == str2;
}

std::string constructProjectName(const lsdj_project_t* project, bool underscore)
{
char name[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
lsdj_project_get_name(project, name, sizeof(name));

if (underscore)
std::replace(name, name + 9, 'x', '_');

return name;
}

bool isHiddenFile(const std::string& str)
{
switch (str.size())
{
case 0: return true;
case 1: return false;
default: return str[0] == '.' && str[1] != '.' && str[1] != '/';
}
}
}
52 changes: 52 additions & 0 deletions common/common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
This file is a part of liblsdj, a C library for managing everything
that has to do with LSDJ, software for writing music (chiptune) with
your gameboy. For more information, see:
* https://github.com/stijnfrishert/liblsdj
* http://www.littlesounddj.com
--------------------------------------------------------------------------------
MIT License
Copyright (c) 2018 Stijn Frishert
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#ifndef LSDJ_COMMON_HPP
#define LSDJ_COMMON_HPP

#include <string>

#include "../liblsdj/error.h"
#include "../liblsdj/project.h"

namespace lsdj
{
int handle_error(lsdj_error_t* error);
bool compareCaseInsensitive(std::string str1, std::string str2);
std::string constructProjectName(const lsdj_project_t* project, bool underscore);
bool isHiddenFile(const std::string& str);
}

#endif
4 changes: 2 additions & 2 deletions liblsdj/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if (APPLE)
add_definitions(-Wall -Werror -Wconversion -Wno-unused-variable)
endif (APPLE)

set(HEADERS chain.h command.h compression.h error.h groove.h instrument.h instrument_constants.h instrument_kit.h instrument_noise.h instrument_pulse.h instrument_wave.h panning.h phrase.h project.h row.h sav.h song.h synth.h table.h vio.h wave.h word.h)
set(HEADERS chain.h channel.h command.h compression.h error.h groove.h instrument.h instrument_constants.h instrument_kit.h instrument_noise.h instrument_pulse.h instrument_wave.h panning.h phrase.h project.h row.h sav.h song.h synth.h table.h vio.h wave.h word.h)
set(SOURCES chain.c command.c compression.c error.c groove.c instrument.c phrase.c project.c row.c sav.c song.c synth.c table.c vio.c wave.c word.c)

# Create the library target
Expand All @@ -14,4 +14,4 @@ set_target_properties(liblsdj PROPERTIES OUTPUT_NAME lsdj)
source_group(\\ FILES ${HEADERS} ${SOURCES})

install(TARGETS liblsdj DESTINATION lib)
install(FILES command.h error.h instrument.h sav.h panning.h phrase.h project.h song.h table.h vio.h DESTINATION include/lsdj)
install(FILES chain.h channel.h command.h error.h groove.h instrument.h sav.h panning.h phrase.h project.h row.h song.h synth.h table.h wave.h word.h vio.h DESTINATION include/lsdj)
8 changes: 8 additions & 0 deletions liblsdj/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
#ifndef LSDJ_CHAIN_H
#define LSDJ_CHAIN_H

#ifdef __cplusplus
extern "C" {
#endif

#include "command.h"

// The length of a chain
Expand All @@ -56,5 +60,9 @@ lsdj_chain_t* lsdj_chain_copy(const lsdj_chain_t* chain);

// Clear chain data to factory settings
void lsdj_chain_clear(lsdj_chain_t* chain);

#ifdef __cplusplus
}
#endif

#endif
57 changes: 57 additions & 0 deletions liblsdj/channel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
This file is a part of liblsdj, a C library for managing everything
that has to do with LSDJ, software for writing music (chiptune) with
your gameboy. For more information, see:
* https://github.com/stijnfrishert/liblsdj
* http://www.littlesounddj.com
--------------------------------------------------------------------------------
MIT License
Copyright (c) 2018 Stijn Frishert
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#ifndef LSDJ_CHANNEL_H
#define LSDJ_CHANNEL_H

#ifdef __cplusplus
extern "C" {
#endif

typedef enum
{
LSDJ_PULSE1,
LSDJ_PULSE2,
LSDJ_WAVE,
LSDJ_NOISE,
} lsdj_channel_t;

#define LSDJ_CHANNEL_COUNT (4)

#ifdef __cplusplus
}
#endif

#endif
38 changes: 34 additions & 4 deletions liblsdj/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,40 @@
*/

#ifndef LSDJ_COMMAND_H
#define LSDJ_COMMAND_H
#ifndef LSDJ_COMMAND_H_GUARD
#define LSDJ_COMMAND_H_GUARD

#ifdef __cplusplus
extern "C" {
#endif

#include <stddef.h>
#include <stdio.h>

#define LSDJ_COMMAND_O (11)

#define LSDJ_COMMAND_NONE (0x00)
#define LSDJ_COMMAND_A (0x01)
#define LSDJ_COMMAND_C (0x02)
#define LSDJ_COMMAND_D (0x03)
#define LSDJ_COMMAND_E (0x04)
#define LSDJ_COMMAND_F (0x05)
#define LSDJ_COMMAND_G (0x06)
#define LSDJ_COMMAND_H (0x07)
#define LSDJ_COMMAND_K (0x08)
#define LSDJ_COMMAND_L (0x09)
#define LSDJ_COMMAND_M (0x0a)
#define LSDJ_COMMAND_O (0x0b)
#define LSDJ_COMMAND_P (0x0c)
#define LSDJ_COMMAND_R (0x0d)
#define LSDJ_COMMAND_S (0x0e)
#define LSDJ_COMMAND_T (0x0f)
#define LSDJ_COMMAND_V (0x10)
#define LSDJ_COMMAND_W (0x11)
#define LSDJ_COMMAND_Z (0x12)
#define LSDJ_COMMAND_ARDUINO_BOY_N (0x13)
#define LSDJ_COMMAND_ARDUINO_BOY_X (0x14)
#define LSDJ_COMMAND_ARDUINO_BOY_Q (0x15)
#define LSDJ_COMMAND_ARDUINO_BOY_Y (0x16)

// Structure representing an effect command with its argument value
typedef struct
{
Expand All @@ -50,5 +76,9 @@ typedef struct

// Clear the command to factory settings
void lsdj_command_clear(lsdj_command_t* command);

#ifdef __cplusplus
}
#endif

#endif
4 changes: 2 additions & 2 deletions liblsdj/compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif

#include "error.h"
#include "vio.h"
Expand All @@ -54,6 +54,6 @@ unsigned int lsdj_compress_to_file(const unsigned char* data, unsigned int block

#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif

#endif
8 changes: 8 additions & 0 deletions liblsdj/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
#ifndef LSDJ_ERROR_H
#define LSDJ_ERROR_H

#ifdef __cplusplus
extern "C" {
#endif

// Structure containing specific error details
typedef struct lsdj_error_t lsdj_error_t;

Expand All @@ -49,5 +53,9 @@ void lsdj_error_free(lsdj_error_t* error);

// Retrieve a string description of an error
const char* lsdj_error_get_c_str(lsdj_error_t* error);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions liblsdj/groove.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
#ifndef LSDJ_GROOVE_H
#define LSDJ_GROOVE_H

#ifdef __cplusplus
extern "C" {
#endif

// The default constant length of a groove
#define LSDJ_GROOVE_LENGTH (16)

Expand All @@ -48,4 +52,8 @@ typedef struct
// Clear all groove data to factory settings
void lsdj_groove_clear(lsdj_groove_t* groove);

#ifdef __cplusplus
}
#endif

#endif
Loading

0 comments on commit cf06e62

Please sign in to comment.