Beispiel #1
0
// Pass resFile as -1 to use the current resource file
// true = exists
Boolean IndResourceExists(short resFile,ResType resType,short inIndex)
{
	short 	oldRes=::CurResFile();
	Handle	theRes=0L;
	
	if (resFile!=-1)
	{
		UseResFile(resFile);
		if (ResError())
			return false;
	}
	
	SetResLoad(false);
	theRes=Get1IndResource(resType,inIndex);
	SetResLoad(true);
	UseResFile(oldRes);
	
	if (theRes)
	{
		ReleaseResource(theRes);
		return true;
	}
	else
		return false;
}
Beispiel #2
0
Handle BetterGetIndResource(short resFile,ResType theType,short resID)
{
	short		saveFile=::CurResFile();
	Handle		theHandle;
	
	if (resFile!=-1)
		UseResFile(resFile);
	theHandle=Get1IndResource(theType,resID);
	if (!theHandle)
	{
		gGetResErr=ResError();
		if (!gGetResErr)
		{
			if (IndResourceExists(resFile,theType,resID))
				gGetResErr=memFullErr;
			else
				gGetResErr=resNotFound;
		}
	}
	else
		gGetResErr=noErr;
	
	if (resFile!=-1)
		UseResFile(saveFile);
	
	return theHandle;
}
Beispiel #3
0
void PAS_sortIDs(short sourceRefNum, OSType theType, short **IdPtr, long *count)
{
	short				oldRef;
	Handle				theHandle;
	short				resCount;
	short				resIndex;
	
	*count	=	-1;
	
	oldRef = CurResFile();
		
	UseResFile(sourceRefNum);

	resCount = Count1Resources(theType);
	
	*IdPtr	=	(short*) NewPtrClear( resCount * sizeof(short) );
	
	for (resIndex=1; resIndex <= resCount; resIndex++)
	{
		theHandle = Get1IndResource(theType, resIndex);
		
		if(theHandle == NULL) return;
	
		(*IdPtr)[resIndex-1] = PAS_getResourceID(theHandle);
		
		ReleaseResource(theHandle);
	}
	
	UseResFile(oldRef);
	
	PAS_bubbleSortIDS(*IdPtr, resCount);
	
	
	*count = resCount;
}
OSStatus		CAComponent::GetResourceVersion (UInt32 &outVersion) const
{
	bool versionFound = false;
	ResFileRefNum componentResFileID = kResFileNotOpened;
	OSStatus result;
	short thngResourceCount;
	
	short curRes = CurResFile();
	require_noerr (result = OpenAComponentResFile( mComp, &componentResFileID), home);
	require_noerr (result = componentResFileID <= 0, home);
	
	UseResFile(componentResFileID);

	thngResourceCount = Count1Resources(kComponentResourceType);
	
	require_noerr (result = ResError(), home);
			// only go on if we successfully found at least 1 thng resource
	require_noerr (thngResourceCount <= 0 ? -1 : 0, home);

	// loop through all of the Component thng resources trying to 
	// find one that matches this Component description
	for (short i = 0; i < thngResourceCount && (!versionFound); i++)
	{
		// try to get a handle to this code resource
		Handle thngResourceHandle = Get1IndResource(kComponentResourceType, i+1);
		if (thngResourceHandle != NULL && ((*thngResourceHandle) != NULL))
		{
			if (UInt32(GetHandleSize(thngResourceHandle)) >= sizeof(ExtComponentResource))
			{
				ExtComponentResource * componentThng = (ExtComponentResource*) (*thngResourceHandle);

				// check to see if this is the thng resource for the particular Component that we are looking at
				// (there often is more than one Component described in the resource)
				if ((componentThng->cd.componentType == mDesc.Type()) 
						&& (componentThng->cd.componentSubType == mDesc.SubType()) 
						&& (componentThng->cd.componentManufacturer == mDesc.Manu()))
				{
					outVersion = componentThng->componentVersion;
					versionFound = true;
				}
			}
			ReleaseResource(thngResourceHandle);
		}
	}

	if (!versionFound)
		result = resNotFound;
		
	UseResFile(curRes);	// revert
	
	if ( componentResFileID != kResFileNotOpened )
		CloseComponentResFile(componentResFileID);
		
home:
	return result;
}
CResource	CResourceFile::GetByIndex( const std::string& type, int16_t index )
{
	if( mResRefNum > 0 )
	{
		return CResource( Get1IndResource( type, index ) );
	}
	else
	{
		return CResource( NULL );
	}
}
Beispiel #6
0
  /* Create a new FT_Face from a file spec to a suitcase file. */
  static FT_Error
  FT_New_Face_From_Suitcase( FT_Library    library,
                             const UInt8*  pathname,
                             FT_Long       face_index,
                             FT_Face*      aface )
  {
    FT_Error       error = FT_ERR( Cannot_Open_Resource );
    ResFileRefNum  res_ref;
    ResourceIndex  res_index;
    Handle         fond;
    short          num_faces_in_res;


    if ( noErr != FT_FSPathMakeRes( pathname, &res_ref ) )
      return FT_THROW( Cannot_Open_Resource );

    UseResFile( res_ref );
    if ( ResError() )
      return FT_THROW( Cannot_Open_Resource );

    num_faces_in_res = 0;
    for ( res_index = 1; ; ++res_index )
    {
      short  num_faces_in_fond;


      fond = Get1IndResource( TTAG_FOND, res_index );
      if ( ResError() )
        break;

      num_faces_in_fond  = count_faces( fond, pathname );
      num_faces_in_res  += num_faces_in_fond;

      if ( 0 <= face_index && face_index < num_faces_in_fond && error )
        error = FT_New_Face_From_FOND( library, fond, face_index, aface );

      face_index -= num_faces_in_fond;
    }

    CloseResFile( res_ref );
    if ( !error && aface )
      (*aface)->num_faces = num_faces_in_res;
    return error;
  }
