%define debug   off

# if 'make install' can install jman automatically
%define jman_install manual
%define org_name TiMidity++

Name:		TiMidity++4ALSA
Version:	2.13.2
Release:	9%{?_dist_release}

Summary:	A software wavetable MIDI synthesizer(for ALSA)
Summary(ja):  ソフトウェアMIDI音源シンセサイザー(for ALSA)
Group:		Applications/Multimedia
License:	GPLv2
URL:		http://timidity.sourceforge.net/

## Packager:	Hiroaki Irokawa <irorin@terra.dti.ne.jp>

Source: http://downloads.sourceforge.net/timidity/%{org_name}-%{version}.tar.bz2
Source1: timidity.desktop
## Source2: wishx.sh
Source2: timidity_add_text.txt
Source3: alsa2midi
Source4: timidity++.cfg
Source5: timidity.Sample.cfg

Vendor:		Project Vine
Distribution:	VineLinux

# FedoraCore patches
## Patch1: TiMidity++-2.13.0-detect.patch
## Patch2: TiMidity++-2.13.0-64bit.patch
## Patch3: TiMidity++-2.13.0-warnings.patch
## Patch4: TiMidity++-2.13.2-flac-detect.patch
## Patch5: TiMidity++-2.13.2-speex.patch
## Patch6: TiMidity++-2.13.2-libao-first.patch

## Patch21: TiMidity++-2.13.2-ipv6.patch
## Patch22: TiMidity++-2.13.2-dynlibroot.patch
## Patch23: TiMidity++-2.13.2-cfgfile-name.patch
## Patch24: TiMidity++-2.13.2-ipv6-fixes.patch
## Patch25: TiMidity++-2.13.2-missing-protos.patch

# The following patches are courtesy of Debian
## Patch10: TiMidity++-2.13.2-man-pages.patch
## Patch11: TiMidity++-2.13.2-misc-fixes.patch
## Patch12: TiMidity++-2.13.2-mlutil.patch
## Patch13: TiMidity++-2.13.2-flac.patch

# VineLinux -- irokawa patches 
## TiMidity++-iro.diff
# replase and others (babasaki)
## Patch10: TiMidity++-2.13.2-doc.patch
## Patch30: TiMidity++-2.13.2-interface.patch

## package rebuild patches
Patch1: TiMidity++_configure.patch
Patch2: TiMidity++_manual_C_ja.patch
Patch3: TiMidity++_interface.patch
Patch4: TiMidity++_lib.patch
Patch5: TiMidity++_timidity.patch
Patch6: TiMidity++_utils.patch

#--------------------------------------------------------------------

BuildRoot:  %{_tmppath}/%{org_name}-%{version}-root

BuildRequires: arts-devel, esound-devel, alsa-lib-devel, ncurses-devel, gtk2-devel
BuildRequires: libao-devel, libvorbis-devel, flac-devel, speex-devel
## BuildRequires: jack-audio-connection-kit-devel
BuildRequires: desktop-file-utils, emacs
## for ALSA
BuildRequires: glibc-kernheaders

BuildPreReq: esound-devel, libogg-devel, libvorbis-devel
BuildPreReq: Xaw3d-devel, gtk+-devel, tcl, tk

Requires: esound, libvorbis, libogg, XOrg-libs, audiofile
Requires: Xaw3d, gtk+, glib, tcl, tk, slang, alsa-utils
Requires: hicolor-icon-theme

Prereq : soundfont2

## _Conflicts_ : TiMidity++
Obsoletes: TiMidity++ <= %{version}
Provides:  TiMidity++
## =========================

#--------------------------------------------------------------------
%description

  TiMidity has originally been a converter that converts MIDI files to WAV
  audio file. But now TiMidity++ is not only a converter but also the
  real-time player that can play a MIDI file in real time. TiMidity does
  not requires external MIDI instrument module to play MIDI file, performs
  with software power.

  -Od8M -s11025 options will help you if bothered with noisy replay.

  TiMidity++ uses GUS/patch (Glavis Ultrasound) as the voice data to
  play.  You must get GUS/patch files, and make the configuration file.
  You must make the configuration file (*.cfg).  By default,
  timidity.cfg is /etc/timidity/timidity.cfg.
  Take care if you wanna upgrade from older version.

See "%{_defaultdocdir}/%{org_name}-%{version}/INSTALL" for futher information.

 * Now this package is beta version, so take care!

%description -l ja

TiMidity++ は、もともとは MIDI -> WAV コンバータでしたが、
今ではソフトウェア MIDI プレーヤとしての機能を持っています。
MIDI 演奏用のハードウェアは必要ありません。

