Creating resource different newbie question 
Author Message
 Creating resource different newbie question

I'm very new to RealBasic & to programing, but I'm learning by trying &
reading.

The documentation on resource Forks is slim, even the examples in
Matt's book fail to give a usage example of CreateResourceFork and the
Language reference wasn't much help.

I am able to create a resource fork on the selected folderitem(s)using

  rf=f.CreateResourceFork("audio/x-sd2")
  rf.AddResource(" 48000"),"STR" ,1001,"sample-rate")
  rf.AddResource(" 2","STR ",1000,"sample-size")
  rf.AddResource(" 1","STR ",1002,"channels")
  rf.close

But when it adds the number ie: " 48000" or " 2" I get a bunch of

if I don't add the space before it the first charachter gets chopped
off ie: the 4 in 48000.

I supose it's because it's a number that I'm sending as a string, but
I'm not sure how else to do it.

I also tried

dim rate as integer
rate = 48000
 rf.AddResource(str(rate),"STR" ,1001,"sample-rate")
but the same thing happens.

Also is there a way to add all that resource info using a single line
as opposed to the 3 lines I use in the example above?

Any info will be greatly appreciated.

Thanks

remove "removethistoreply" to reply via e-mail



Mon, 21 Jul 2003 04:03:18 GMT  
 Creating resource different newbie question

Quote:

> I am able to create a resource fork on the selected folderitem(s)using

>   rf=f.CreateResourceFork("audio/x-sd2")
>   rf.AddResource(" 48000"),"STR" ,1001,"sample-rate")
>   rf.AddResource(" 2","STR ",1000,"sample-size")
>   rf.AddResource(" 1","STR ",1002,"channels")
>   rf.close

> But when it adds the number ie: " 48000" or " 2" I get a bunch of

> if I don't add the space before it the first charachter gets chopped
> off ie: the 4 in 48000.

As judged how?  The syntax is correct (except for the extra ")" in your
48000 line above, and the extra space on the front is not needed).
I've used this and it really does work.  I think you're not viewing the
resources correctly after they're added.

Quote:
> I supose it's because it's a number that I'm sending as a string, but
> I'm not sure how else to do it.

It doesn't matter what the string contains.  (And yes, it must be a
string.)

Quote:
> Also is there a way to add all that resource info using a single line
> as opposed to the 3 lines I use in the example above?

No, one line per resource is what it takes.

Quote:
> remove "removethistoreply" to reply via e-mail

Please don't forge your return address.

Thanks,
- Joe

--
,------------------------------------------------------------------.
|    Joseph J. Strout         Check out the Mac Web Directory:     |