Beispiel #7
0
  /* Create a new FT_Face from a file spec to a suitcase file. */
  static FT_Error
  FT_New_Face_From_dfont( FT_Library  library,
                          FSSpec*     spec,
                          FT_Long     face_index,
                          FT_Face*    aface )
  {
    FT_Error  error = FT_Err_Ok;
    short     res_ref, res_index;
    Handle    fond;
    FSRef     hostContainerRef;


    error = FSpMakeFSRef( spec, &hostContainerRef );
    if ( error == noErr )
      error = FSOpenResourceFile( &hostContainerRef,
                                  0, NULL, fsRdPerm, &res_ref );

    if ( error != noErr )
      return FT_Err_Cannot_Open_Resource;

    UseResFile( res_ref );

    /* face_index may be -1, in which case we
       just need to do a sanity check */
    if ( face_index < 0 )
      res_index = 1;
    else
    {
      res_index = (short)( face_index + 1 );
      face_index = 0;
    }
    fond = Get1IndResource( 'FOND', res_index );
    if ( ResError() )
    {
      error = FT_Err_Cannot_Open_Resource;
      goto Error;
    }

    error = FT_New_Face_From_FOND( library, fond, face_index, aface );

  Error:
    CloseResFile( res_ref );
    return error;
  }
Beispiel #8
0
  /* Create a new FT_Face from a file spec to a suitcase file. */
  static FT_Error
  FT_New_Face_From_Suitcase( FT_Library    library,
                             const UInt8*  pathname,
                             FT_Long       face_index,
                             FT_Face*      aface )
  {
    FT_Error  error = FT_Err_Cannot_Open_Resource;
    short     res_ref, res_index;
    Handle    fond;
    short     num_faces_in_res, num_faces_in_fond;


    if ( noErr != FT_FSPathMakeRes( pathname, &res_ref ) )
      return FT_Err_Cannot_Open_Resource;

    UseResFile( res_ref );
    if ( ResError() )
      return FT_Err_Cannot_Open_Resource;

    num_faces_in_res = 0;
    for ( res_index = 1; ; ++res_index )
    {
      fond = Get1IndResource( 'FOND', res_index );
      if ( ResError() )
        break;

      num_faces_in_fond  = count_faces( fond, pathname );
      num_faces_in_res  += num_faces_in_fond;

      if ( 0 <= face_index && face_index < num_faces_in_fond && error )
        error = FT_New_Face_From_FOND( library, fond, face_index, aface );

      face_index -= num_faces_in_fond;
    }

    CloseResFile( res_ref );
    if ( FT_Err_Ok == error && NULL != aface )
      (*aface)->num_faces = num_faces_in_res;
    return error;
  }
Beispiel #9
0
/*
**	FindBundleGivenCreator
**
**	Search the current resource file for the 'BNDL' resource with the given
**	creator and return a handle to it.
*/
static	OSErr	FindBundleGivenCreator(OSType creator,
									   BNDLRecHandle *returnBndl)
{
	OSErr			error;
	short			numOfBundles;
	short			index;
	BNDLRecHandle	theBndl;
	
	error = afpItemNotFound;	/* default to not found */
	
	/* Search each BNDL resource until we find the one with a matching creator. */
	
	numOfBundles = Count1Resources(kBNDLResType);
	index = 1;
	*returnBndl = NULL;
	
	while ( (index <= numOfBundles) && (*returnBndl == NULL) )
	{
		theBndl = (BNDLRecHandle)Get1IndResource(kBNDLResType, index);
		
		if ( theBndl != NULL )
		{
			if ( (*theBndl)->signature == creator )
			{
				/* numTypes and typeArray->count will always be the actual count minus 1, */
				/* so 0 in both fields is valid. */
				if ( ((*theBndl)->numTypes >= 0) && ((*theBndl)->typeArray->count >= 0) )
				{
					/* got it */
					*returnBndl = theBndl;
					error = noErr;
				}
			}
		}	
		
		index ++;
	}
	
	return ( error );
}
// Parse all resources in a set
bool XML_ResourceFork::ParseResourceSet(ResType Type)
{
    short NumResources = Count1Resources(Type);

    if (NumResources <= 0) {
        return false;
    }

    // This sorting is necessary so that the resources will be read in ascending order of ID's
    short *IDList = new short[NumResources];

    // Get the resource ID's
    SetResLoad(false);

    for (int ir=0; ir<NumResources; ir++)
    {
        // Zero-based to one-based indexing
        ResourceHandle = Get1IndResource(Type,ir+1);
        ResType _Type;
        Str255 Name;
        GetResInfo(ResourceHandle,&IDList[ir],&_Type,Name);
        ReleaseResource(ResourceHandle);
    }

    SetResLoad(true);

    // Using a better sorter; STL will succeed where Rhys Hill had failed :-)
    sort(IDList,IDList+NumResources);

    // Now get the resources
    for (int ir=0; ir<NumResources; ir++)
    {
        ParseResource(Type,IDList[ir]);
    }

    delete [] IDList;
    return true;
}
Beispiel #11
0
  /* Create a new FT_Face from a file spec to a suitcase file. */
  static FT_Error
  FT_New_Face_From_Suitcase( FT_Library  library,
                             FSSpec*     spec,
                             FT_Long     face_index,
                             FT_Face    *aface )
  {
    FT_Error  error = FT_Err_Ok;
    short     res_ref, res_index;
    Handle    fond;


    res_ref = FSpOpenResFile( spec, fsRdPerm );
    if ( ResError() )
      return FT_Err_Cannot_Open_Resource;
    UseResFile( res_ref );

    /* face_index may be -1, in which case we
       just need to do a sanity check */
    if ( face_index < 0 )
      res_index = 1;
    else
    {
      res_index = (short)( face_index + 1 );
      face_index = 0;
    }
    fond = Get1IndResource( 'FOND', res_index );
    if ( ResError() )
    {
      error = FT_Err_Cannot_Open_Resource;
      goto Error;
    }

    error = FT_New_Face_From_FOND( library, fond, face_index, aface );

  Error:
    CloseResFile( res_ref );
    return error;
  }