CPU パワーの少ないマシンでは、-Od8M -s11025 オプションを
付けると音飛びが防げるでしょう。

TiMidity++のその他のオプションについてはドキュメントの収められている
ディレクトリの %{_defaultdocdir}/%{org_name}-%{version}/INSTALL.ja を読んで下さい。
=======================================================================
このパッケージは TiMidity++ を ALSA のためのMIDIポートにする機能を含みます。
root権限で /etc/init.d/alsa2midi status を確認してください。
(不要なら停止しても問題ありません。任意にはstart/stopで制御できます)

注:このパッケージはデスクトップ設定を含み、サウンドフォント(音色ファィル)
必須の構成になっています

※サウンドフォントについて

演奏するためには、サウンドフォント(*.pat または *.sf2)をインストール、
または入手し、timidity.cfg 設定ファイルを作成します。
設定ファイルは、
 /etc/timidity/timidity++.cfg
 /etc/timidity/timidity.cfg@ --> /etc/update-alternatives/timidity.cfg
……の順序で認識されますが、timidity++.cfg が存在すると timidity.cfg は
読み込まれません。そこで、source 文を使って timidity.cfg をインクルード
しています。
このパッケージにはサンプルの timidity.Sample.cfg が含まれ、
 /etc/timidity/timidity.cfg にリンクされています。
※soundfonts2を提供するパッケージが必ず先にインストールされるはずなので、
  update-alternativesのリストには出ますが、使用されません。

あくまで参考ですが、共通の起動時オプションを設定する場合は、
 timidity++.cfg に、サウンドフォントに固有の定義は timidity.cfg@ を
活用すると良いかと思います。( timidity++.cfg の文末に source文を忘れずに)

VineLinuxに用意した freepatsパッケージなどのサウンドフォントを使用する
場合には、root権限で timidity.cfg のサウンドフォント定義を切替えられる
ようにしています。

rootコマンド
  update-alternatives --config timidity.cfg

※他は追加情報(timidity_add_text.txt)をご覧下さい

#--------------------------------------------------------------------
## %patch1 -p1 -b .detect
# fix for x86_64 and s390x
## %patch2 -p1 -b .64bit
## %patch3 -p1 -b .warnings
## %patch6 -p1
## %patch10 -p1
## %patch11 -p1
## %patch12 -p1
## %patch13 -p1
## %patch21 -p1
## %patch22 -p1
## %patch23 -p1
## %patch24 -p1
## %patch25 -p1
## %patch30 -p1
#--------------------------------------------------------------------
%prep
%setup -q -n %{org_name}-%{version}

%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1

%build
if [ %{debug} = "on" ] ; then
  export CFLAGS="$RPM_OPT_FLAGS -g"
else
  export CFLAGS="$RPM_OPT_FLAGS"
fi
## SEED 2008-08-18現在で flac オプションでエラーが出る対応
if [ %{?_dist_release} = "vl5" ] ; then
  export ENABLE_AUDIO="oss,alsa,arts,esd,ao,vorbis,speex"
else
  export ENABLE_AUDIO="oss,alsa,arts,esd,ao,vorbis,speex,flac"
fi


./configure \
  --prefix=%{_prefix} \
  --with-elf \
  --with-default-output=default \
  --with-x \
  --x-includes=/usr/include --x-libraries=/usr/X11R6/lib \
  --disable-dependency-tracking \
  --enable-dynamic= \
  --enable-interface=ncurses,slang,tcltk,emacs,vt100,xskin,gtk,server,alsaseq,network,spectrogram \
  --enable-audio=${ENABLE_AUDIO}
## --enable-audio=oss,alsa,arts,esd,ao,vorbis,speex,flac
## remove ,xaw

make
##make %{?_smp_mflags}

#--------------------------------------------------------------------
%install

rm -rf $RPM_BUILD_ROOT

## mkdir -p $RPM_BUILD_ROOT%{_libdir}
make prefix=$RPM_BUILD_ROOT%{_prefix} install

mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/timidity/
install %{SOURCE4} %{SOURCE5} $RPM_BUILD_ROOT/%{_sysconfdir}/timidity/