`------------------------------------------------------------------'



Mon, 21 Jul 2003 07:02:54 GMT  
 Creating resource different newbie question

Quote:

> I'm very new to RealBasic & to programing, but I'm learning by trying &
> reading.

> The documentation on resource Forks is slim, even the examples in
> Matt's book fail to give a usage example of CreateResourceFork and the
> Language reference wasn't much help.

I'd suggest looking at the ResEdit reference, which is online somewhere
at Apple's developer site <http://developer.apple.com/>, and not too
hard to find. Check out the list of resource types at the end, to see
what the different types are.

Quote:
> I am able to create a resource fork on the selected folderitem(s)using

>   rf=f.CreateResourceFork("audio/x-sd2")
>   rf.AddResource(" 48000"),"STR" ,1001,"sample-rate")
>   rf.AddResource(" 2","STR ",1000,"sample-size")
>   rf.AddResource(" 1","STR ",1002,"channels")
>   rf.close

> But when it adds the number ie: " 48000" or " 2" I get a bunch of

> if I don't add the space before it the first charachter gets chopped
> off ie: the 4 in 48000.

> I supose it's because it's a number that I'm sending as a string, but
> I'm not sure how else to do it.

First of all, you want to test if the resource fork was actually opened,
like this:

rf=f.CreateResourceFork("file type")
if rf <> nil then // rf will be nil if the fork wasn't opened
  // work on the resource fork here
end if

If you don't do this, you'll likely end up with a NilObjectException
eventually. Also, it might be worth your while to test if the resource
fork in question is already open, with Thomas Tempelmann's FileManager
plugin <http://www.tempel.org/>.

Secondly, you're using the 'STR ' resource type, which is a Pascal
string (or pstring), meaning the first byte of data tells how long the
string is. That's why you have to include the space at the beginning;
you're unintentionally faking the size byte with it. Since ASCII for a
space is 32, it's returning 32 bytes of data, which includes both
"48000" and whatever's in memory after it.

I'd suggest using another resource type, such as TEXT, or your own data
type.

Quote:
> Also is there a way to add all that resource info using a single line
> as opposed to the 3 lines I use in the example above?

Not if the three items have different ID numbers. You could make your
own resource type, like, say, 'saDa' (for sample data), and make a
string like "48000 2 1", write that, and then parse it when you need to
read it:

rf.addresource("48000 2 1","saDa",128,"sample data")
parseSampleData(rf.getresource("saDa",128))

Quote:
> Any info will be greatly appreciated.

> Thanks

HTH.

--
"In a world full of lies / Which tug at the truth
 I'm taking no sides.. Now I recognize you." -DS
"Embrace the darkness or killfile it." -Paghat



Mon, 21 Jul 2003 07:14:47 GMT  
 Creating resource different newbie question

Quote:



> > I am able to create a resource fork on the selected folderitem(s)using

> >   rf=f.CreateResourceFork("audio/x-sd2")
> >   rf.AddResource(" 48000","STR" ,1001,"sample-rate")
> >   rf.AddResource(" 2","STR",1000,"sample-size")
> >   rf.AddResource(" 1","STR",1002,"channels")
> >   rf.close

> > But when it adds the number ie: " 48000" or " 2" I get a bunch of

> > if I don't add the space before it the first charachter gets chopped
> > off ie: the 4 in 48000.

> As judged how?  The syntax is correct (except for the extra ")" in your
> 48000 line above, and the extra space on the front is not needed).
> I've used this and it really does work.  I think you're not viewing the
> resources correctly after they're added.

Thanks for the reply.

While I am new to programming I am very experienced with resources &
resedit. The proof of the pudding is in the eating, after creating
resources this way the file doesn't work. I get an error that says
"invalid bit specification"

I am opening the file with resedit or resorcerer after they have been
created on files that had none before. The resources are there, they
are all correct except for the extra stuff that gets stuck in where the
value is. And I promise when I run it without the space before the
number or text it cuts off the first Character. I have tried it more
than a few times. I took out the extra ) and it still does it.

The example with the garbage in it  above is pasted directly from
resorcerer.

The interesting thing is that in  ResEdit the normal resource editor
doesn't see junk but you can see a difference between it & a normal
file using resEdit's hex editor. Resorcerer displays the extra stuff in
it's resource editor, if I then delete the values with either
resorcerer or Resedit & type in the values by hand the file works fine.
So the resource fork & the resources are created properly it's just the
string that gets placed in the particular resource that is getting
stuck in wrong.

Quote:
> > remove "removethistoreply" to reply via e-mail

> Please don't forge your return address.

I didn't realize that adding something to block spam was forging. But
if it's not done in this newsgroup how do you stop the spammers from
automatically collecting your e-mail address?

Any help will be greatly appreciated.

Thanks

remove "removethistoreply" to reply via e-mail



Mon, 21 Jul 2003 08:37:22 GMT  
 Creating resource different newbie question

Quote:
> Secondly, you're using the 'STR ' resource type, which is a pascal
> string (or pstring), meaning the first byte of data tells how long the
> string is. That's why you have to include the space at the beginning;
> you're unintentionally faking the size byte with it. Since ASCII for a
> space is 32, it's returning 32 bytes of data, which includes both
> "48000" and whatever's in memory after it.

Ahh, so how do I tell it properly?

Quote:
> I'd suggest using another resource type, such as TEXT, or your own data
> type.

I can't the whole purpose of this is a utility to replace resource
forks on Sound Designer 2 audio files, the type ProTools uses, which
have been stripped off. I need to create exactly a resource fork with a
STR resource with those values & IDs.

Thanks

remove "removethistoreply" to reply via e-mail



Mon, 21 Jul 2003 08:48:27 GMT  
 Creating resource different newbie question

[..]

Quote:
> > I'd suggest using another resource type, such as TEXT, or your own data
> > type.

> I can't the whole purpose of this is a utility to replace resource forks
> on Sound Designer 2 audio files, the type ProTools uses, which have been
> stripped off. I need to create exactly a resource fork with a STR resource
> with those values & IDs.

Aha! Then you need to create pstrings for the numbers, like this:

dim s as string
s = "48000"
s = chr(lenb(s)) + s

There might even be a pstring type coercion function somewhere within
RB, but I don't know it offhand.

Hand s off to AddResource as the data, as in:

rf.AddResource(s,"STR ",1001,"sample-rate")

HTH.

--
"In a world full of lies / Which tug at the truth
 I'm taking no sides.. Now I recognize you." -DS
"Embrace the darkness or killfile it." -Paghat



Mon, 21 Jul 2003 17:19:52 GMT  
 Creating resource different newbie question
[[ This message was both posted and mailed: see
   the "To," "Cc," and "Newsgroups" headers for details. ]]


Woo hoo, it worked, thank you. I don't know if you can remember back
when you started programming, that happy feeling when you finally get
something to work right. I've go that right now.

Thank you thank you

-Ezra-

Quote:

> [..]
> > > I'd suggest using another resource type, such as TEXT, or your own data
> > > type.

> > I can't the whole purpose of this is a utility to replace resource forks
> > on Sound Designer 2 audio files, the type ProTools uses, which have been
> > stripped off. I need to create exactly a resource fork with a STR resource
> > with those values & IDs.

> Aha! Then you need to create pstrings for the numbers, like this:

> dim s as string
> s = "48000"
> s = chr(lenb(s)) + s

> There might even be a pstring type coercion function somewhere within
> RB, but I don't know it offhand.

> Hand s off to AddResource as the data, as in:

> rf.AddResource(s,"STR ",1001,"sample-rate")

> HTH.



Tue, 22 Jul 2003 03:35:36 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Stupid question (creating a sequence of *different* objects)

2. Newbie Oberon Question (Different Guy)

3. Digilab 10K10 Resources / Samples & Newbie Questions

4. Newbie Question--How do I create an executable program from VW

5. Newbie question - can I create DB Views?

6. Newbie question: creating dll without the need of CVF 6.6 Runtime library

7. Creating a file - newbie question

8. newbie question: create directories with open

9. Newbie Question (Was: Newbie Question...)

10. Creating a memory dump display with different colors.

11. Creating resources in files without one

12. Creating a resource fork

 

 
Powered by phpBB® Forum Software