gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog server/asobj/ASSound.cpp server...


From: Tomas Groth
Subject: [Gnash-commit] gnash ChangeLog server/asobj/ASSound.cpp server...
Date: Mon, 12 Feb 2007 17:35:51 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Tomas Groth <tgc>       07/02/12 17:35:51

Modified files:
        .              : ChangeLog 
        server/asobj   : ASSound.cpp ASSound.h Global.cpp 

Log message:
        * server/asobj/ASSound.{cpp,h}, server/asobj/Global.cpp: Updated the
          AS Sound class to the new init method.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2329&r2=1.2330
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/ASSound.cpp?cvsroot=gnash&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/ASSound.h?cvsroot=gnash&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/Global.cpp?cvsroot=gnash&r1=1.42&r2=1.43

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2329
retrieving revision 1.2330
diff -u -b -r1.2329 -r1.2330
--- ChangeLog   12 Feb 2007 14:18:42 -0000      1.2329
+++ ChangeLog   12 Feb 2007 17:35:51 -0000      1.2330
@@ -1,3 +1,8 @@
+2007-02-12 Tomas Groth Christensen <address@hidden>
+
+       * server/asobj/ASSound.{cpp,h}, server/asobj/Global.cpp: Updated the
+         AS Sound class to the new init method.
+
 2007-02-12 Sandro Santilli <address@hidden>
 
        * server/sprite_instance.{cpp,h}: reverted

Index: server/asobj/ASSound.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/ASSound.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- server/asobj/ASSound.cpp    18 Jan 2007 22:53:21 -0000      1.7
+++ server/asobj/ASSound.cpp    12 Feb 2007 17:35:51 -0000      1.8
@@ -26,12 +26,33 @@
 #include "movie_definition.h"
 #include "sprite_instance.h"
 #include "fn_call.h"
