Skip to content

Commit

Permalink
debugging....
Browse files Browse the repository at this point in the history
  • Loading branch information
newdigate committed Oct 6, 2024
1 parent 6965351 commit 5d1c327
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 35 deletions.
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ if (NOT DEFINED BUILD_FOR_LINUX)
add_subdirectory(examples)
else()
set(CMAKE_CXX_STANDARD 14)
find_library(teensy_x86_stubs NAME teensy_x86_stubs)
find_library(teensy_x86_sd_stubs NAME teensy_x86_sd_stubs)
include(cmake_declare_and_fetch.cmake.in)
DeclareAndFetch(teensy_x86_stubs git@github.com:/newdigate/teensy-x86-stubs.git feature/shared_serial src)
DeclareAndFetch(teensy_x86_sd_stubs git@github.com:/newdigate/teensy-x86-sd-stubs.git noinstall src)
add_subdirectory(src)
if(DEFINED BUILD_EXAMPLES)
add_subdirectory(examples)
endif ()
#add_subdirectory(test)
endif()
7 changes: 7 additions & 0 deletions cmake_declare_and_fetch.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include(FetchContent)
FetchContent_Declare(cmake_declare_and_fetch
GIT_REPOSITORY https://github.com/newdigate/cmake-declare-and-fetch.git
GIT_TAG main
)
FetchContent_MakeAvailable(cmake_declare_and_fetch)
include("${FETCHCONTENT_BASE_DIR}/cmake_declare_and_fetch-src/DeclareAndFetchCMake.in")
14 changes: 10 additions & 4 deletions examples/basic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
cmake_minimum_required(VERSION 3.10)
project(basic)
teensy_include_directories(../../src)
teensy_add_executable(basic midiread.ino)
teensy_target_link_libraries(basic midi_smf_writer SD SdFat SPI cores)
target_link_libraries(basic.elf stdc++)
if (NOT DEFINED BUILD_FOR_LINUX)
teensy_include_directories(../../src)
teensy_add_executable(basic midiread.cpp)
teensy_target_link_libraries(basic midi_smf_writer SD SdFat SPI cores)
target_link_libraries(basic.elf stdc++)
else ()
include_directories(../../src)
add_executable(basic midiread.cpp)
target_link_libraries(basic midi_smf_writer teensy_x86_sd_stubs teensy_x86_stubs)
endif ()
26 changes: 26 additions & 0 deletions examples/basic/midiread.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <Arduino.h>
#include "smfwriter.h"

void setup() {
SmfWriter writer;
writer.setFilename("test");
writer.writeHeader();
writer.addSetTempo(0, 120.0);
double microsPerTick = writer.get_microseconds_per_tick(120.0);

writer.addNoteOnEvent(0, 0, 64, 127);
writer.addNoteOnEvent(480, 0, 64, 127 );
writer.flush();
}

void loop() {

}

//#ifdef BUILD_FOR_LINUX
int main(int, char**) {
SD.setSDCardFolderPath("/Users/moolet/Development/github/newdigate/midi-smf-writer/cmake-build-debug");
setup();
//while(true) loop();
}
//#endif
18 changes: 0 additions & 18 deletions examples/basic/midiread.ino

This file was deleted.

2 changes: 2 additions & 0 deletions git-status-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
find ./cmake-build-debug/_deps -name "*-src" -maxdepth 1 -mindepth 1 -type d -exec sh -c '(echo {} && cd {} && git status -s && echo)' \;
36 changes: 25 additions & 11 deletions src/smfwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,31 +253,45 @@ int SmfWriter::flushWithErrorHandling() {
_bytesWritten += dataWrittenSize;
data.close();

if (dataWrittenSize != _bufferPos) {
return 2;
}

_bufferPos = 0;
bool errorWhenOpening = false;
if (trackSize > 0) {
// go back and update the 0'th midi track length
data = SD.open(_filename, O_READ | O_WRITE);
#ifdef BUILD_FOR_LINUX
data = SD.open(_filename, O_READ | O_WRITE);
#else
data = SD.open(_filename, O_WRITE);
#endif

if(!data) {
errorWhenOpening = true;
Serial.print("Failed to update length");
} else {
data.seek(18);

write_buf_int(trackSize);
Serial.print("TrackSize ");
Serial.println(trackSize);

data.write(_buffer, _bufferPos);
Serial.print("_bufferPos ");
Serial.println(_bufferPos);
_bufferPos = 0;
data.close();
}
data.seek(18);

write_buf_int(trackSize);
data.write(_buffer, _bufferPos);
_bufferPos = 0;
data.close();
}

if (dataWrittenSize != _bufferPos) {
return 2;
}


if (errorWhenOpening) {
return 3;
}

return true;
return 0;
}

void SmfWriter::flush() {
Expand Down

0 comments on commit 5d1c327

Please sign in to comment.