Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How exactly am I supposed to setup and use mx in a project? #117

Closed
kir12 opened this issue Jan 10, 2021 · 2 comments · Fixed by #118
Closed

How exactly am I supposed to setup and use mx in a project? #117

kir12 opened this issue Jan 10, 2021 · 2 comments · Fixed by #118

Comments

@kir12
Copy link

kir12 commented Jan 10, 2021

Forgive me for the noob-ish question, but I tried following the setup guidelines you posted in README.md and was unable to actually use the library in the same manner as you did in the examples. In particular I followed your build instructions --

git clone https://github.com/webern/mx.git mx
mkdir build
cd build
cmake ../mx -DMX_BUILD_TESTS=on -DMX_BUILD_CORE_TESTS=off -DMX_BUILD_EXAMPLES=on
make -j6
./mxtest

And I also turned off all the CMake build options I only needed the library.

In the very first example, you used the below dependencies, which I tried compiling: (as a bare minimum example)

#include "mx/api/DocumentManager.h"
#include "mx/api/ScoreData.h"

Unfortunately my compiler couldn't find either file (assuming that my own program code is supposed to reside outside of MX's codebase) so I tried specifying the direct path to both these files.

#include "/direct/path/to/mx/api/DocumentManager.h"
#include "/direct/path/to/mx/api/ScoreData.h"

The compiler was able to find both files, but they had internal relative references to other MX .h files, which the compiler also failed to find.

I'm 100% sure I'm doing something wrong, but I have no idea what it is. Any tips?

@webern
Copy link
Owner

webern commented Jan 10, 2021

I'll see if I can give an example of how to do this using mx from source 'in-tree'. If you want to 'install' it on your system and reference it that way, that's something I have less experience with. But I should be able to give you at least a minimal example of the 'in-tree' method, scripted.

@webern
Copy link
Owner

webern commented Jan 10, 2021

Does this help?

#!/bin/bash

# this script demonstrates how to depend on mx by including it in your sourcecode tree.

# the location where you want your new project
export REPO=/tmp/my-musicxml-proj

# create a new git repository for your project
rm -rf "${REPO}"
mkdir -p "${REPO}"
cd "${REPO}"
git init
# bring the mx sourcecode into your project
git clone https://github.com/webern/mx.git mx
# remove mx's .git directory and other things you don't need in your tree
rm -rf mx/.git mx/.circleci mx/.gitattributes mx/.github \
       mx/.idea mx/CodeGen mx/DevScripts mx/Documents mx/Resources \
       mx/build.sh mx/Xcode
git add --all && git commit --all -m'mx sourcecode'

# create a main.cpp file
cat <<- "EOF" > main.cpp
#include <iostream>
#include "mx/api/ScoreData.h"
#include "mx/api/DocumentManager.h"

int main () {
    using namespace mx::api;
    ScoreData score{};
    score.workTitle = "Hello World";
    NoteData note{};
    note.durationData.durationName = DurationName::quarter;
    note.pitchData.step = Step::d;
    VoiceData voiceData{};
    voiceData.notes.push_back(note);
    StaffData staff{};
    staff.voices[0] = voiceData;
    MeasureData measure{};
    measure.staves.push_back(staff);
    PartData part{};
    part.measures.push_back(measure);
    score.parts.push_back(part);
    auto& mgr = DocumentManager::getInstance();
    const auto id = mgr.createFromScore(score);
    mgr.writeToStream(id, std::cout);
    mgr.destroyDocument(id);
}
EOF

# create a cmake file
cat <<- "EOF" > CMakeLists.txt
cmake_minimum_required(VERSION 3.17)
project(my-musicxml-proj)
set(CMAKE_CXX_STANDARD 17)
set(CPP_VERSION 17)

add_executable(my-musicxml-proj main.cpp)
add_subdirectory(mx)
target_link_libraries(my-musicxml-proj mx)
target_include_directories(my-musicxml-proj PRIVATE mx/Sourcecode/include)
EOF

# create a .gitignore file to ignore a build directory
cat <<- "EOF" > .gitignore
build/
EOF

git add --all && git commit -m'musicxml hello world'

# create a build directory
mkdir build

# build your project
cd build
cmake .. && make -j10
# run your executable
./my-musicxml-proj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants