# Maintainer: Fabrizio del Tin <fdt@euniversity.pub>
# Contributor: Yan Burdinsky
# Contributor: Ainola
# Contributor: speps
# Contributor: Bernardo Barros
pkgname=muse
pkgver=3.0.2
pkgrel=1
pkgdesc="A MIDI/Audio sequencer with recording and editing capabilities"
arch=('i686' 'x86_64')
url="http://muse-sequencer.org/"
license=('GPL2')
depends=('qt5-base' 'fluidsynth' 'liblo' 'gtkmm' 'lib32-gtk2' 
'gcc-libs-multilib' 'jack2' 'rtaudio')
makedepends=('cmake' 'gcc' 'ladspa' 'lv2' 'dssi' 
'dssi-vst' 'ladish' 'liblo' 'qt5-tools')
optdepends=(
    'python2: Python scripting'
    'python2-pyqt5: Python scripting'
    'ladspa: ladspa plugin support'
    'lv2: lv2 plugin support'
    'dssi: dssi plugin support'
    'dssi-vst: dssi-vst plugins support'
    'ladish: LASH session support'
)
install="${pkgname}.install"
provides=('muse')
conflicts=('muse')
source=("https://sourceforge.net/projects/lmuse/files/muse-3.0/muse-${pkgver}.tar.gz")
sha256sums=('49326fce7b2aecbc4b6f70b86cc5e502d3d8c8872f5f3583a9fe945865d6372e')

build() {
  cd "${srcdir}/muse-${pkgver}/"

  sed -i '1s/^/#include <QButtonGroup>\n\n/' muse/widgets/genset.cpp
  sed -i '1s/^/#include <QAction>\n\n/' muse/mplugins/mitplugin.cpp
  sed -i 's/PyInt_AsLong/PyLong_AsLong/g' muse/remote/pyapi.cpp
  sed -i 's/PyString_AsString/PyBytes_AsString/g' muse/remote/pyapi.cpp
  sed -i 's/static void\* pyapithreadfunc(void\*)/static struct PyModuleDef muse =\n{\n    PyModuleDef_HEAD_INIT,\n    "muse", \/\* name of module \*\/\n    "",          \/\* module documentation, may be NULL \*\/\n    -1,          \/\* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. \*\/\n    g_methodDefinitions\n};\n\nstatic void\* pyapithreadfunc(void\*)/' muse/remote/pyapi.cpp
  sed -i 's/Py_InitModule( "muse", g_methodDefinitions );/PyModule_Create( \&muse );/' muse/remote/pyapi.cpp

  # build dir
  [ -d bld ] || mkdir bld && cd bld

  cmake -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMAKE_BUILD_TYPE=release \
        -DENABLE_VST_VESTIGE=1 \
        -DENABLE_VST_NATIVE=1 \
        -DENABLE_LV2=1 \
        -DENABLE_PYTHON=1 \
        -DENABLE_FLUID=1 \
        -DENABLE_DSSI=1 \
        -DENABLE_LASH=1 \
        -DENABLE_OSC=1 \
        -DENABLE_RTAUDIO=1 ..
  make
#        -DCMAKE_CXX_COMPILER=/usr/bin/c++ \
#        -DCMAKE_CXX_COMPILER_AR=/usr/bin/gcc-ar \
#        -DCMAKE_CXX_COMPILER_RANLIB=/usr/bin/gcc-ranlib \
#        -DCMAKE_C_COMPILER=/usr/bin/cc \
#        -DCMAKE_C_COMPILER_AR=/usr/bin/gcc-ar \
#        -DCMAKE_C_COMPILER_RANLIB=/usr/bin/gcc-ranlib \
#        -DPYTHON_INCLUDE_DIR=/usr/include/python2.7 \
#        -DPYTHON_LIBRARY=/usr/lib/libpython2.7.so \
}

package() {
  cd "$srcdir/muse-${pkgver}/bld"
  make DESTDIR="$pkgdir" install

  # .. and oomidi grepmidi bin
  cd "$pkgdir/usr/bin"
  mv grepmidi "$pkgname-grepmidi"

  # grepmidi man
  cd "$pkgdir/usr/share/man/man1"
  mv grepmidi.1 "$pkgname-grepmidi.1"

  # python2 Fixes
#  sed -i "s/\#\!.*python/&2/" \
#    `grep -rl "\#\!.*python" "$pkgdir"`
}
sha256sums=('c9efddb901632ce7acfb163e319a56eae27b841dc30dd19d417bbc14a9d1b748')
