diff --git a/GUI/Widgets/PawfalYesNo.C b/GUI/Widgets/PawfalYesNo.C index 5174762..a283318 100644 --- a/GUI/Widgets/PawfalYesNo.C +++ b/GUI/Widgets/PawfalYesNo.C @@ -34,9 +34,20 @@ bool Pawfal_YesNo(const char *a,...) ::vsnprintf(buffer, 1024, a, ap); } va_end(ap); - +#if !__APPLE__ PawfalYesNo pi(300, 100,buffer); if (pi.go()) return true; +#else + Str255 copy; + strncpy((char*)copy + 1, buffer, 253); + copy[0] = strlen((char*)copy+1); + AlertStdAlertParamRec rec = { true, false, NULL, + (StringPtr)-1, (StringPtr)-1, NULL, + kAlertStdAlertOKButton, 0, kWindowAlertPositionParentWindowScreen }; + SInt16 ret = 0; + StandardAlert(kAlertCautionAlert, copy, NULL, &rec, &ret); + return ret == kAlertStdAlertOKButton; +#endif return false; } diff --git a/SpiralSound/Midi.C b/SpiralSound/Midi.C index c3a0509..882a7fa 100644 --- a/SpiralSound/Midi.C +++ b/SpiralSound/Midi.C @@ -45,6 +45,10 @@ static int NKEYS = 30; MidiDevice *MidiDevice::m_Singleton; string MidiDevice::m_DeviceName; +#if __APPLE__ +#define read AppleRead +#endif + MidiDevice::MidiDevice() : m_Poly(1) { @@ -52,9 +56,7 @@ m_Poly(1) seq_handle=AlsaOpen(); #else Open(); -#endif - - +#endif #ifdef KEYBOARD_SUPPORT m_Oct=4; @@ -78,6 +80,9 @@ MidiDevice::~MidiDevice() void MidiDevice::Close() { +#if __APPLE__ + AppleClose(); +#else pthread_mutex_lock(m_Mutex); pthread_cancel(m_MidiReader); pthread_mutex_unlock(m_Mutex); @@ -86,11 +91,15 @@ void MidiDevice::Close() close(m_MidiFd); close(m_MidiWrFd); cerr<<"Closed midi device"< 0) { + int r = m_ReadReadIndex; + outbuffer[len++] = m_ReadBuffer[r]; + r++; + m_ReadReadIndex = r % midi_ReadSize; + } + } while (len < maxlen); + return len; +} + +void MidiDevice::sMIDIRead(const MIDIPacketList *pktlist, void *readProcRefCon, void *srcConnRefCon) +{ + MidiDevice & t = *((MidiDevice*)readProcRefCon); + + const MIDIPacket *packet = &pktlist->packet[0]; + for (int i = 0; i < (int)pktlist->numPackets; i++) { + const MIDIPacket & p = *packet; + + for (int b = 0; b < p.length; b++) { + // printf("%02x ", p.data[b]); + int d = t.m_ReadFillIndex; + t.m_ReadBuffer[d] = p.data[b]; + d++; + t.m_ReadFillIndex = d % midi_ReadSize; + } + // printf("\n"); + packet = MIDIPacketNext(packet); + } +} + +#endif diff --git a/SpiralSound/Midi.h b/SpiralSound/Midi.h index adf4dc4..b58fe4f 100644 --- a/SpiralSound/Midi.h +++ b/SpiralSound/Midi.h @@ -36,6 +36,10 @@ using namespace std; #include #endif +#if __APPLE__ +#include +#endif + class MidiEvent { public: @@ -97,6 +101,25 @@ private: snd_seq_t *seq_handle; snd_seq_t *AlsaOpen(); #endif + +#if __APPLE__ + MIDIClientRef mMIDIClient; + MIDIEndpointRef mMIDISource; + MIDIEndpointRef mMIDIDestination; + + #define midi_ReadSize 4096 + unsigned char m_ReadBuffer[midi_ReadSize]; + volatile int m_ReadFillIndex; + volatile int m_ReadReadIndex; + + void MidiDevice::AppleOpen(); + void MidiDevice::AppleClose(); + int MidiDevice::AppleWrite(int dummy, unsigned char *outbuffer, int maxlen); + int MidiDevice::AppleRead(int dummy, unsigned char *outbuffer, int maxlen); + + static void MidiDevice::sMIDIRead(const MIDIPacketList *pktlist, void *readProcRefCon, void *srcConnRefCon); + +#endif }; #endif diff --git a/SpiralSound/Plugins/LFOPlugin/LFOPlugin.h b/SpiralSound/Plugins/LFOPlugin/LFOPlugin.h index 192f853..c49cac6 100644 --- a/SpiralSound/Plugins/LFOPlugin/LFOPlugin.h +++ b/SpiralSound/Plugins/LFOPlugin/LFOPlugin.h @@ -35,7 +35,8 @@ class LFOPlugin : public SpiralPlugin { virtual void StreamOut (ostream &s); virtual void StreamIn (istream &s); - enum Type {SINE, TRIANGLE, SQUARE, SAW}; + typedef char Type; + enum {SINE, TRIANGLE, SQUARE, SAW}; void WriteWaves(); void NoteTrigger (int V, int s, int v); diff --git a/SpiralSound/Plugins/OscillatorPlugin/OscillatorPlugin.h b/SpiralSound/Plugins/OscillatorPlugin/OscillatorPlugin.h index 8b66dd0..a9559a7 100644 --- a/SpiralSound/Plugins/OscillatorPlugin/OscillatorPlugin.h +++ b/SpiralSound/Plugins/OscillatorPlugin/OscillatorPlugin.h @@ -34,7 +34,8 @@ public: virtual void StreamOut(ostream &s); virtual void StreamIn(istream &s); - enum Type{NONE,SQUARE,SAW,NOISE}; + typedef char Type; + enum {NONE,SQUARE,SAW,NOISE}; void ModulateFreq(Sample *data) {m_FreqModBuf=data;} void ModulatePulseWidth(Sample *data) {m_PulseWidthModBuf=data;} diff --git a/SpiralSound/Plugins/SpiralLoopPlugin/GUI/Widgets/Fl_Loop.C b/SpiralSound/Plugins/SpiralLoopPlugin/GUI/Widgets/Fl_Loop.C index 4ce5ec6..20f564f 100644 --- a/SpiralSound/Plugins/SpiralLoopPlugin/GUI/Widgets/Fl_Loop.C +++ b/SpiralSound/Plugins/SpiralLoopPlugin/GUI/Widgets/Fl_Loop.C @@ -186,8 +186,10 @@ void Fl_Loop::DrawPosMarker() if (m_Pos) { float Angle=(*m_Pos/m_Length)*360.0; - fl_line_style(FL_SOLID, 3, NULL); + fl_line_style(FL_SOLID, 3, NULL); +#if !__APPLE__ XSetFunction(fl_display,fl_gc,GXxor); +#endif fl_line(m_IndSX,m_IndSY,m_IndEX,m_IndEY); fl_color(FL_BLUE); @@ -200,7 +202,9 @@ void Fl_Loop::DrawPosMarker() fl_line(m_IndSX,m_IndSY,m_IndEX,m_IndEY); fl_line_style(FL_SOLID, 1, NULL); +#if !__APPLE__ XSetFunction(fl_display,fl_gc,GXcopy); +#endif } if (m_PosMarkerCount>POSMARKER_MAX) diff --git a/SpiralSound/Plugins/WaveTablePlugin/WaveTablePlugin.h b/SpiralSound/Plugins/WaveTablePlugin/WaveTablePlugin.h index ed8bdcf..13027e5 100644 --- a/SpiralSound/Plugins/WaveTablePlugin/WaveTablePlugin.h +++ b/SpiralSound/Plugins/WaveTablePlugin/WaveTablePlugin.h @@ -40,7 +40,8 @@ public: // has to be defined in the plugin virtual void UpdateGUI() { Fl::check(); } - enum Type{SINE,SQUARE,SAW,REVSAW,TRIANGLE,PULSE1,PULSE2,INVSINE}; + typedef char Type; + enum {SINE,SQUARE,SAW,REVSAW,TRIANGLE,PULSE1,PULSE2,INVSINE}; void WriteWaves(); void NoteTrigger(int V,int s,int v); diff --git a/SpiralSound/Plugins/Widgets/Fl_EventMap.C b/SpiralSound/Plugins/Widgets/Fl_EventMap.C index 65cb28b..2d9aa4e 100644 --- a/SpiralSound/Plugins/Widgets/Fl_EventMap.C +++ b/SpiralSound/Plugins/Widgets/Fl_EventMap.C @@ -34,8 +34,8 @@ int LINE_COLOUR;// = 140; //////////////////////////////////////////////////////////////////// -Fl_EventMap::Fl_EventMap(int x, int y, int w, int h, const char* label) : -Fl_Group(x,y,w,h,label), +Fl_EventMap::Fl_EventMap(int x, int y, int ww, int h, const char* label) : +Fl_Group(x,y,ww,h,label), m_Type(ARRANGE_MAP), m_Update(true), m_Zoom(1.0f), @@ -62,6 +62,7 @@ m_FirstUpdate(true) LINE_COLOUR=fl_color(); fl_color(200,200,200); +// SpiralSound/Plugins/Widgets/Fl_EventMap.C:65: declaration of `w' shadows a parameter int w=fl_color(); fl_color(50,50,50); int b=fl_color(); @@ -263,12 +264,14 @@ void Fl_EventMap::SetTime(float Time) int Depth=parent()->h(); if (DrawPos>Left && DrawPos>8)) +#define SWAPSHORT(a) (a)=(((a)<<8)|(((a)>>8)&0xff)) #define SWAPINT(a) (a)=(((a)&0x000000ff)<<24)|(((a)&0x0000ff00)<<8)|(((a)&0x00ff0000)>>8)|(((a)&0xff000000)>>24) +#else +#define SWAPSHORT(a) +#define SWAPINT(a) #endif int WavFile::Open(string FileName, Mode mode, Channels channels) @@ -92,7 +94,6 @@ int WavFile::Open(string FileName, Mode mode, Channels channels) m_DataHeader.DataLengthBytes=0; - #if __BYTE_ORDER == BIG_ENDIAN SWAPINT(m_Header.RiffFileLength); SWAPINT(m_Header.FmtLength); SWAPSHORT(m_Header.FmtTag); @@ -102,7 +103,6 @@ int WavFile::Open(string FileName, Mode mode, Channels channels) SWAPSHORT(m_Header.FmtBlockAlign); SWAPSHORT(m_Header.FmtBitsPerSample); SWAPINT(m_DataHeader.DataLengthBytes); - #endif fwrite(&m_Header,1,sizeof(CanonicalWavHeader),m_Stream); fwrite(&m_DataHeader,1,sizeof(DataHeader),m_Stream); @@ -113,7 +113,16 @@ int WavFile::Open(string FileName, Mode mode, Channels channels) if (mode==READ) { fread(&m_Header,sizeof(CanonicalWavHeader),1,m_Stream); - + + SWAPINT(m_Header.RiffFileLength); + SWAPINT(m_Header.FmtLength); + SWAPSHORT(m_Header.FmtTag); + SWAPSHORT(m_Header.FmtChannels); + SWAPINT(m_Header.FmtSamplerate); + SWAPINT(m_Header.FmtBytesPerSec); + SWAPSHORT(m_Header.FmtBlockAlign); + SWAPSHORT(m_Header.FmtBitsPerSample); + #ifdef TRACE_OUT cerr<1) v=1; temp[n]=(short)(v*SHRT_MAX); + SWAPSHORT(temp[n]); } m_DataHeader.DataLengthBytes+=data.GetLength()*2; fwrite(temp,sizeof(&temp),data.GetLength()/2,m_Stream); + + // leak! + delete[] temp; + return 1; } @@ -270,7 +286,9 @@ int WavFile::Load(Sample &data) long value=0; for (int i=0; i #include "Sample.h" +#if __APPLE__ +// this is the traditional way of setting 2 bytes alignment +// else the apple compiler might use 4, or even 8 +#pragma options align=mac68k +#endif + struct CanonicalWavHeader { char RiffName[4]; @@ -46,6 +52,10 @@ struct DataHeader int DataLengthBytes; }; +#if __APPLE__ +#pragma options align=reset +#endif + class WavFile { public: diff --git a/SpiralSynthModularInfo.C b/SpiralSynthModularInfo.C index 93b7b82..ed2964e 100644 --- a/SpiralSynthModularInfo.C +++ b/SpiralSynthModularInfo.C @@ -125,6 +125,11 @@ void SpiralSynthModularInfo::StreamInPrefs(istream &s) s>>st; if (st!="end") PLUGINVEC.push_back(st); } +#if __APPLE__ + // ignore custom paths, plugins are encapsulated in the app anyway + // this prevents the program to fail if the user move the application icon + PLUGIN_PATH = PLUGIN_PATH_LOCATION; +#endif } void SpiralSynthModularInfo::StreamOutPrefs(ostream &s) diff --git a/main.cpp b/main.cpp index 1d4e88a..c756ef8 100644 --- a/main.cpp +++ b/main.cpp @@ -99,9 +99,29 @@ void audioloop(void* o) } ////////////////////////////////////////////////////// +#if __APPLE__ +#include +#include +#endif int main(int argc, char **argv) -{ +{ +#if __APPLE__ + // --with-plugindir=./Libraries + system("pwd"); + CFBundleRef main = CFBundleGetMainBundle(); + CFURLRef url = main ? CFBundleCopyExecutableURL(main) : NULL; + CFStringRef path = url ? CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle) : NULL; + char * dst = (char*)CFStringGetCStringPtr(path, 0); + + printf("main %p url %p path %p dst %p", main, url, path, dst); + if (dst) { + printf("Have a valid name '%s'\n", dst); + chdir(dirname(dst)); + chdir(".."); + } else + printf("No base pathname\n"); +#endif srand(time(NULL)); SpiralSynthModularInfo::Get()->LoadPrefs();