+#include "GnashException.h"
+#include "builtin_function.h"
 
 #include <string>
 
 namespace gnash {
 
-Sound::Sound() {
+static void sound_new(const fn_call& fn);
+static void sound_attachsound(const fn_call& fn);
+static void sound_getbytesloaded(const fn_call& fn);
+static void sound_getbytestotal(const fn_call& fn);
+static void sound_getpan(const fn_call& fn);
+static void sound_gettransform(const fn_call& fn);
+static void sound_getvolume(const fn_call& fn);
+static void sound_loadsound(const fn_call& fn);
+static void sound_setpan(const fn_call& fn);
+static void sound_settransform(const fn_call& fn);
+static void sound_setvolume(const fn_call& fn);
+static void sound_start(const fn_call& fn);
+static void sound_stop(const fn_call& fn);
+static as_object* getSoundInterface();
+
+Sound::Sound()         :
+       as_object(getSoundInterface()),
+       soundName(""),
+       soundId(-1)
+{
 }
 
 Sound::~Sound() {
@@ -39,9 +60,10 @@
 
 
 void
-Sound::attachSound()
+Sound::attachSound(int si, const char* name)
 {
-    log_msg("%s:unimplemented \n", __FUNCTION__);
+       soundId = si;
+       soundName = name;
 }
 
 void
@@ -68,16 +90,24 @@
     log_msg("%s:unimplemented \n", __FUNCTION__);
 }
 
-void
+int
 Sound::getVolume()
 {
-    log_msg("%s:unimplemented \n", __FUNCTION__);
+       int volume = 0;
+       sound_handler* s = get_sound_handler();
+       if (s != NULL)
+       {
+               volume = s->get_volume(soundId);
+       }
+       return volume;
 }
 
 void
-Sound::loadSound()
+Sound::loadSound(std::string /*file*/, bool /*streaming*/)
 {
-    log_msg("%s:unimplemented \n", __FUNCTION__);
+    log_msg("%s is still testing!! \n", __FUNCTION__);
+
+
 }
 
 void
@@ -93,62 +123,75 @@
 }
 
 void
-Sound::setVolume()
+Sound::setVolume(int volume)
 {
-    log_msg("%s:unimplemented \n", __FUNCTION__);
+       // sanity check
+       if (volume >= 0 && volume <=100)
+       {
+               sound_handler* s = get_sound_handler();
+               if (s != NULL)
+               {
+                       s->set_volume(soundId, volume);
+               }
+       }
 }
 
 void
-Sound::start()
+Sound::start(int offset, int loops)
 {
-    log_msg("%s:unimplemented \n", __FUNCTION__);
+           sound_handler* s = get_sound_handler();
+           if (s) s->play_sound(soundId, loops, offset, 0, NULL);
+    
 }
 
 void
-Sound::stop()
+Sound::stop(int si)
 {
-    log_msg("%s:unimplemented \n", __FUNCTION__);
+
+       sound_handler* s = get_sound_handler();
+       if (s != NULL)
+       {
+           if (si > -1) {
+                       s->stop_sound(soundId);
+               } else {
+                       s->stop_sound(si);
+               }
+       }
 }
 
 void
 sound_new(const fn_call& fn)
 {
-    sound_as_object *sound_obj = new sound_as_object;
-
-    sound_obj->init_member("attachSound", &sound_attachsound);
-    sound_obj->init_member("getBytesLoaded", &sound_getbytesloaded);
-    sound_obj->init_member("getBytesTotal", &sound_getbytestotal);
-    sound_obj->init_member("getPan", &sound_getpan);
-    sound_obj->init_member("getTransform", &sound_gettransform);
-    sound_obj->init_member("getVolume", &sound_getvolume);
-    sound_obj->init_member("loadSound", &sound_loadsound);
-    sound_obj->init_member("setPan", &sound_setpan);
-    sound_obj->init_member("setTransform", &sound_settransform);
-    sound_obj->init_member("setVolume", &sound_setvolume);
-    sound_obj->init_member("start", &sound_start);
-    sound_obj->init_member("stop", &sound_stop);
+       Sound *sound_obj = new Sound;
 
     fn.result->set_as_object(sound_obj);
 }
 
+// Wrapper around dynamic_cast to implement user warning.
+// To be used by builtin properties and methods.
+static Sound*
+ensure_sound(as_object* obj)
+{
+       Sound* ret = dynamic_cast<Sound*>(obj);
+       if ( ! ret )
+       {
+               throw ActionException("builtin method or gettersetter for Sound 
objects called against non-Sound instance");
+       }
+       return ret;
+}
+
 void
 sound_start(const fn_call& fn)
 {
     log_action("-- start sound \n");
-    sound_handler* s = get_sound_handler();
-               if (s != NULL)
-               {
+       Sound* so = ensure_sound(fn.this_ptr);
                        int loop = 0;
                        int secondOffset = 0;
-                       if (fn.nargs > 0)
-                       {
-                               int secondOffset = (int) fn.arg(0).to_number();
 
-                               // sanity check
-                               secondOffset = secondOffset <= 0 ? 0 : 
secondOffset;
+       if (fn.nargs > 0) {
+               secondOffset = (int) fn.arg(0).to_number();
 
-                               if (fn.nargs > 1)
-                               {
+               if (fn.nargs > 1) {
                                        loop = (int) fn.arg(1).to_number() - 1;
 
                                        // -1 means infinite playing of sound
@@ -156,11 +199,7 @@
                                        loop = loop < 0 ? -1 : loop;
                                }
                        }
-
-                       sound_as_object*        so = (sound_as_object*) 
(as_object*) fn.this_ptr;
-                       assert(so);
-                       s->play_sound(so->sound_id, loop, secondOffset, 0, 
NULL);
-               }
+       so->start(secondOffset, loop);
 
 }
 
@@ -168,13 +207,38 @@
 sound_stop(const fn_call& fn)
 {
     log_action("-- stop sound \n");
-    sound_handler* s = get_sound_handler();
-    if (s != NULL)
+       Sound* so = ensure_sound(fn.this_ptr);
+
+       int si = -1;
+
+       if (fn.nargs > 0) {
+               const char* name = fn.arg(0).to_string();
+
+               // check the import.
+               movie_definition* def = 
fn.env->get_target()->get_root_movie()->get_movie_definition();
+               assert(def);
+               boost::intrusive_ptr<resource> res = 
def->get_exported_resource(name);
+               if (res == NULL)
        {
-           sound_as_object*    so = (sound_as_object*) (as_object*) 
fn.this_ptr;
-           assert(so);
-           s->stop_sound(so->sound_id);
+                   log_error("import error: resource '%s' is not exported\n", 
name);
+                   return;
        }
+
+               sound_sample_impl* ss = (sound_sample_impl*) 
res->cast_to_sound_sample();
+
+               if (ss != NULL)
+               {
+                   si = ss->m_sound_handler_id;
+               }
+               else
+               {
+                   log_error("sound sample is NULL\n");
+                   return;
+               }
+
+       }
+       so->stop(si);
+
 }
 
 void
@@ -187,19 +251,21 @@
            return;
        }
 
-    sound_as_object*   so = (sound_as_object*) (as_object*) fn.this_ptr;
-    assert(so);
+       Sound* so = ensure_sound(fn.this_ptr);
 
     const char* name = fn.arg(0).to_string();
-    if ( name ) so->sound = name;
+    if (!name) {
+               log_error("attachSound need a non-null argument\n");
+               return;
+       }
 
     // check the import.
     movie_definition* def = 
fn.env->get_target()->get_root_movie()->get_movie_definition();
     assert(def);
-    boost::intrusive_ptr<resource> res = 
def->get_exported_resource(so->sound.c_str());
+    boost::intrusive_ptr<resource> res = 
def->get_exported_resource(so->soundName.c_str());
     if (res == NULL)
        {
-           log_error("import error: resource '%s' is not exported\n", 
so->sound.c_str());
+           log_error("import error: resource '%s' is not exported\n", 
so->soundName.c_str());
            return;
        }
 
@@ -218,7 +284,7 @@
 
     // sanity check
     assert(si >= 0 && si < 1000);
-    so->sound_id = si;
+    so->attachSound(si, name);
 }
 
 void
@@ -248,14 +314,13 @@
 void
 sound_getvolume(const fn_call& fn)
 {
-       sound_handler* s = get_sound_handler();
-       if (s != NULL)
-       {
-               sound_as_object*        so = (sound_as_object*) (as_object*) 
fn.this_ptr;
-               assert(so);
-               int volume = s->get_volume(so->sound_id);
+
+       Sound* so = ensure_sound(fn.this_ptr);
+
+       int volume = so->getVolume();
+
     fn.result->set_int(volume);
-       }
+
        return;
 }
 
@@ -286,19 +351,95 @@
                return;
        }
                
+       Sound* so = ensure_sound(fn.this_ptr);  
        int volume = (int) fn.arg(0).to_number();
 
-       // sanity check
-       if (volume >= 0 && volume <=100)
-       {
-               sound_handler* s = get_sound_handler();
-               if (s != NULL)
+       so->setVolume(volume);
+}
+
+void
+sound_duration(const fn_call& /*fn*/)
+{
+       log_msg("%s:unimplemented \n", __FUNCTION__);
+}
+
+void
+sound_ID3(const fn_call& /*fn*/)
+{
+       log_msg("%s:unimplemented \n", __FUNCTION__);
+}
+
+void
+sound_position(const fn_call& /*fn*/)
+{
+       log_msg("%s:unimplemented \n", __FUNCTION__);
+}
+
+void
+attachSoundInterface(as_object& o)
+{
+
+       o.init_member("attachSound", &sound_attachsound);
+       o.init_member("getBytesLoaded", &sound_getbytesloaded);
+       o.init_member("getBytesTotal", &sound_getbytestotal);
+       o.init_member("getPan", &sound_getpan);
+       o.init_member("getTransform", &sound_gettransform);
+       o.init_member("getVolume", &sound_getvolume);
+       o.init_member("loadSound", &sound_loadsound);
+       o.init_member("setPan", &sound_setpan);
+       o.init_member("setTransform", &sound_settransform);
+       o.init_member("setVolume", &sound_setvolume);
+       o.init_member("start", &sound_start);
+       o.init_member("stop", &sound_stop);
+
+       // Properties
+
+       boost::intrusive_ptr<builtin_function> gettersetter;
+
+       gettersetter = new builtin_function(&sound_duration, NULL);
+       o.init_property("duration", *gettersetter, *gettersetter);
+
+       gettersetter = new builtin_function(&sound_ID3, NULL);
+       o.init_property("ID3", *gettersetter, *gettersetter);
+
+       gettersetter = new builtin_function(&sound_position, NULL);
+       o.init_property("position", *gettersetter, *gettersetter);
+
+}
+
+static as_object*
+getSoundInterface()
+{
+
+       static boost::intrusive_ptr<as_object> o;
+       if ( o == NULL )
                {
-                       sound_as_object*        so = (sound_as_object*) 
(as_object*) fn.this_ptr;
-                       assert(so);
-                       s->set_volume(so->sound_id, volume);
+               o = new as_object();
+               attachSoundInterface(*o);
                }
+
+       return o.get();
+}
+
+// extern (used by Global.cpp)
+void sound_class_init(as_object& global)
+{
+
+       // This is going to be the global Sound "class"/"function"
+       static boost::intrusive_ptr<builtin_function> cl;
+
+       if ( cl == NULL )
+       {
+               cl=new builtin_function(&sound_new, getSoundInterface());
+               // replicate all interface to class, to be able to access
+               // all methods as static functions
+               attachSoundInterface(*cl);
+                    
        }
+
+       // Register _global.String
+       global.init_member("Sound", cl.get());
+
 }
 
 } // end of gnash namespace