Beispiel #12
0
static PyObject *Res_Get1IndResource(PyObject *_self, PyObject *_args)
{
    PyObject *_res = NULL;
    Handle _rv;
    ResType theType;
    short index;
#ifndef Get1IndResource
    PyMac_PRECHECK(Get1IndResource);
#endif
    if (!PyArg_ParseTuple(_args, "O&h",
                          PyMac_GetOSType, &theType,
                          &index))
        return NULL;
    _rv = Get1IndResource(theType,
                          index);
    {
        OSErr _err = ResError();
        if (_err != noErr) return PyMac_Error(_err);
    }
    _res = Py_BuildValue("O&",
                         ResObj_New, _rv);
    return _res;
}
Beispiel #13
0
/* parse and summarize FOND resource information */
static fond_table * parse_fond(FSSpec *spec)
{
    OSErr result = noErr;
    FSRef specref;
    SInt16 ref;
    Handle fond = NULL;
    unsigned char *res;
    fond_table *table = NULL;
    int i,j, count, n, start;

        /* FSpOpenResFile will fail for data fork resource (.dfont) files.
           FSOpenResourceFile can open either, but cannot handle broken resource
           maps, as often occurs in font files (the suitcase version of Arial,
           for example) Thus, we try one, and then the other. */

    result = FSpMakeFSRef(spec,&specref);
#ifdef __CARBON__
        if (result == noErr)
                result = FSOpenResourceFile(&specref, 0, NULL, fsRdPerm, &ref);
#else
        result = bdNamErr; /* simulate failure of the carbon routine above */
#endif
    if (result != noErr) {
            ref = FSpOpenResFile(spec, fsRdPerm);
            result = ResError();
        }
    if (result != noErr || ref <= 0) {
        char path[256];
        convertSpecToPath(spec, path, 256);
        dlprintf2("unable to open resource file '%s' for font enumeration (error %d)\n",
                path, result);
        goto fin;
    }

    /* we've opened the font file, now loop over the FOND resource(s)
       and construct a table of the font references */

    start = 0; /* number of entries so far */
    UseResFile(ref);
    count = Count1Resources('FOND');
    for (i = 0; i < count; i++) {
        fond = Get1IndResource('FOND', i+1);
        if (fond == NULL) {
            result = ResError();
            goto fin;
        }

        /* The FOND resource structure corresponds to the FamRec and AsscEntry
           data structures documented in the FontManager reference. However,
           access to these types is deprecated in Carbon. We therefore access the
           data by direct offset in the hope that the resource format will not change
           even if api access to the in-memory versions goes away. */
        HLock(fond);
        res = *fond + 52; /* offset to association table */
        n = get_int16(res) + 1;	res += 2;
                table = fond_table_grow(table, n);
        for (j = start; j < start + n; j++ ) {
            table->refs[j].size = get_int16(res); res += 2;
            table->refs[j].style = get_int16(res); res += 2;
            table->refs[j].id = get_int16(res); res += 2;
        }
        start += n;
        HUnlock(fond);
    }
fin:
    CloseResFile(ref);
    return table;
}
Beispiel #14
0
Boolean MCScreenDC::open()
{
	owndnd = False;
	mouseMoveRgn = NewRgn();
	SetRectRgn(mouseMoveRgn, 0, 0, 1, 1);

	//create a invisible window, and set port to this window
	//so that later on at the very first time MC select and set font
	//will only affect in this invisible window, not other apps on the desk top,
	// when MC is first started.  The size of the window is random.
	//  Rect invisibleWinRect;
	Rect invisibleWinRect;
	SetRect(&invisibleWinRect, 0, 0, 20, 20);


	invisibleWin = NewCWindow(nil, &invisibleWinRect, "\p", False,
	                          kUtilityWindowClass, (WindowRef)(-1L), False, 0);



	long response;
	if (Gestalt(gestaltSystemVersion, &response) == noErr)
	{
		if (response >= 0x1030 && response < 0x1040)
			MCantialiasedtextworkaround = True;
		else
			MCantialiasedtextworkaround = False;
	}

	SetGWorld(GetWindowPort(invisibleWin), GetMainDevice());

	vis = new MCVisualInfo;
	
	devdepth = 32;

	black_pixel.red = black_pixel.green = black_pixel.blue = 0; //black pixel
	white_pixel.red = white_pixel.green = white_pixel.blue = 0xFFFF; //white pixel
		black_pixel.pixel = 0;
		white_pixel.pixel = 0xFFFFFF;

			redbits = greenbits = bluebits = 8;
			redshift = 16;
			greenshift = 8;
			blueshift = 0;
			vis->red_mask = 0x00FF0000;
			vis->green_mask = 0x0000FF00;
			vis->blue_mask = 0x000000FF;

	MCzerocolor = MCbrushcolor = white_pixel;
	alloccolor(MCbrushcolor);
	MCselectioncolor = MCpencolor = black_pixel;
	alloccolor(MCselectioncolor);
	alloccolor(MCpencolor);
	gray_pixel.red = gray_pixel.green = gray_pixel.blue = 0x8888;
	alloccolor(gray_pixel);
	background_pixel.red = background_pixel.green = background_pixel.blue = 0xffff;
	alloccolor(background_pixel);

	//query the system for the hilited text color, and set ours
	RGBColor hiliteRGB;
	LMGetHiliteRGB(&hiliteRGB);
	MChilitecolor.red = hiliteRGB.red;
	MChilitecolor.green = hiliteRGB.green;
	MChilitecolor.blue = hiliteRGB.blue;
	alloccolor(MChilitecolor);

	MCColor *syscolors = getaccentcolors();
	if (syscolors != NULL)
		MCaccentcolor = syscolors[4];
	else
	{
		MCaccentcolor.red = MCaccentcolor.green = 0x0000;
		MCaccentcolor.blue = 0x8080;
	}
	alloccolor(MCaccentcolor);

	grabbed = False;
	tripleclick = doubleclick = False;
	MCdoubletime = GetDblTime() * 1000 / 60;
	opened = True;
	mousewindow = new _Drawable;
	activewindow = new _Drawable;
	lastactivewindow = new _Drawable;
	mousewindow->type = activewindow->type = lastactivewindow->type = DC_WINDOW;
	mousewindow->handle.window = activewindow->handle.window
	                             = lastactivewindow->handle.window = 0;

	//get handle of application menu bar
	menuBar = GetMenuBar();
	SetMenuBar(menuBar);  //set menu bar as current menulist
	
	//create Apple menu
	appleMenu = NewMenu(mApple, "\p\024"); //menu title is an apple icon
	InsertMenuItem(appleMenu, "\pAbout...", 0);
	InsertMenu(appleMenu, 0);
	
	DrawMenuBar(); //draw the menu bar with the Apple menu
	usetemp = False;
	Handle tmem = Get1IndResource('TMEM', 1);
	if (tmem != NULL)
	{
		char *ptr = *tmem;
		if (*(ptr + 1))
			usetemp = True;
	}
	MCtemplatescrollbar->alloccolors();
	if (IsMacEmulatedLF()) // no AM
		MCtemplatebutton->allocicons();

	// preallocate these because GetItemMark can't distinguish them
	submenuIDs[0] = 1;
	submenuIDs[checkMark] = 1;
	submenuIDs[diamondMark] = 1;
	
	MCcursors[PI_NONE] = nil;
	MCblinkrate = GetCaretTime() * 1000 / 60;

	MCDisplay const *t_displays;
	getdisplays(t_displays, false);
	MCwbr = t_displays[0] . workarea;

	//TSM - INIT TSM APPLICATION AND INSTALL REQUIRED APPLEVENT HANDLERS
	TSMPositionToOffsetUPP = NewAEEventHandlerUPP(TSMPositionToOffset);
	TSMOffsetToPositionUPP = NewAEEventHandlerUPP(TSMOffsetToPosition);
	TSMUpdateHandlerUPP = NewAEEventHandlerUPP(TSMUpdateHandler);
	TSMUnicodeNotFromInputUPP
	= NewAEEventHandlerUPP(TSMUnicodeNotFromInputHandler);
	AEInstallEventHandler(kTextServiceClass, kPos2Offset,
	                      TSMPositionToOffsetUPP, 0L , False);
	AEInstallEventHandler(kTextServiceClass, kOffset2Pos,
	                      TSMOffsetToPositionUPP, 0L , False);
	AEInstallEventHandler(kTextServiceClass, kUpdateActiveInputArea,
	                      TSMUpdateHandlerUPP, 0L , False);
	AEInstallEventHandler(kTextServiceClass, kUnicodeNotFromInputMethod,
	                      TSMUnicodeNotFromInputUPP, 0L , False);
	openIME();

	dragdropUPP = NewDragReceiveHandlerUPP(DragReceiveHandler);
	InstallReceiveHandler(dragdropUPP, NULL, NULL);
	dragmoveUPP = NewDragTrackingHandlerUPP(DragTrackingHandler);
	InstallTrackingHandler(dragmoveUPP, NULL, NULL);
	
	s_animation_current_time = s_animation_start_time = CFAbsoluteTimeGetCurrent();
	
	//// Dock Menu Initialization
	
	EventTypeSpec t_menu_event_specs[1];
	t_menu_event_specs[0] . eventClass = kEventClassMenu;
	t_menu_event_specs[0] . eventKind = kEventMenuPopulate;
	
	CreateNewMenu(0, 0, &f_icon_menu);
	s_icon_menu_event_handler_upp = NewEventHandlerUPP((EventHandlerProcPtr)handleiconmenuevent);
	InstallEventHandler(GetMenuEventTarget(f_icon_menu), s_icon_menu_event_handler_upp, 1, t_menu_event_specs, NULL, NULL);
	
	t_menu_event_specs[0] . eventClass = kEventClassCommand;
	t_menu_event_specs[0] . eventKind = kEventCommandProcess;
	InstallEventHandler(GetApplicationEventTarget(), s_icon_menu_event_handler_upp, 1, t_menu_event_specs, NULL, NULL);
	
	SetApplicationDockTileMenu(f_icon_menu);
	
	//// Color Profile Initialization
	
	CMGetDefaultProfileBySpace(cmRGBData, &m_dst_profile);

	CMProfileLocation t_location;
	t_location . locType = cmPathBasedProfile;
	strcpy(t_location . u . pathLoc . path, "/System/Library/ColorSync/Profiles/sRGB Profile.icc");
	CMOpenProfile(&m_srgb_profile, &t_location);
	
	////
	
	return True;
}
Beispiel #15
0
void
hashicons (ControlHandle c)
{
/* todo: worry about filenames in FREFs */
  /* get FREF, BNDL, ICN#, ics#, icl8, ics8, icl4, ics4 */
  /* BNDL is:
     4 bytes of signature
     2 bytes of 0 [signature resource id?]
     2 bytes of <number of main entries - 1> (almost always 1)
     numberofmainentries *
     4 bytes of 'ICN#' or 'FREF'
     2 bytes of <number of entries - 1>
     numberofentries *
     2 bytes of localid
     2 bytes of resid
   */
/* todo: see what happens with multiple BNDLs */

  char *p;
  short i, j, spacemade, nummain, numbndls;
  unsigned short hashval;
  iconentry **iconarray;
  icontableentry **node;
  Handle h;
  OSType signature;
  short refnum, sigid;
  unsigned char state;
  applist **ah;

  refnum = openappres (c);
  numbndls = Count1Resources ('BNDL');
  for (i = 1; i <= numbndls; i++)
    {
      h = (Handle) Get1IndResource ('BNDL', i);
      state = HGetState (h);
      HLock (h);
      p = *h;
      signature = *(OSType *) p;
      p += 4;
      sigid = *(short *) p;
      p += 2;

      hashval = (unsigned long) signature % SIGARRAYSIZE;
#define CONTROLPROBLEMS
#ifndef CONTROLPROBLEMS
      for (ah = sigowners[hashval]; ah != 0 && (*ah)->sig != signature; ah = (*ah)->next)
	;
      if (ah == 0)
	{
#endif /* CONTROLPROBLEMS */
	  ah = sigowners[hashval];
	  sigowners[hashval] = (applist **) NewHandle (sizeof (applist));
	  (*sigowners[hashval])->next = ah;
	  (*sigowners[hashval])->parid = (*(item **) (*c)->contrlData)->ioparid;
	  (*sigowners[hashval])->vrefnum = (*(item **) (*c)->contrlData)->vrefnum;
	  (*sigowners[hashval])->sig = signature;
	  mystr255copy ((*sigowners[hashval])->name, (*c)->contrlTitle);
#ifndef CONTROLPROBLEMS
	}
#endif /* CONTROLPROBLEMS */

/* todo: find out if nummain must == 2 */
      nummain = *(short *) p + 1;
      p += 2;

      spacemade = 0;
      for (j = 0; j < nummain; j++)
	{
	  dobundle (&spacemade, &iconarray, &p);
	}

      for (j = 0; j < spacemade; j++)
	{
	  hashval = ((unsigned long) signature + (unsigned long) (*iconarray)[j].type)
	    % ICONTABLESIZE;
	  for (node = icontable[hashval]; node != 0 &&
	       ((*node)->sig != signature || (*node)->type != (*iconarray)[j].type);
	       node = (*node)->next)
	    ;
	  if (node == 0)
	    {
	      node = (icontableentry **) NewHandle (sizeof (icontableentry));
	      (*node)->sig = signature;
	      (*node)->type = (*iconarray)[j].type;
	      (*node)->next = icontable[hashval];
	      geticons (node, (*iconarray)[j].resid);
	      icontable[hashval] = node;
	    }
	}
      DisposHandle ((Handle) iconarray);
      HSetState (h, state);
      ReleaseResource (h);
    }
  CloseResFile (refnum);
}
Beispiel #16
0
void main(fptr *f) {
	long oldA4;
	OSStatus err;
	DateTimeRec date;
	
	oldA4 = SetCurrentA4();
	RememberA4();
	FNS = f;	

#ifdef MULTI_SEGMENT
	/* Multi-segment code resource stuff */
	{
		Str255 buf;
		short i, n, theID;
		char **ch;
		OSType theType;
		n = Count1Resources('Cccc');
	    post("This external has %ld resources", (long) n);
		for (i = 1; i <= n; i++) {
			ch = Get1IndResource('Cccc', i);
			GetResInfo(ch, &theID, &theType, buf);
			rescopy('Cccc', theID);
		}
	}
#endif

#ifdef EXTENDED_CODE_RESOURCE
	// Cause it's an extended code resource...
	// rescopy('Cccc',22222);
#endif

	ps_readbufsize = gensym("readbufsize");
	ps_writebufsize = gensym("writebufsize");
	ps_OTTCP_nbytes = gensym("OTTCP_nbytes");
	ps_OTTCP_delim = gensym("OTTCP_delim");
	ps_connected = gensym("connected");
	ps_disconnected = gensym("disconnected");

	setup(&ottcp_class, ottcp_new, (method) ottcp_free, (short)sizeof(OTTCP), 0L, A_GIMME, 0);
	
	version(0);
#ifdef DAVID_LIKES_EXPIRING_MAX_OBJECTS
	post("Expires %d/%d/%d", MONTH, DAY, YEAR);
#endif

#ifdef DAVID_LIKES_EXPIRING_MAX_OBJECTS
	GetTime(&date);
	if((date.year > YEAR)  || 
       (date.year == YEAR && ((date.month > MONTH) ||
							  (date.month == MONTH && date.day > DAY)))) {
            ouchstring(EXPIRATION_NOTICE);
            goto quit;
    }
#endif
    
    // post ("*** before  InitOpenTransport();");
	err = InitOpenTransport();
	if (err != kOTNoError) {
		ouchstring("Couldn't InitOpenTransport (err %d).  Perhaps Open Transport is not installed.",
					err);
		goto quit;
	}
	
	/* bind methods */
	addmess((method) ottcp_connect, "connect", A_SYM, A_LONG, 0);
	addmess((method) ottcp_disconnect, "disconnect", 0);
	addmess((method) ottcp_read_nbytes, "nbytes", A_LONG, 0);
	addmess((method) ottcp_read_until_delimiter_symbol, "delim", A_SYM, 0);
	addmess((method) ottcp_read_until_delimiter_bytes, "delim-bytes", A_GIMME, 0);
	addmess((method) ottcp_write, "write", A_LONG, A_LONG, 0);
	addmess((method) version, "version", 0);
	addmess((method) ottcp_ErrorReporting, "errorreporting", 0);
	addmess((method) ottcp_tellmeeverything, "tellmeeverything", 0);
	addmess((method) ottcp_assist, "assist", A_CANT, 0);

	finder_addclass("System","ottcp");

quit:
	RestoreA4(oldA4);
}
Beispiel #17
0
// hdll, pluginmain and audiomaster are set here
// must be NULL beforehand!
bool VSTPlugin::NewPlugin(const char *plugname)
{
    FLEXT_ASSERT(!pluginmain && !audiomaster);

    dllname = plugname;

#if FLEXT_OS == FLEXT_OS_WIN
    hdll = LoadLibraryEx(dllname.c_str(),NULL,0 /*DONT_RESOLVE_DLL_REFERENCES*/);
/*
    char buf[255],*c;
    strcpy(buf,dllname.c_str());
    for(c = buf; *c; ++c) 
        if(*c == '/') 
            *c = '\\';
    char *sl = strrchr(buf,'\\');
    if(sl) *sl = 0;
    SetCurrentDirectory(buf);
    hdll = LoadLibrary(dllname.c_str());
*/
    if(hdll) pluginmain = (PVSTMAIN)GetProcAddress(hdll,"main");
    audiomaster = Master;  

#elif FLEXT_OS == FLEXT_OS_MAC

#if 1
	CFStringRef fileNameString = CFStringCreateWithCString(NULL, fileName, kCFStringEncodingUTF8);
	if(fileNameString == 0) goto bail;
	CFURLRef url = CFURLCreateWithFileSystemPath(NULL, fileNameString, kCFURLPOSIXPathStyle, false);
	CFRelease(fileNameString);
	if(url == 0) goto bail;
	hdll = CFBundleCreate(NULL, url);
	CFRelease (url);
	if(hdll && !CFBundleLoadExecutable(hdll)) goto bail;

    PVSTMAIN mainaddr = PluginEntryProc)CFBundleGetFunctionPointerForName(hdll, CFSTR("VSTPluginMain"));
	if(!mainaddr)
		mainaddr = (PluginEntryProc)CFBundleGetFunctionPointerForName(hdll, CFSTR("main_macho"));
