Browse Source

tweak for ubuntu

palxex 7 years ago
parent
commit
3ca9be4dc0
4 changed files with 17 additions and 6 deletions
  1. 4 1
      midi.c
  2. 1 1
      unix/Makefile
  3. 11 4
      unix/native_midi.cpp
  4. 1 0
      unix/pal_config.h

+ 4 - 1
midi.c

@@ -32,6 +32,9 @@ MIDI_Play(
 )
 {
 #if PAL_HAS_NATIVEMIDI
+	if (!native_midi_detect() ) 
+		return;
+
 	if (native_midi_active(g_pMidi) && iNumRIX == g_iMidiCurrent)
 	{
 		return;
@@ -58,7 +61,7 @@ MIDI_Play(
 		uint8_t *buf = NULL;
 		int      size;
 
-		if (fp = UTIL_OpenFile("midi.mkf"))
+		if ((fp = UTIL_OpenFile("midi.mkf")) != NULL)
 		{
 			
 			if ((size = PAL_MKFGetChunkSize(iNumRIX, fp)) > 0 &&

+ 1 - 1
unix/Makefile

@@ -17,7 +17,7 @@ TEST_OBJFILES = $(TEST_CPPFILES:.cpp=.o)
 CCFLAGS = `sdl2-config --cflags` -g -Wall -O2 -fno-strict-aliasing -I. -I../ -I../liboggvorbis/include -I../liboggvorbis/src -DPAL_HAS_PLATFORM_SPECIFIC_UTILS $(TEST_CCFLAGS)
 CXXFLAGS = $(CCFLAGS) -std=c++11 `fltk-config --cxxflags`
 CFLAGS = $(CCFLAGS) -std=gnu99 `fltk-config --cflags`
-LDFLAGS = `sdl2-config --libs` `fltk-config --ldflags` -lstdc++ -lm
+LDFLAGS = `sdl2-config --libs` `fltk-config --ldflags` -lstdc++ -lm -pthread
 TEST_CXXFLAGS += -isystem $(GTEST_DIR)/include -I $(GTEST_DIR) -g -Wall -Wextra -pthread
 
 .PHONY : all clean check

+ 11 - 4
unix/native_midi.cpp

@@ -38,7 +38,8 @@ extern "C" int native_midi_detect()
         free(timidity);
         timidity = nullptr;
     }
-    if (system("timidity -v") == 0)
+    //system `timidity -v` will cause CLI blocked by the version info...
+    if (access("/usr/bin/timidity",F_OK) == 0)
     {
         timidity = strdup("/usr/bin/timidity");
         return 1;
@@ -86,6 +87,9 @@ extern "C" void native_midi_freesong(NativeMidiSong *song)
 {
     if (song)
     {
+	//stop it first to prevent app terminated by destructing joinable thread destruction 
+	if (native_midi_active(song)) 
+		native_midi_stop(song);
         if (song->file) delete []song->file;
         delete song;
     }
@@ -129,9 +133,12 @@ extern "C" void native_midi_stop(NativeMidiSong *song)
 	{
 		song->looping = false;
 		song->playing = false;
-        song->Mutex.lock();
-        kill(song->pid, SIGTERM);
-        song->Mutex.unlock();
+ 		if (-1 != song->pid)
+            	{
+			song->Mutex.lock();
+			kill(song->pid, SIGTERM);
+			song->Mutex.unlock();
+            	}
 		if (song->Thread.joinable())
 			song->Thread.join();
 		song->Thread = std::move(std::thread());

+ 1 - 0
unix/pal_config.h

@@ -56,5 +56,6 @@
 # define PAL_PORTYEAR         NULL
 
 # define PAL_HAS_CONFIG_PAGE  1
+# define PAL_HAS_NATIVEMIDI 1
 
 #endif