# Manual
if [ %{jman_install} = "manual" ]; then

  # install Japanese manual
  mkdir -p $RPM_BUILD_ROOT%{_mandir}/ja/{man1,man5}
  install -m644 doc/ja_JP.eucJP/timidity.1 $RPM_BUILD_ROOT%{_mandir}/ja/man1/
  install -m644 doc/ja_JP.eucJP/timidity.cfg.5 $RPM_BUILD_ROOT%{_mandir}/ja/man5/
  mkdir -p $RPM_BUILD_ROOT%{_defaultdocdir}/%{org_name}-%{version}/ja_JP.eucJP/
  install -m644 doc/ja_JP.eucJP/README.* $RPM_BUILD_ROOT%{_defaultdocdir}/%{org_name}-%{version}/ja_JP.eucJP/

  # install English manual
  mkdir -p $RPM_BUILD_ROOT%{_mandir}/{man1,man5}
  install -m644 doc/C/timidity.1 $RPM_BUILD_ROOT%{_mandir}/man1/
  install -m644 doc/C/timidity.cfg.5 $RPM_BUILD_ROOT%{_mandir}/man5/
  mkdir -p $RPM_BUILD_ROOT%{_defaultdocdir}/%{org_name}-%{version}/C/
  install -m644 doc/C/README.* $RPM_BUILD_ROOT%{_defaultdocdir}/%{org_name}-%{version}/C/
  install -m644 doc/C/CHANGES.02i $RPM_BUILD_ROOT%{_defaultdocdir}/%{org_name}-%{version}/C/
  install -m644 doc/C/FAQ $RPM_BUILD_ROOT%{_defaultdocdir}/%{org_name}-%{version}/C/

fi

# add Documents
install -m644 doc/ja_JP.eucJP/README.* $RPM_BUILD_ROOT%{_defaultdocdir}/%{org_name}-%{version}/ja_JP.eucJP/
install -m644 doc/C/README.* doc/C/CHANGES.02i doc/C/FAQ $RPM_BUILD_ROOT%{_defaultdocdir}/%{org_name}-%{version}/C/
## cp -p interface/interface*.txt interface/timidity.el $RPM_BUILD_ROOT%{_libdir}/timidity
cp -p interface/interface*.txt interface/timidity.el $RPM_BUILD_ROOT%{_prefix}/lib/timidity
install -m644 interface/timidity.el $RPM_BUILD_ROOT%{_defaultdocdir}/%{org_name}-%{version}
install -m644 AUTHORS COPYING NEWS TODO $RPM_BUILD_ROOT%{_defaultdocdir}/%{org_name}-%{version}
install -m644 ChangeLog* INSTALL* README*  $RPM_BUILD_ROOT%{_defaultdocdir}/%{org_name}-%{version}

# install GNOME desktop
mkdir -p $RPM_BUILD_ROOT%{_datadir}/applications
desktop-file-install --vendor VineLinux              \
  --dir ${RPM_BUILD_ROOT}%{_datadir}/applications \
  %{SOURCE1}

# install icon.
mkdir -p $RPM_BUILD_ROOT%{_datadir}/icons/hicolor/48x48/apps
install -p -m 644 interface/pixmaps/timidity.xpm \
  $RPM_BUILD_ROOT%{_datadir}/icons/hicolor/48x48/apps/timidity.xpm

