SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-22-2006, 03:22 AM
sundansx sundansx is offline
Sage Advanced User
 
Join Date: Aug 2003
Posts: 193
Thumbs up coding help

Please help me with my Sage coding problem:
here is a snippet. Most of this is from the Comskip STVI addin.
...
1 pos = GetMediaTime() + 0
2 pos =GetMediaTime()+0
3 num=0
4 num < Size(commercials2) && GetProperty("commercial_auto_skip",false)
5 true
6 location = GetElement(commercials2,num)
7 startdelay_pb = new_java_lang_Integer(GetProperty("commercial_start_delay_ms",1))
8 location = location + startdelay_pb
9 IF (pos > location) && ((pos - 10000) < location) && GetProperty("commercial_auto_skip", false)
10 true
...
11 Seek(location)
12 false
...

I am trying to add a delay to the location value before it is passed to Seek()
Problem is on line 8 that it appears that sage is coverting startdelay_pb to a string and then cat'ting it to location. How do I add these values together (location + startdelay_pb) so it will seek to the correct positon (location + a 1000 ms delay)?
Code syntax examples would be helpful as I am new at this. Thanks very much
-ck
Reply With Quote
  #2  
Old 07-22-2006, 11:45 AM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
Without knowing where commercials2 is coming from, my guess is that it's an array of strings, so that location is already a string on line 6. Try wrapping a new_java_lang_Long() call around the call to GetElement() to see if that helps. (Seek() takes a long as an argument, so you want to use longs, not ints, in your arithmetic.)

When in doubt, use Sage's DebugLog() API to print diagnostic info to the console window for debugging purposes. For instance:

Code:
DebugLog("location is a " + java_lang_Class_getName(java_lang_Object_getClass(location)))
should print out the name of the runtime type of location. To enable the console window, create a DWORD registry value called "consolewin" at HKEY_LOCAL_MACHINE\SOFTWARE\Frey Technologies\Common and set it to 1.

Also, when posting code, use the code tags (the # button on the composition menu) to preserve indentation and improve readability.
__________________
-- Greg
Reply With Quote
  #3  
Old 07-22-2006, 12:05 PM
Narflex's Avatar
Narflex Narflex is offline
Sage
 
Join Date: Feb 2003
Location: Redondo Beach, CA
Posts: 6,349
There's a shortcut that can be used to convert a string that represents a number to an actual numeric type object:

location = location*1 + startdelay_pb

Additions will be converted to string cats if any of the arguments are non-numeric object types. Multiplication (or division, etc.) which don't have a String equivalent will always have their arguments converted to numbers (if possible) and will therefore return a number. so by doing 'location*1' I've converted the location variable into an integer/float and then as long as startdelay_pb is a numeric type then it'll add the numbers together and return a new number. If location can't be converted to a number then there'll be an exception in the evaluator and it'll just return null for the whole expression.

Hope that explains it better.
__________________
Jeffrey Kardatzke
Google
Founder of SageTV
Reply With Quote
  #4  
Old 07-22-2006, 05:34 PM
sundansx sundansx is offline
Sage Advanced User
 
Join Date: Aug 2003
Posts: 193
Thanks for the help. I am still having a problem, tho.
I have now coded:

location = GetElement(commercials2,num)
startdelay_pb = new_java_lang_Long(GetProperty("commercial_start_delay_ms",1))
location = location*1 + startdelay_pb

and further up commercials 2 is instantiated from the line:
commercials2 = java_lang_String_split(commerciallist,"[^0-9\\.]+")
I believe that commerciallist is an array.

but I get the exception as jeffery explained. It appears from the sage docs that GetElement returns a java.lang.object...is that the type for location? Im not quite sure I understand what is going on, since "pos" is a long and a comparison later (line 9) evidently works. Something else interesting is that in the trace pos looks wierd even the trace of line 1. I expected a long in ms printed out, but the trace is a big old "1153288145048" number. Am I seeing the trace report a string representation of a long?

Greg...I will try the debug log to see what else I can find out.

By the way...What am I programming in here? Is it a custom script language for sage derived from Java?
Reply With Quote
  #5  
Old 07-22-2006, 05:45 PM
sundansx sundansx is offline
Sage Advanced User
 
Join Date: Aug 2003
Posts: 193
Jeffery,
Another thing....Is there a way to put a line number indicator at the bottom of the sagestudio window to indicate a line one is working on? I find it difficult sometimes when nothing is expanded or if I want to jump back to a line after studio took me on a wild goose chase while single stepping. Just a suggestion.
Reply With Quote
  #6  
Old 07-22-2006, 07:31 PM
sundansx sundansx is offline
Sage Advanced User
 
Join Date: Aug 2003
Posts: 193
Jeffery and Greg,
I got the console kicking and it is a good resource. Is there a way to print values to the log in a format? like a printf("%d", location);?
tried:
DebugLog("location is a " + java_lang_Class_getName(java_lang_Object_getClass(location)) + " value: " + new_java_lang_Long_toString(location*1))
but I got a Catbert Method Lookup Failure for the toString method.

Also, I got the code to work...thanks to both of you for your help.

Last edited by sundansx; 07-22-2006 at 08:05 PM.
Reply With Quote
  #7  
Old 07-22-2006, 07:35 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
If commericals2 is the result of a call to java_lang_String_split, then it will be an array of strings (as per the Java docs) and its elements will be strings.

GetElement returns an Object, but then everything in Java is an Object at bottom. You need to know what kind of Object (String, Long, etc.) to know how + is going to behave. (Personally I think that overloading + to mean string concatenation was a mistake, since it really has very little to do with the traditional meaning of + and just causes confusion in cases like this where the types are ambiguous. But it seems to be pretty entrenched by now.)

Jeff's location*1 trick is a clever shorthand, but personally I prefer to make sure everything is the correct type in the first place so that tricks like that aren't necessary.

When you say you're new at this, do you mean new to Studio, new to Java, or new to programming in general? If it's one of the latter two, you might want to look at some of the Java tutorials at http://java.sun.com/docs/books/tutorial/java/TOC.html, which cover most of the basics.
__________________
-- Greg
Reply With Quote
  #8  
Old 07-22-2006, 08:14 PM
sundansx sundansx is offline
Sage Advanced User
 
Join Date: Aug 2003
Posts: 193
I am an experienced programmer, but new to Java and sage studio. I am pretty experienced with C++ and OOP in general, so I am picking up the java docs topics without much trouble. I wasn't sure what reference to use when writing the Studio code...is it Java, then? I understand that the java_lang... calls are calls to some java library outside of the UI scripter that allows access to Java language constructs.
I will check out those tutorials.
thanks for your help, I got my code working great, now I will try to make it into an STVi. Looks tricky.
Reply With Quote
  #9  
Old 07-22-2006, 09:20 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
Expressions in Studio code are Java-like, but not pure Java. (For instance there are some differences in the way && and || work.) But whenever you see a java_x_y call, those are calls to the actual Java runtime, as documented in the Java docs. You can also write your own Java packages outside of Studio and call those the same way (e.g. myinstance = new_mypackage_myclass(args) and mypackage_myclass_mymethod(myinstance)).

I don't know if you've figured this out yet, but your problem with new_java_lang_Long_toString is that you have an extraneous new_ on the front of it.
__________________
-- Greg
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 05:46 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.