#ifdef __CFM__
    pluginmain = (PVSTMAIN)NewMachOFromCFM(mainaddr);
    audiomaster = NewCFMFromMachO(Master);
#else
    pluginmain = (PVSTMAIN)mainaddr;
    audiomaster = Master;
#endif

#else
    short   resFileID;
    FSSpec  spec;
    OSErr err;

    err = FSPathMakeFSSpec(dllname.c_str(),&spec,NULL);
    resFileID = FSpOpenResFile(&spec, fsRdPerm);
    short cResCB = Count1Resources('aEff');

    for(int i = 0; i < cResCB; i++) {
        Handle             codeH;
        CFragConnectionID  connID;
        Ptr                mainAddr;
        Str255             errName;
        Str255             fragName;
        char               fragNameCStr[256];
        short              resID;
        OSType             resType;

        codeH = Get1IndResource('aEff', short(i+1));
        if(!codeH) continue;

        GetResInfo(codeH, &resID, &resType, fragName);
        DetachResource(codeH);
        HLock(codeH);

        err = GetMemFragment(*codeH,
                             GetHandleSize(codeH),
                             fragName,
                             kPrivateCFragCopy,
                             &connID, (Ptr *) & mainAddr, errName);

        if(!err) {
           #ifdef __CFM__
           pluginmain = (PVSTMAIN)NewMachOFromCFM(mainAddr);
           #else
           pluginmain = (PVSTMAIN)mainAddr;
           #endif
        }
    }
    CloseResFile(resFileID);

    audiomaster = 
