%define debug   off
%define org_name TiMidity++

Name:		TiMidity++4ALSA
Version:	2.14.0
Release:	3%{?_dist_release}

Summary:	A software wavetable MIDI synthesizer (for ALSA)
Summary(ja):	ソフトウェアMIDI音源シンセサイザー (for ALSA)

License:	GPLv2
Group:		Applications/Multimedia
URL:		http://timidity.sourceforge.net/

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

# 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
Patch10: TiMidity++_tcltk.patch

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

BuildRequires: 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
BuildRequires: tcl-devel tk-devel
BuildRequires: libuuid-devel
## for ALSA
#BuildRequires: glibc-kernheaders

#BuildRequires: libogg-devel, libvorbis-devel
#BuildRequires: Xaw3d-devel, gtk+-devel, tcl, tk

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

Requires(pre):  soundfont2
Requires(post): /sbin/chkconfig, /sbin/service, /sbin/update-alternatives
Requires(preun): /sbin/chkconfig, /sbin/service, /sbin/update-alternatives
    
## _Conflicts_ : TiMidity++
Obsoletes: TiMidity++ < %{version}-%{release}
Provides:  TiMidity++ = %{version}-%{release}
## =========================

Vendor:		Project Vine
Distribution:	Vine Linux
## Packager:	Hiroaki Irokawa <irorin@terra.dti.ne.jp>

#--------------------------------------------------------------------
%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.

%description -l ja

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

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

=======================================================================
このパッケージは 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)をご覧下さい

#--------------------------------------------------------------------
%prep
%setup -q -n %{org_name}-%{version}
#patch1 -p1
#patch2 -p1
#patch3 -p1
#patch4 -p1
#patch5 -p1
#patch6 -p1
#patch10 -p1

cp -p %{SOURCE2} .
iconv -f euc-jp -t utf8 README.ja > README.ja.utf8
mv README.ja.utf8 README.ja

%build
export EXTRACFLAGS="$RPM_OPT_FLAGS -DCONFIG_FILE=\\\"/etc/timidity++.cfg\\\""
# Note the first argument to --enable-audio is the default output, and
# we use libao to get pulse output
%configure \
    --disable-dependency-tracking \
    --with-module-dir=%{_libdir}/timidity++ \
    --enable-interface=ncurses,vt100,alsaseq,server,network,gtk,tcltk \
    --enable-dynamic=gtk,tcltk \
    --enable-audio=ao,alsa,oss,jack,vorbis,speex,flac
make %{?_smp_mflags}


#  --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

#--------------------------------------------------------------------
%install
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT INSTALL="install -p"

# add Japanese stuffs
cd doc/ja_JP.eucJP
mkdir -p $RPM_BUILD_ROOT%{_mandir}/ja/{man1,man5}
iconv -f euc-jp -t utf8 timidity.1 > timidity.1.utf8
iconv -f euc-jp -t utf8 timidity.cfg.5 > timidity.cfg.5.utf8
install -m644 timidity.1.utf8 $RPM_BUILD_ROOT%{_mandir}/ja/man1/timidity.1
install -m644 timidity.cfg.5.utf8 $RPM_BUILD_ROOT%{_mandir}/ja/man5/timidity.cfg.5

iconv -f euc-jp -t utf8 README.alsaseq > README.alsaseq.ja
iconv -f euc-jp -t utf8 README.dl      > README.dl.ja
iconv -f euc-jp -t utf8 README.m2m     > README.m2m.ja
iconv -f euc-jp -t utf8 README.mts     > README.mts.ja
iconv -f euc-jp -t utf8 README.sf      > README.sf.ja
iconv -f euc-jp -t utf8 README.tk      > README.tk.ja
cd ../..

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

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

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

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

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

%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 -eq 1 ]; then
    /sbin/chkconfig --add alsa2midi
fi
if [ $1 -eq 2 ]; then
    /sbin/service alsa2midi condrestart >/dev/null 2>&1 || :
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/service alsa2midi stop >/dev/null 2>&1 || :
    /sbin/chkconfig --del alsa2midi
    /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* NEWS ChangeLog* doc/C/FAQ
%doc timidity_add_text.txt doc/ja_JP.eucJP/README*.ja
%config(noreplace) %{_sysconfdir}/timidity/timidity*.cfg
%{_sysconfdir}/init.d/*
%{_bindir}/*
%{_libdir}/timidity++
%{_mandir}/*
%{_datadir}/applications/timidity.desktop
%{_datadir}/icons/hicolor/48x48/apps/timidity.xpm

%changelog
* Sun Sep 01 2019 Toshiaki Ara <ara_t@384.jp> 2.14-0-3
- rebuild with ncurses-6.1

* Mon Feb  2 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> 2.14.0-2
- added BR: libuuid-devel

* Mon Feb  2 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> 2.14.0-1
- rebuilt on current VineSeed
- updated SOURCE1
- changed SOURCE2 encoding to UTF-8
- fixed spec encoding to UTF-8 (BTS #2784)
- rebuilt with tcl/tk 8.5
				
* Wed Aug 29 2012 Yoji TOYODA 2.13.2-10
- rebuild with VineSeed environment
- add Patch10 (TiMidity++_tcltk.patch)

* 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.