Index: server/asobj/ASSound.h
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/ASSound.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- server/asobj/ASSound.h      3 Nov 2006 14:03:37 -0000       1.4
+++ server/asobj/ASSound.h      12 Feb 2007 17:35:51 -0000      1.5
@@ -25,58 +25,45 @@
 
 #include "impl.h"
 #include "as_object.h" // for inheritance 
+#include "NetConnection.h"
 
 namespace gnash {
 
 // Forward declarations
 class fn_call;
   
-class Sound {
+class Sound : public as_object {
 public:
     Sound();
     ~Sound();
-   void attachSound();
+       void attachSound(int si, const char* name);
    void getBytesLoaded();
    void getBytesTotal();
    void getPan();
    void getTransform();
-   void getVolume();
-   void loadSound();
+       int getVolume();
+       void loadSound(std::string file, bool streaming);
    void setPan();
    void setTransform();
-   void setVolume();
-   void start();
-   void stop();
+       void setVolume(int volume);
+       void start(int offset, int loops);
+       void stop(int si);
+
+       std::string soundName;
 private:
     bool _duration;
     bool _id3;
     bool _onID3;
     bool _onLoad;
-    bool _onomplete;
+       bool _onComplete;
     bool _position;
-};
+       NetConnection* connection;
 
-class sound_as_object : public as_object
-{
-public:
-    //Sound obj;
-    std::string sound;
-    int sound_id;
+       int soundId;
+       bool externalSound;
 };
 
-void sound_new(const fn_call& fn);
-void sound_attachsound(const fn_call& fn);
-void sound_getbytesloaded(const fn_call& fn);
-void sound_getbytestotal(const fn_call& fn);
-void sound_getpan(const fn_call& fn);
-void sound_gettransform(const fn_call& fn);
-void sound_getvolume(const fn_call& fn);
-void sound_loadsound(const fn_call& fn);
-void sound_setpan(const fn_call& fn);
-void sound_settransform(const fn_call& fn);
-void sound_setvolume(const fn_call& fn);
-void sound_start(const fn_call& fn);
-void sound_stop(const fn_call& fn);
+void sound_class_init(as_object& global);
 
 } // end of gnash namespace
 

Index: server/asobj/Global.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/Global.cpp,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -b -r1.42 -r1.43
--- server/asobj/Global.cpp     9 Feb 2007 09:34:56 -0000       1.42
+++ server/asobj/Global.cpp     12 Feb 2007 17:35:51 -0000      1.43
@@ -18,7 +18,7 @@
 
 // Implementation of the Global ActionScript Object
 
-/* $Id: Global.cpp,v 1.42 2007/02/09 09:34:56 strk Exp $ */
+/* $Id: Global.cpp,v 1.43 2007/02/12 17:35:51 tgc Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -436,7 +436,7 @@
        boolean_class_init(*this);
        color_class_init(*this);
        selection_class_init(*this); // Selection
-       init_member("Sound", as_value(sound_new));
+       sound_class_init(*this);
        init_member("XMLSocket", as_value(xmlsocket_new));
        date_class_init(*this);
        xml_class_init(*this);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]