Skip to content

Commit

Permalink
Add custom CMakeLists.txt file and do more replacing in code
Browse files Browse the repository at this point in the history
  • Loading branch information
sakertooth committed Sep 22, 2023
1 parent a9a597e commit 68de469
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 64 deletions.
46 changes: 3 additions & 43 deletions plugins/Sid/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,51 +1,11 @@
INCLUDE(BuildPlugin)

INCLUDE_DIRECTORIES(resid)
include_directories(resid/resid)
add_subdirectory(resid)

BUILD_PLUGIN(sid
SidInstrument.cpp
SidInstrument.h
resid/envelope.h
resid/extfilt.h
resid/filter.h
resid/pot.h
resid/siddefs.h
resid/sid.h
resid/spline.h
resid/voice.h
resid/wave.h
resid/envelope.cc
resid/extfilt.cc
resid/filter.cc
resid/pot.cc
resid/sid.cc
resid/version.cc
resid/voice.cc
resid/wave6581_PS_.cc
resid/wave6581_PST.cc
resid/wave6581_P_T.cc
resid/wave6581__ST.cc
resid/wave8580_PS_.cc
resid/wave8580_PST.cc
resid/wave8580_P_T.cc
resid/wave8580__ST.cc
resid/wave.cc
$<TARGET_OBJECTS:resid>
MOCFILES SidInstrument.h
EMBEDDED_RESOURCES *.png)

# Parse VERSION
FILE(READ "resid/CMakeLists.txt" lines)
STRING(REGEX MATCH "set\\(MAJOR_VER [A-Za-z0-9_]*\\)" MAJOR_RAW ${lines})
STRING(REGEX MATCH "set\\(MINOR_VER [A-Za-z0-9_]*\\)" MINOR_RAW ${lines})
STRING(REGEX MATCH "set\\(PATCH_VER [A-Za-z0-9_]*\\)" PATCH_RAW ${lines})
SEPARATE_ARGUMENTS(MAJOR_RAW)
SEPARATE_ARGUMENTS(MINOR_RAW)
SEPARATE_ARGUMENTS(PATCH_RAW)
LIST(GET MAJOR_RAW 1 MAJOR_RAW)
LIST(GET MINOR_RAW 1 MINOR_RAW)
LIST(GET PATCH_RAW 1 PATCH_RAW)
STRING(REPLACE ")" "" MAJOR_VER "${MAJOR_RAW}")
STRING(REPLACE ")" "" MINOR_VER "${MINOR_RAW}")
STRING(REPLACE ")" "" PATCH_VER "${PATCH_RAW}")

TARGET_COMPILE_DEFINITIONS(sid PRIVATE VERSION="${MAJOR_VER}.${MINOR_VER}.${PATCH_VER}")
24 changes: 12 additions & 12 deletions plugins/Sid/SidInstrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ f_cnt_t SidInstrument::desiredReleaseFrames() const