#ifdef __CFM__
        NewCFMFromMachO(Master);
#else
        Master;
#endif

#endif

#else
#error Platform not supported
#endif    

bail:
    if(pluginmain && audiomaster)
        return true;
    else {
        FreePlugin();
        return false;
    }
}
Beispiel #18
0
   void LoadVSTPlugins()
   {
#ifdef __MACOSX__
      audioMasterCallback audioMasterFPtr =
         (audioMasterCallback)NewCFMFromMachO(audioMaster);
#else
      // What is the corrct way of creating an audioMasterCallback
      // in OS 9/Carbon???
      // audioMasterCallback audioMasterFPtr = NULL; 
      audioMasterCallback audioMasterFPtr = audioMaster;
#endif      

      wxArrayString audacityPathList = wxGetApp().audacityPathList;
      wxArrayString pathList;
      wxArrayString files;
      unsigned int i;
      
      for(i=0; i<audacityPathList.GetCount(); i++) {
         wxString prefix = audacityPathList[i] + wxFILE_SEP_PATH;
         wxGetApp().AddUniquePathToPathList(prefix + "VST",
                                            pathList);
         wxGetApp().AddUniquePathToPathList(prefix + "Plugins",
                                            pathList);
         wxGetApp().AddUniquePathToPathList(prefix + "Plug-Ins",
                                            pathList);
      }

      #ifdef __MACOSX__
      wxGetApp().AddUniquePathToPathList("/Library/Audio/Plug-Ins/VST",
                              pathList);
      wxString vstPath;
      vstPath.Printf("/Users/%s/Library/Audio/Plug-Ins/VST",
                     wxGetenv("USER"));
      wxGetApp().AddUniquePathToPathList(vstPath,
                                         pathList);
      #endif

      wxGetApp().FindFilesInPathList("*", pathList, wxFILE, files);
      
      for(i=0; i<files.GetCount(); i++) {
         short   resFileID;
         FSSpec  spec;
         
         wxMacFilename2FSSpec(FILENAME(files[i]), &spec);
         resFileID = FSpOpenResFile(&spec, fsRdPerm);
         short cResCB = Count1Resources('aEff');

         for (int i = 0; i < cResCB; i++) {
            Handle             codeH;
            CFragConnectionID  connID;
            Ptr                mainAddr;
            Str255             errName;
            Str255             fragName;
            char               fragNameCStr[256];
            short              resID;
            OSType             resType;
            OSErr              err;

            codeH = Get1IndResource('aEff', short(i+1));
            if (!codeH)
               continue;

            GetResInfo(codeH, &resID, &resType, fragName);
            DetachResource(codeH);
            HLock(codeH);

            err = GetMemFragment(*codeH,
                                 GetHandleSize(codeH),
                                 fragName,
                                 kPrivateCFragCopy,
                                 &connID, (Ptr *) & mainAddr, errName);

            if (!err) {
               vstPluginMain   pluginMain;
               AEffect        *theEffect;

               #ifdef __MACOSX__
               pluginMain = (vstPluginMain)NewMachOFromCFM(mainAddr);
               #else
               pluginMain = (vstPluginMain)mainAddr;
               #endif

               theEffect = pluginMain(audioMasterFPtr);

               if (theEffect->magic == kEffectMagic) {
                  
                  memcpy(fragNameCStr, &fragName[1], fragName[0]);
                  fragNameCStr[fragName[0]] = 0;
                  
                  VSTEffect *vst =
                     new VSTEffect(wxString(fragNameCStr), theEffect);
                  Effect::RegisterEffect(vst);
               }

               #ifdef __MACOSX__
               DisposeMachOFromCFM(pluginMain);
               #endif
               
               audacityVSTID++;
            }
         }
         
         CloseResFile(resFileID);

      }
         
#ifdef __MACOSX__
      DisposeCFMFromMachO(audioMasterFPtr);
#endif  //   __MACOSX__
   }
