# Maintainer (arch): David Runge <dvzrv@archlinux.org>
# Contributor: Rob Til Freedmen <rob.til.freedman@gmail.com>
# Contributor: Ray Rashif <schiv@archlinux.org>
# Contributor: tobias <tobias@archlinux.org>
# Maintainer: Omar Vega Ramos <ovruni@gnu.org.pe>
# Contributor: André Silva <emulatorman@hyperbola.info>
# Contributor: bill-auger <bill-auger@programmer.net>


# parabola changes and rationale:
#  - Offer only freely-licensed drumkit downloads from parabola


pkgname=hydrogen
pkgver=1.1.1
pkgrel=2
pkgrel+=.parabola1
pkgdesc="An advanced drum machine"
arch=(x86_64)
arch+=(armv7h i686)
url="http://www.hydrogen-music.org/"
license=(GPL2)
groups=(pro-audio)
depends=(
  gcc-libs
  glibc
  hicolor-icon-theme
  qt5-base
  qt5-xmlpatterns
)
makedepends=(
  alsa-lib
  cmake
  jack
  ladspa
  libarchive
  liblo
  liblrdf
  libpulse
  libsndfile
  portaudio
  portmidi
  python
  qt5-tools
)
checkdepends=(cppunit)
optdepends=('new-session-manager: for session management')
source=(https://github.com/$pkgname-music/$pkgname/archive/$pkgver/$pkgname-$pkgver.tar.gz)
sha512sums=('c5e6bd713a0f9ef3b30bf0ae00bc41fea7494c20342c14c9f41ec05d1fdd3be721ffc3ff92bacd011e3b39a68022ea04daf55e60d334f64a00abef17d892cd37')
b2sums=('52f6f61fc6e247875688dcea2290d92eb7bc85910620f0adcb52506d587b02dcaec6e2ecb72c77cf4eb3134534c75fc64bc4dd76a63f886cc6ea07d9b8812089')


prepare() {
  # Offer only freely-licensed drumkits
  local sed_rx='s|hydrogen-music[.]org/feeds/drumkit_list[.]php|repo.parabola.nu/other/hydrogen-libre/feeds/drumkit_list.php|'
  for f in $(grep -rlI 'hydrogen-music[.]org/feeds/drumkit_list[.]php' $pkgname-$pkgver/)
  do  sed -i -e "${sed_rx}" ${f}
  done
}

build() {
  local cmake_options=(
    -B build
    -D CMAKE_INSTALL_PREFIX=/usr
    -D CMAKE_BUILD_TYPE=None
    -D WANT_DEBUG=OFF
    -D WANT_CPPUNIT=ON
    -D WANT_LRDF=ON
    -D WANT_PORTAUDIO=ON
    -D WANT_PORTMIDI=ON
    -D WANT_PULSEAUDIO=ON
    -S $pkgname-$pkgver
    -W no-dev
  )

  cmake "${cmake_options[@]}"
  cmake --build build --verbose
  # update translations
  (
    cd $pkgname-$pkgver/data/i18n
    ./updateTranslations.sh
  )
}

check() {
  ctest --test-dir build --output-on-failure
}

package() {
  depends+=(
    alsa-lib libasound.so
    jack libjack.so
    libarchive libarchive.so
    liblo liblo.so
    liblrdf liblrdf.so
    libpulse libpulse.so
    libsndfile libsndfile.so
    portaudio libportaudio.so
    portmidi libportmidi.so
  )

  DESTDIR="$pkgdir" cmake --install build
  install -vDm 644 $pkgname-$pkgver/{ChangeLog,DEVELOPERS,INSTALL.md,README.md} -t "$pkgdir/usr/share/doc/$pkgname/"
}

