# $Id: vstsdk2.4.2.patch,v 1.2 2012-10-24 03:56:58 otu Exp $
# Original file is on http://otu.sakura.ne.jp/gallery/
#
# This is for
#   vst_sdk2_4_rev2.zip (md5sum: b4b496306a95e422ccffd0e73b87a870)
#
# Install
#   zlib   from Cygwin setup
#   LIBPNG from http://gnuwin32.sourceforge.net/packages/libpng.htm
#     * libpng3.dll in libpng-1.2.37-bin.zip to c:\windows
#     * libpng.dll.a in libpng-1.2.37-lib.zip to /lib/wingw/.
#     * png.h and pngconf.h in libpng-1.2.37-lib.zip to /usr/include/mingw/.
# and
# Copy
#   /bin/mgwz.dll to c:\windows\zlib1.dll
# and
# Execute
#   patch -p0 <vstsdk2.4.2.patch
#   cd vstsdk2.4/public.sdk/samples/vst2.x/cygwin
#   make
#
# OR
#
# Execute
#   patch -p0 <vstsdk2.4.2.patch
# and
# Modify
#   vstsdk2.4/vstgui.sf/drawtest/win/drawtest.rc
#   : s/png/bmp/
#   : s/PNG/BITMAP DISCARDABLE/
#   vstsdk2.4/public.sdk/samples/vst2.x/cygwin/Makefile
#   : s/USEPNG = y/USEPNG = n/
# and
# Convert
#   vstsdk2.4/vstgui.sf/drawtest/resource/*.png into vstsdk2.4/vstgui.sf/drawtest/resource/*.bmp
# Execute
#   cd vstsdk2.4/public.sdk/samples/vst2.x/cygwin
#   make
# (In this method drawtest.dll is incomplete because BMP format does not support transparency.)
#
#
--- vstsdk2.4/vstgui.sf/drawtest/source/pdrawtestmain.cpp	2006-01-10 19:21:00.000000000 +0900
+++ vstsdk2.4/vstgui.sf/drawtest/source/pdrawtestmain.cpp	2012-10-23 15:08:29.859375000 +0900
@@ -72,2 +72,7 @@
-void* hInstance;
-BOOL WINAPI DllMain (HINSTANCE hInst, DWORD dwReason, LPVOID lpvReserved)
+//void* hInstance;
+//BOOL WINAPI DllMain (HINSTANCE hInst, DWORD dwReason, LPVOID lpvReserved)
+//{
+//	hInstance = hInst;
+//	return 1;
+//}
+AudioEffect* createEffectInstance (audioMasterCallback audioMaster)
@@ -75,2 +80 @@
-	hInstance = hInst;
-	return 1;
+	return new DrawTestEffect (audioMaster);
--- vstsdk2.4/vstgui.sf/vstgui/plugguieditor.h	2006-02-13 11:15:00.000000000 +0900
+++ vstsdk2.4/vstgui.sf/vstgui/plugguieditor.h	2012-06-01 12:44:50.529375000 +0900
@@ -45,7 +45,7 @@
-struct ERect
-{
-	short top;
-	short left;
-	short bottom;
-	short right;
-};
+//struct ERect
+//{
+//	short top;
+//	short left;
+//	short bottom;
+//	short right;
+//};
--- vstsdk2.4/public.sdk/samples/vst2.x/cygwin/Makefile	1970-01-01 09:00:00.000000000 +0900
+++ vstsdk2.4/public.sdk/samples/vst2.x/cygwin/Makefile	2012-10-23 20:07:31.984375000 +0900
@@ -0,0 +1,71 @@
+#! /usr/bin/make -f
+## A Makefile to build contents of VST SDK 2.4 on Cygwin.
+## Make "cygwin" subdirectory in "public.sdk/samples/vst2.x" directory
+## and put this Makefile in it.
+##
+
+VPATH = ../adelay:../again/source:../adelay/editor:../minihost:../vstxsynth/source:../../../source/vst2.x:../../../../vstgui.sf/vstgui:../adelay/editor/resources:../vstxsynth/resource:../../../../vstgui.sf/drawtest/source:../../../../vstgui.sf/drawtest/win:../minihost/source
+
+CC      = g++
+INCLUDE = -I../../../.. -I../../../source/vst2.x -I../../../vstgui.sf/vstgui -I../adelay -I../again -I../minihost -I../vstxsynth -I../../../../vstgui.sf/vstgui
+LIB     = -L. -lvst
+USEPNG = y
+ifeq ($(USEPNG),y)
+CFLAGS  = -mno-cygwin -mwindows -g -DWINDOWS -s -DUSE_LIBPNG
+GUILIB  = -lole32 -luuid -lpng
+else
+CFLAGS  = -mno-cygwin -mwindows -g -DWINDOWS -s
+GUILIB  = -lole32 -luuid
+endif
+
+.SUFFIXES: .coff .rc
+
+all : adelay.dll again.dll surrounddelay.dll vstxsynth.dll drawtest.dll minihost.exe
+
+libvst.a : $(subst .cpp,.o,$(notdir $(wildcard ../../../source/vst2.x/*.cpp ../../../../vstgui.sf/vstgui/*.cpp)))
+	ar rv $@ $?
+
+clean :
+	rm -f *.o *.dll *.a *.coff *.exe *.def
+
+.cpp.o :
+	$(CC) $(CFLAGS) $(INCLUDE) -c $?
+
+.rc.coff :
+	windres --input-format=rc --output-format=coff $^ $@
+
+adelay.dll : adelay.o adelaymain.o libvst.a vstplug.def
+	$(CC) $(CFLAGS) -shared -o $@ $^ $(LIB)
+
+again.dll : again.o libvst.a vstplug.def
+	$(CC) $(CFLAGS) -shared -o $@ $^ $(LIB)
+
+surrounddelay.dll : surrounddelay.o adelay.o sdeditor.o surrounddelay.coff libvst.a vstplug.def
+	$(CC) $(CFLAGS) -shared -o $@ $^ $(LIB) $(GUILIB) vstplug.def
+
+vstxsynth.dll : vstxsynth.o vstxsynthproc.o vstxsynth.coff libvst.a vstplug.def
+	$(CC) $(CFLAGS) -shared -o $@ $^ $(LIB) $(GUILIB)
+
+drawtest.dll : $(subst .cpp,.o,$(notdir $(wildcard ../../../../vstgui.sf/drawtest/source/*.cpp))) drawtest.coff libvst.a vstplug.def
+	$(CC) $(CFLAGS) -shared -o $@ $^ $(LIB) $(GUILIB)
+
+minihost.exe : minihost.o minieditor.o
+	$(CC) $(CFLAGS) -o $@ $^ $(LIB) $(GUILIB)
+
+vstplug.def :
+	echo EXPORTS >$@
+	echo VSTPluginMain >>$@
+	echo main=VSTPluginMain >>$@
+
+installlib : libvst.a uninstalllib
+	cp libvst.a /usr/local/lib
+	mkdir -p /usr/local/include/vst
+	cd ../../../source/vst2.x && cp audioeffectx.h audioeffect.h aeffeditor.h /usr/local/include/vst/.
+	cd ../../../../vstgui.sf/vstgui && cp vstgui.h aeffguieditor.h vstcontrols.h cscrollview.h ctabview.h cfileselector.h /usr/local/include/vst/.
+	mkdir -p /usr/local/include/vst/pluginterfaces/vst2.x
+	cd ../../../../pluginterfaces/vst2.x && cp aeffectx.h aeffect.h /usr/local/include/vst/pluginterfaces/vst2.x
+
+uninstalllib :
+	rm -f /usr/local/lib/libvst.a
+	rm -rf /usr/local/include/vst
+