Beispiel #19
0
void main(fptr *f) {
	OSStatus err;
	DateTimeRec date;
	
#ifdef MULTI_SEGMENT
	/* Multi-segment code resource stuff */
	{
		Str255 buf;
		short i, n, theID;
		char **ch;
		OSType theType;
		n = Count1Resources('Cccc');
	    post("This external has %ld resources", (long) n);
		for (i = 1; i <= n; i++) {
			ch = Get1IndResource('Cccc', i);
			GetResInfo(ch, &theID, &theType, buf);
			rescopy('Cccc', theID);
		}
	}
#endif

#ifdef EXTENDED_CODE_RESOURCE
	// Cause it's an extended code resource...
	// rescopy('Cccc',22222);
#endif

	setup((t_messlist **)&otudp_class, (method)otudp_new, (method) otudp_free, (short)sizeof(OTUDP), 0L, A_GIMME, 0);
	
	version(0);
#ifdef DAVID_LIKES_EXPIRING_MAX_OBJECTS
	post("Expires %d/%d/%d", MONTH, DAY, YEAR);
#endif


#ifdef DAVID_LIKES_EXPIRING_MAX_OBJECTS
	GetTime(&date);
	if((date.year > YEAR)  || 
       (date.year == YEAR && ((date.month > MONTH) ||
							  (date.month == MONTH && date.day > DAY)))) {
            ouchstring(EXPIRATION_NOTICE);
            return;
    }
#endif
        
    // post ("*** before  InitOpenTransport();");
	err = InitOpenTransportInContext(kInitOTForExtensionMask, &OTContext);
	if (err != kOTNoError) {
		error("¥ OTUDP: Couldn't InitOpenTransport (err %d).  Perhaps Open Transport is not installed.",
					err);
		return;
	}
	
	/* bind methods */
	addmess((method) otudp_write, "FullPacket", A_LONG, A_LONG, 0);
	addmess((method) version, "version", 0);
	addmess((method) otudp_toggleErrorReporting, "errorreporting", 0);
	addmess((method) otudp_tellmeeverything, "tellmeeverything", 0);
	addmess((method) otudp_old_write, "write", A_GIMME, 0);
	addmess((method) otudp_old_write, "gimme", A_GIMME, 0);
	addmess((method) otudp_assist, "assist", A_CANT, 0);
	addmess((method) otudp_changeHost, "host", A_SYM, A_LONG, 0);
	addmess((method) otudp_changeReceivePort, "receiveport", A_LONG, 0);

	/* These methods are just for debugging. */
	addmess((method) otudp_debugstats, "debugstats", 0);
	addmess((method) otudp_resetdebugstats, "resetdebugstats", 0);
	addmess((method) otudp_read, "readitagainsam", 0);

	finder_addclass("System","otudp");

	ps_read = gensym("read");
	ps_write = gensym("write");
	ps_FullPacket = gensym("FullPacket");
	ps_PartialPacket = gensym("PartialPacket");
	ps_nbufs = gensym("nbufs");
	ps_bufsize = gensym("bufsize");
}
Beispiel #20
0
   void LoadVSTPlugins() {
      wxString home = DirManager::GetHomeDir();
      wxString pathChar = DirManager::GetPathChar();
      wxString vstDirPath = home + pathChar + "vst";
      wxString fname;

      fname =
          wxFindFirstFile((const char *) (vstDirPath + pathChar + "*"));

      while (fname != "") {
         short resID;
         FSSpec spec;

         wxMacFilename2FSSpec(fname, &spec);
         resID = FSpOpenResFile(&spec, fsRdPerm);
         Handle codeH;

         int count = Count1Resources('aEff');
         for (int i = 0; i < count; i++) {
            CFragConnectionID connID;
            Ptr mainAddr;
            Str255 errName;
            Str255 fragName;
            char fragNameCStr[256];
            short resID;
            OSType resType;
            OSErr err;

            codeH = Get1IndResource('aEff', count);
            GetResInfo(codeH, &resID, &resType, fragName);
            DetachResource(codeH);
            HLock(codeH);

            err = GetMemFragment(*codeH,
                                 GetHandleSize(codeH),
                                 fragName,
                                 kPrivateCFragCopy,
                                 &connID, (Ptr *) & mainAddr, errName);

            if (err >= 0) {

               Ptr symbolAddress;
               CFragSymbolClass symbolClass;

               err =
                   FindSymbol(connID, "\pmain", &symbolAddress,
                              &symbolClass);
               if (!err) {
                  vstPluginMain pluginMain = (vstPluginMain) symbolAddress;

                  AEffect *theEffect;

                  theEffect = pluginMain(audioMaster);

                  if (theEffect->magic == kEffectMagic) {

                     memcpy(fragNameCStr, &fragName[1], fragName[0]);
                     fragNameCStr[fragName[0]] = 0;

                     VSTEffect *vst =
                         new VSTEffect(wxString(fragNameCStr), theEffect);
                     Effect::RegisterEffect(vst);
                  }
               }
            } else {
               HUnlock(codeH);
            }

            audacityVSTID++;

            // Don't HUnlock unless you don't want to keep it in memory
         }

         CloseResFile(resID);
         fname = wxFindNextFile();
      }
   }