Skip to content

Commit

Permalink
mxj_safe: an extension to protect users and provide a reasonable user…
Browse files Browse the repository at this point in the history
… experience when java is not installed. it does not resolve the problems with having java8 and not java6 however. see #8.
  • Loading branch information
Timothy Place committed May 24, 2016
1 parent 005bfa6 commit 4272aaa
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*.x86_64
*.hex
externals
extensions

# Xcode User Data
project.xcworkspace
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "source/max-api"]
path = source/max-api
url = https://github.com/Cycling74/max-api.git
31 changes: 31 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,34 @@ else ()
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/source/mxj"
)
endif ()


if (APPLE)

######################################################################
message(STATUS "NOW WORKING ON THE SAFE WRAPPERS")
######################################################################


# Fetch the correct verion of the max-api
message(STATUS "Updating Git Submodules")
execute_process(
COMMAND git submodule update --init --recursive
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)


# Misc setup and subroutines
include(${CMAKE_CURRENT_SOURCE_DIR}/source/max-api/script/max-package.cmake)


# Generate a project for every folder in the "source/projects" folder
SUBDIRLIST(PROJECT_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/source/projects)
foreach (project_dir ${PROJECT_DIRS})
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/source/projects/${project_dir}/CMakeLists.txt")
message("Generating: ${project_dir}")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/source/projects/${project_dir})
endif ()
endforeach ()

endif() # APPLE
1 change: 1 addition & 0 deletions source/max-api
Submodule max-api added at fad1e2
19 changes: 19 additions & 0 deletions source/projects/mxj_safe/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.0)

set(C74_BUILD_MAX_EXTENSION TRUE)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../max-api/script/max-pretarget.cmake)


include_directories(
"${C74_INCLUDES}"
)


add_library(
${PROJECT_NAME}
MODULE
${PROJECT_NAME}.cpp
)


include(${CMAKE_CURRENT_SOURCE_DIR}/../../max-api/script/max-posttarget.cmake)
112 changes: 112 additions & 0 deletions source/projects/mxj_safe/mxj_safe.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright (c) 2016, Cycling '74
// Timothy Place
// Usage of this file and its contents is governed by the MIT License


#include "c74_msp.h"

using namespace c74::max;


#define DEFAULT_OS_ARCH "x86_64" // do we need to worry about 32-bit?
#include "../../mxj/JavaHomeOsx.c"
#include <dlfcn.h>
#include <string>


bool java_installed() {
char* baseDir = getJavaHome();

if (baseDir == nullptr || !strcmp(baseDir, "/"))
return false;
else
return true;
}


static t_class *mxj_class = nullptr;
static t_class *mxj_tilde_class = nullptr;



struct mxj_safe {
t_pxobject base;
};


mxj_safe* mxj_safe_new(t_symbol* name, long ac, t_atom* av) {
mxj_safe* self;

if (name == gensym("mxj~"))
self = (mxj_safe*)object_alloc(mxj_class);
else
self = (mxj_safe*)object_alloc(mxj_class);

object_error_obtrusive((t_object*)self, "Java is not installed on this computer. Please install it from https://support.apple.com/kb/DL1572?locale=en_US.");
return self;
}


void ext_main(void* r) {
if (java_installed()) {
// object_post(nullptr, "java is installed... nothing to see... please move along...");
}
else {
// object_error(nullptr, "java is not installed... defining dummies!");

auto c = class_new("mxj", (method)mxj_safe_new, nullptr, sizeof(mxj_safe), nullptr, A_GIMME, 0);
class_addmethod(c, (method)method_false, "int", A_LONG, 0);
class_addmethod(c, (method)method_false, "float", A_FLOAT, 0);
class_addmethod(c, (method)method_false, "bang", 0);
class_addmethod(c, (method)method_false, "list", A_GIMME, 0);
class_addmethod(c, (method)method_false, "anything", A_GIMME, 0);
class_addmethod(c, (method)method_false, "viewsource", A_GIMME, 0);
class_addmethod(c, (method)method_false, "zap", A_GIMME, 0);
class_addmethod(c, (method)method_false, "quickref",A_CANT,0);
class_addmethod(c, (method)method_false, "assist", A_CANT, 0);
class_addmethod(c, (method)method_false, "get", A_GIMME, 0);
class_addmethod(c, (method)method_false, "objectfilename", A_CANT, 0);
class_addmethod(c, (method)method_false, "save2", A_CANT, 0);
class_addmethod(c, (method)method_false, "loadbang",A_CANT,0);
class_addmethod(c, (method)method_false, "dblclick",A_CANT,0);
class_addmethod(c, (method)method_false, "fileusage", A_CANT, 0);
class_register(CLASS_BOX, c);
mxj_class = c;

object_method_direct(void, (t_object*, t_symbol*, t_symbol*, t_symbol*),
gensym("max")->s_thing, gensym("objectfile"), gensym("mxj"), gensym("mxj_safe"), gensym("mxj"));



c = class_new("mxj~", (method)mxj_safe_new, nullptr, sizeof(mxj_safe), nullptr, A_GIMME, 0);
class_dspinit(c);
class_addmethod(c, (method)method_false, "int", A_LONG, 0);
class_addmethod(c, (method)method_false, "float", A_FLOAT, 0);
class_addmethod(c, (method)method_false, "bang", 0);
class_addmethod(c, (method)method_false, "list", A_GIMME, 0);
class_addmethod(c, (method)method_false, "anything", A_GIMME, 0);
class_addmethod(c, (method)method_false, "viewsource", A_GIMME, 0);
class_addmethod(c, (method)method_false, "zap", A_GIMME, 0);
class_addmethod(c, (method)method_false, "quickref",A_CANT,0);
class_addmethod(c, (method)method_false, "assist", A_CANT, 0);
class_addmethod(c, (method)method_false, "get", A_GIMME, 0);
class_addmethod(c, (method)method_false, "objectfilename", A_CANT, 0);
class_addmethod(c, (method)method_false, "save2", A_CANT, 0);
class_addmethod(c, (method)method_false, "loadbang",A_CANT,0);
class_addmethod(c, (method)method_false, "dblclick",A_CANT,0);
class_addmethod(c, (method)method_false, "fileusage", A_CANT, 0);
//class_addmethod(c, (method)mxj_dsp64, "dsp64", A_CANT, 0);
//class_addmethod(c, (method)mxj_dspstate, "dspstate", A_CANT, 0);
//class_addmethod(c, (method)mxj_benchmark, "benchmark",A_DEFLONG,A_DEFLONG,0);
//class_addmethod(c, (method)mxj_exception_check, "exceptioncheck",A_DEFLONG,0);
class_register(CLASS_BOX, c);
mxj_tilde_class = c;

object_method_direct(void, (t_object*, t_symbol*, t_symbol*, t_symbol*),
gensym("max")->s_thing, gensym("objectfile"), gensym("mxj~"), gensym("mxj_safe"), gensym("mxj~"));


}
}


0 comments on commit 4272aaa

Please sign in to comment.