mkdir -p $RPM_BUILD_ROOT%{_sharedstatedir}/pixmaps/timidity/
install -p interface/pixmaps/*.xpm $RPM_BUILD_ROOT%{_sharedstatedir}/pixmaps/timidity/

# make symlink for Window Maker
cd $RPM_BUILD_ROOT%{_sharedstatedir}/pixmaps/
ln -s timidity/timidity.xpm .

# make wishx for tcl/tk timidity
# mkdir -p $RPM_BUILD_ROOT/usr/local/bin/
# cp -p %{SOURCE2} $RPM_BUILD_ROOT/usr/local/bin/wishx

# MIDI port init.d for ALSA
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/init.d/
install %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/init.d/

# add text
install %{SOURCE2} $RPM_BUILD_ROOT%{_defaultdocdir}/%{org_name}-%{version}/ja_JP.eucJP/
rm -rf $RPM_BUILD_ROOT/usr/man


%clean
rm -rf $RPM_BUILD_ROOT
#--------------------------------------------------------------------
%post
# update icon themes
touch --no-create %{_datadir}/icons/hicolor || :
if [ -x %{_bindir}/gtk-update-icon-cache ]; then
   %{_bindir}/gtk-update-icon-cache --quiet %{_datadir}/icons/hicolor || :
fi
if [ $1 = 1 ]; then
/sbin/chkconfig --add alsa2midi
/sbin/chkconfig --level 35 alsa2midi on
/sbin/service alsa2midi start &>/dev/null || :
fi
# update-alternatives
/sbin/update-alternatives --install \
  %{_sysconfdir}/timidity/timidity.cfg timidity.cfg \
  %{_sysconfdir}/timidity/timidity.Sample.cfg 1 \

%preun
# update-alternatives
if [ "$1" = "0" ]; then
  /sbin/update-alternatives --remove \
  timidity.cfg %{_sysconfdir}/timidity/timidity.Sample.cfg
fi

%postun
# update icon themes
touch --no-create %{_datadir}/icons/hicolor || :
if [ -x %{_bindir}/gtk-update-icon-cache ]; then
   %{_bindir}/gtk-update-icon-cache --quiet %{_datadir}/icons/hicolor || :
fi


#--------------------------------------------------------------------
%files
%defattr(-,root,root)
## %doc AUTHORS COPYING README README.ja NEWS ChangeLog INSTALL INSTALL.ja
## %doc doc/*
%{_defaultdocdir}/%{org_name}-%{version}/*
%config(noreplace) %{_sysconfdir}/timidity/timidity*.cfg
%{_mandir}/*
## %{_mandir}/ja/man1/timidity.1*
## %{_mandir}/ja/man5/timidity.cfg.5*
## %{_mandir}/man1/timidity.1*
## %{_mandir}/man5/timidity.cfg.5*
%{_bindir}/*
%{_sysconfdir}/init.d/*
## /usr/local/bin/wishx
/usr/share/emacs/site-lisp/timidity.el
%{_datadir}/pixmaps/timidity.xpm
%{_datadir}/pixmaps/timidity/*.xpm
%{_datadir}/applications/VineLinux-timidity.desktop
%{_datadir}/icons/hicolor/48x48/apps/timidity.xpm

## if you faced on an error to rebuild or run, please uncomment below.
## maybe for Tcl/Tk, xaw, xskin and gtk...

## %{_libdir}/timidity/*
%{_prefix}/lib/timidity/*
#--------------------------------------------------------------------
%changelog

* Thu Aug 18 2008 Seiichirou Babasaki 2.13.2-9
- Updated specfile
- included "Shu KONNO" x86_64 changes.

* Sat Aug 09 2008 Shu KONNO <owa@bg.wakwak.com> 2.13.2-8 (x86_64)
- changed %%{_libdir}/timidity to %%{_prefix}/lib/timidity

* Thu Jul 1 2008 Seiichirou Babasaki 2.13.2-8
- Updated specfile
- "Obsoletes:" and "Provides:" option
- Updated  timidity_add_text.txt

* Wed Jun 11 2008 Seiichirou Babasaki 2.13.2-7
- Updated specfile
- Remove "flac" optin (Seed)
- Build Requires : Emacs

* Fri May 23 2008 Seiichirou Babasaki 2.13.2-6
- Updated specfile
- Packgage rename (TiMidity++ to TiMidity++4ALSA)
- remove wishx.sh

* Fri May 9 2008 Seiichirou Babasaki 2.13.2-5
- Updated specfile
- add  timidity++.cfg, dummy-cfg-file

* Fri May 2 2008 Seiichirou Babasaki 2.13.2-4
- Updated specfile
- add alsa2midi /etc/init.d/ file
- "update-alternatives" (Mandriva idea) 

* Fri Apr 18 2008 Seiichirou Babasaki 2.13.2-3
- Updated specfile ( marge Seed-2.13.1)

* Thu Apr 17 2008 Seiichirou Babasaki 2.13.2-2
- Updated specfile ( soundable, gtk+ & tcltk interface )

* Wed Apr 16 2008 Seiichirou Babasaki 2.13.2-1
- Update source - Babasaki
- Updated specfile (import FC9 )

#--------------------------------------------------------------------
* Thu Jul 27 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.13.0-0vl2
- rebuilt with Xaw3d-1.5-17vl3
- s/Copyright/License/
- changed Group to Applications/Multimedia 
- updated build dependancy

* Fri Apr 30 2004 Hiroaki Irokawa <irorin@terra.dti.ne.jp>
- update

* Fri Aug 16 2002 Hiroaki Irokawa <irorin@terra.dti.ne.jp> 2.11.3-0vl4
- fix typo (ncurces -> ncurses) thanks Mr. Mickey_U

* Fri Jul 26 2002 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 2.11.3-0vl3
- rebuilt with libvorbis-1.0

* Thu Feb 14 2002 Hiroaki Irokawa <irorin@terra.dti.ne.jp>
- [TiMidity++-2.11.3-0vl2]
- fix %defattr
- Add Requires: XFree86-libs, audiofile, Xaw3d, gtk+, glib, tcl, tk, lesstif, slang

* Fri Jan 18 2002 Hiroaki Irokawa <irorin@terra.dti.ne.jp>
- [TiMidity++-2.11.3-0vl1]
- update.

* Mon Jan 14 2002 Hiroaki Irokawa <irorin@terra.dti.ne.jp>
- [TiMidity++-2.11.2-0vl2]
- Add Requires:	libvorbis, libogg
- Add BuildPreReq: libogg-devel, libvorbis-devel

* Sat Jan 12 2002 Hiroaki Irokawa <irorin@terra.dti.ne.jp>
- [TiMidity++-2.11.2-0vl1]
- update.

* Mon Dec 31 2001 Hiroaki Irokawa <irorin@terra.dti.ne.jp>
- [TiMidity++-2.11.1-0vl1]
- update.

* Thu Dec 27 2001 Hiroaki Irokawa <irorin@terra.dti.ne.jp>
- [TiMidity++-2.11.0-0vl1]
- update.

* Thu Nov 22 2001 Hiroaki Irokawa <irorin@terra.dti.ne.jp>
- [TiMidity++-2.10.4-0vl2]
- Rebuilt(About Tcl/Tk).

* Mon Mar 19 2001 Hiroaki Irokawa <irorin@terra.dti.ne.jp>
  [TiMidity++-2.10.4-0vl1]
- Updated to 2.10.4.

* Sun Mar 11 2001 Hiroaki Irokawa <irorin@terra.dti.ne.jp>
  [TiMidity++-2.10.3-0vl1]
- Updated to 2.10.3.

* Sat Mar 03 2001 MATSUBAYASHI 'Shaolin' Kohji <shaolin@vinelinux.org>
- 2.10.2-0vl3
- always require esound
- disable alsa in case alsa driver/library is not installed

* Thu Jan 13 2001 Hiroaki Irokawa <irorin@terra.dti.ne.jp>
  [TiMidity++-2.10.2-0vl2]
- Use some rpmmacros, Modified Compile Option & man5 data, tcl path.

* Thu Nov  2 2000 Hiroaki Irokawa <irorin@terra.dti.ne.jp>
  [TiMidity++-2.10.2-0vl1]
- Updated to 2.10.2.

* Sat Oct 18 2000 Hiroaki Irokawa <irorin@terra.dti.ne.jp>
  [TiMidity++-2.10.1-0vl1]
- Updated to 2.10.1.

* Sat Sep 16 2000 Hiroaki Irokawa <irorin@terra.dti.ne.jp>
  [TiMidity++-2.10.0-0vl3]
- Updated to 2.10.0.(rebuild without alsa-lib)

* Sat Sep  9 2000 Hiroaki Irokawa <irorin@terra.dti.ne.jp>
  [TiMidity++-2.10.0-0vl2]
- Updated to 2.10.0.(ja_JP.ujis -> ja)

* Wed Sep  6 2000 Hiroaki Irokawa <irorin@terra.dti.ne.jp>
  [TiMidity++-2.10.0-0vl1]
- Updated to 2.10.0.

* Wed Oct  6 1999 Yasuhide OOMORI <dasen@typhoon.co.jp>
  [TiMidity++-2.6.1-1]
- Updated to 2.6.1.

* Fri Sep 23 1999 Yasuhide OOMORI <dasen@typhoon.co.jp>
  [TiMidity++-2.6.0-1]
- Updated to the full release of version 2.6.0.
- Include pixmaps.
- Make symlink for Window Maker.

* Fri Sep 11 1999 Yasuhide OOMORI <dasen@typhoon.co.jp>
  [TiMidity++-2.6.0-0.4.0]
- Updated to the 4th (maybe last?) beta release of version 2.6.0.

* Fri Sep 11 1999 Yasuhide OOMORI <dasen@typhoon.co.jp>
  [TiMidity++-2.6.0-0.3.1]
- Enabled all the interfaces.

* Fri Sep 11 1999 Yasuhide OOMORI <dasen@typhoon.co.jp>
  [TiMidity++-2.6.0-0.3.0]
- Updated to the 3rd beta release of version 2.6.0.
- Added TiMidity.ad, TiMidity-uj.ad to install documents.

* Fri Sep 03 1999 Yasuhide OOMORI <dasen@typhoon.co.jp>
  [TiMidity++-2.6.0-0.2.2]
- Updated to the 2nd beta release of version 2.6.0.

* Mon Aug 23 1999 Yasuhide OOMORI <dasen@typhoon.co.jp>
  [TiMidity++-2.5.0-1]
- Updated to full release of version 2.5.0.
- Modified to install Japanese manuals.

* Mon Aug 23 1999 Yasuhide OOMORI <dasen@typhoon.co.jp>
  [TiMidity++-2.4.1-1]
- First attempt.