static int sid_fillbuffer(unsigned char* sidreg, SID *sid, int tdelta, short *ptr, int samples)
static int sid_fillbuffer(unsigned char* sidreg, reSID::SID *sid, int tdelta, short *ptr, int samples)
{
int tdelta2;
int result;
Expand Down Expand Up @@ -302,17 +302,17 @@ void SidInstrument::playNote( NotePlayHandle * _n,

if (!_n->m_pluginData)
{
SID *sid = new SID();
sid->set_sampling_parameters( clockrate, SAMPLE_FAST, samplerate );
sid->set_chip_model( MOS8580 );
auto sid = new reSID::SID();
sid->set_sampling_parameters(clockrate, reSID::SAMPLE_FAST, samplerate);
sid->set_chip_model(reSID::MOS8580);
sid->enable_filter( true );
sid->reset();
_n->m_pluginData = sid;
}
const fpp_t frames = _n->framesLeftForCurrentPeriod();
const f_cnt_t offset = _n->noteOffset();

SID *sid = static_cast<SID *>( _n->m_pluginData );
auto sid = static_cast<reSID::SID*>(_n->m_pluginData);
int delta_t = clockrate * frames / samplerate + 4;
// avoid variable length array for msvc compat
auto buf = reinterpret_cast<short*>(_working_buffer + offset);
Expand All @@ -325,20 +325,20 @@ void SidInstrument::playNote( NotePlayHandle * _n,

if( (ChipModel)m_chipModel.value() == ChipModel::MOS6581 )
{
sid->set_chip_model( MOS6581 );
sid->set_chip_model(reSID::MOS6581);
}
else
{
sid->set_chip_model( MOS8580 );
sid->set_chip_model(reSID::MOS8580);
}

// voices
reg8 data8 = 0;
reg8 data16 = 0;
reg8 base = 0;
reSID::reg8 data8 = 0;
reSID::reg8 data16 = 0;
reSID::reg8 base = 0;
float freq = 0.0;
float note = 0.0;
for( reg8 i = 0 ; i < 3 ; ++i )
for (reSID::reg8 i = 0; i < 3; ++i)
{
base = i*7;
// freq ( Fn = Fout / Fclk * 16777216 ) + coarse detuning
Expand Down Expand Up @@ -438,7 +438,7 @@ void SidInstrument::playNote( NotePlayHandle * _n,

void SidInstrument::deleteNotePluginData( NotePlayHandle * _n )
{
delete static_cast<SID *>( _n->m_pluginData );
delete static_cast<reSID::SID*>(_n->m_pluginData);
}


Expand Down
71 changes: 62 additions & 9 deletions plugins/Sid/resid/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,67 @@
add_library(resid OBJECT
resid/dac.cc
resid/envelope.cc
resid/extfilt.cc
resid/filter8580new.cc
resid/filter.cc
resid/pot.cc
add_library(resid OBJECT
resid/sid.cc
resid/voice.cc
resid/wave.cc
resid/envelope.cc
resid/filter8580new.cc
resid/dac.cc
resid/extfilt.cc
resid/pot.cc
resid/version.cc
)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/resid/siddefs.h.in ${CMAKE_CURRENT_SOURCE_DIR}/resid/siddefs.h @ONLY)
target_include_directories(resid PUBLIC resid)
target_include_directories(resid PUBLIC resid)

set(RESID_WAVE_DATA
wave6581_PST
wave6581_PS_
wave6581_P_T
wave6581__ST
wave8580_PST
wave8580_PS_
wave8580_P_T
wave8580__ST
)

find_package(Perl)
if(${PERL_FOUND})
set(RESID_SAMP2SRC_SCRIPT samp2src.pl)
foreach(WAVE_DATA ${RESID_WAVE_DATA})
add_custom_command(
OUTPUT
${CMAKE_CURRENT_SOURCE_DIR}/resid/${WAVE_DATA}.h
COMMAND
${PERL_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/resid/${RESID_SAMP2SRC_SCRIPT}
${CMAKE_CURRENT_SOURCE_DIR}/resid/${WAVE_DATA}
${CMAKE_CURRENT_SOURCE_DIR}/resid/${WAVE_DATA}.dat
${CMAKE_CURRENT_SOURCE_DIR}/resid/${WAVE_DATA}.h
VERBATIM
COMMENT "Generating resid wave data"
)
target_sources(resid PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/resid/${WAVE_DATA}.h)
endforeach()
else()
message(SEND_ERROR "Cannot build resid - Perl not found")
endif()

# These are the defaults
set(RESID_INLINING 1)
set(RESID_INLINE inline)
set(RESID_BRANCH_HINTS 1)
set(NEW_8580_FILTER 1)

check_cxx_source_compiles("int main() { bool flag; }" HAVE_BOOL)
check_cxx_source_compiles("int main() { __builtin_expect(0, 0); }" HAVE_BUILTIN_EXPECT)
check_cxx_source_compiles("#include <math.h> int main() { log1p(1); }" HAVE_LOG1P)

configure_file(resid/siddefs.h.in resid/siddefs.h @ONLY)
configure_file(resid/siddefs.h.in ${CMAKE_CURRENT_SOURCE_DIR}/resid/siddefs.h @ONLY)

# used the version from the previous submodule, this might not be accurate
set(SRC_VER 0.16)
set(MAJOR_VER 5)
set(MINOR_VER 0)
set(PATCH_VER 0)

target_compile_definitions(resid PUBLIC VERSION="${MAJOR_VER}.${MINOR_VER}.${PATCH_VER}")

0 comments on commit 68de469

Please sign in to comment.