Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 706
  • Last Modified:

c++ over riding...

I have a class that I am over riding.  I have discovered that by overriding only one funtion, I have over riden them all.  I am not a c++ expert so I need some help fixing this.  

The orginal names space follows.  The next post will be the new overriding namespace
0
makman111
Asked:
makman111
2 Solutions
 
makman111Author Commented:
Original namespace:

//////////////////////////////////////////////////////////////////////////
//
// VirtualDJ / Cue
// Plugin SDK
// (c)Atomix Productions 2006
//
//////////////////////////////////////////////////////////////////////////
//
// This file defines the external-device custom mapper plugins.
// In addition to all the elements supported from the base IVdjPlugin class,
// it defines additional device-specific functions and variables:
//
//////////////////////////////////////////////////////////////////////////


#ifndef VdjDeviceH
#define VdjDeviceH

#include "VdjPlugin.h"

struct TVdjDeckInfo;

//////////////////////////////////////////////////////////////////////////
// VdjDevice plugin class

class IVdjPluginDevice : public IVdjPlugin
{
public:
      // You must implement this function and return the device type for which this
      // plugin has been written.
      virtual HRESULT __stdcall GetDeviceType(int *type)=0;

      // called when device is initialized
      virtual HRESULT __stdcall OnReset() {return 0;}

      // This function is called each time a button is pressed or depressed
      // (return E_NOTIMPL if you want VirtualDJ to use the default mapper)
      virtual HRESULT __stdcall OnButton(int chan,int button,int down) {return 0;}
      // This function is called each time a knob or slider is moved.
      // absvalue is the absolute position of the slider between 0 and 4096 included.
      // relvalue is the relative movement of this slider, on the same scale.
      virtual HRESULT __stdcall OnSlider(int chan,int slider,int absvalue,int relvalue)
      // This function is called on devices that are compatible with low-latency scratch.
      // return S_OK and VirtualDJ will apply a low-latency scratch automatically.
      // return S_FALSE and OnSlider() will be called the regular way.
      {return 0;}

      virtual HRESULT __stdcall OnScratch(int chan,int *value) {return 0;}

      // This function is called once every 100ms, letting you update the LEDs on the device
      virtual HRESULT __stdcall OnTimer() {return 0;} // 100 ms
      // Call these functions to update the LEDs and display on the device.
      HRESULT (__stdcall *SetLed)(int chan,int n,int value);
      HRESULT (__stdcall *SetDigit)(int chan,int n,int value);
      HRESULT (__stdcall *SetText)(int chan,int n,char *value);
      // This structure gives you direct access to common information useful for LED status.
      // You can call GetInfo() if you need other less common datas.
      TVdjDeckInfo *DeckInfo[2];
      // Leds and Digits sends are buffered. If you need to flush the buffer, use this:
      HRESULT (__stdcall *CommitSends)();

      // An alternative to SendCommand, that lets you specify up and down status (for compat. with previous SDK)
      HRESULT (__stdcall *SendAction)(char *action,char *chan,char *param,int down);

      // extension function and variable for specific-device needs
      void *DeviceSpecificVar;
      HRESULT (__stdcall *DeviceSpecificCall)(int cmd,int param1,void *param2);
};

//////////////////////////////////////////////////////////////////////////
// Structures declarations

struct TVdjDeckInfo
{
      int StructSize; // =72 in current version. Might be expanded in the future
      int Position; // position in number of samples since begining
      int Length; // total number of samples in song (1 sample = 1/44100 second)
      int Status;
      int Playing;
      int Bpm;
      int Pitch;
      int PitchReset;
      int PitchMin,PitchMax;
      int Loop;
      int LoopLength;
      int CuePos,CuePos2,CuePos3;
      int BeatLed;
      int BeatLocked;
      int AutoMix;
      int MixNow;
      int Selected;
      int BassKill,MediumKill,HighKill;
};

//////////////////////////////////////////////////////////////////////////
// Common defines

#define PLUGINDEVICE_XP10                  1
#define PLUGINDEVICE_DJCONSOLE            2
#define PLUGINDEVICE_DMC1                  3
#define PLUGINDEVICE_DVINYL                  4
#define PLUGINDEVICE_DAC3                  5
#define PLUGINDEVICE_BCD2000      6
#define PLUGINDEVICE_ICDX                  7
#define PLUGINDEVICE_DMC2                  8
#define PLUGINDEVICE_TOTALCONTROL      9
#define PLUGINDEVICE_ICUE                  10

//////////////////////////////////////////////////////////////////////////
// GUID definitions

#ifndef VDJDEVICEGUID_DEFINED
#define VDJDEVICEGUID_DEFINED
static const GUID IID_IVdjPluginDevice = { 0xc17ed55e, 0x76b2, 0x4fb7, { 0x99, 0x34, 0xbb, 0xb1, 0xaf, 0xcd, 0x8c, 0x7b } };
#else
extern static const GUID IID_IVdjPluginDevice;
#endif

//////////////////////////////////////////////////////////////////////////

#endif
0
 
makman111Author Commented:
Over riding namespace:

#define _CRT_SECURE_NO_WARNINGS
#define WIN32_LEAN_AND_MEAN

#include <windows.h>
//#include <stdio.h>
#include "stdafx.h"
#include "KC0Mapper.h"
#include "VdjPlugin.h"
#include "vdjDevice.h"

// Mapper class

class KC0DefaultMapper:public IVdjPluginDevice
{
      public:
      KC0DefaultMapper();

      HRESULT __stdcall GetDeviceType(int *type);
      HRESULT __stdcall OnGetPluginInfo(TVdjPluginInfo *infos);
      HRESULT __stdcall OnSlider(int chan,int slider,int absvalue,int relvalue);

};
KC0DefaultMapper::KC0DefaultMapper()  {}
// Set device type
HRESULT KC0DefaultMapper::GetDeviceType(int *type)
{
      *type = PLUGINDEVICE_TOTALCONTROL;
      return(PLUGINDEVICE_TOTALCONTROL);
}


HRESULT KC0DefaultMapper::OnSlider(int chan,int slider,int absvalue,int relvalue)
{
      char cmd[32];

      switch(slider)
      {
            case KC0_SLID_CROSSFADER:
            wsprintf(cmd,"video_crossfade %d",absvalue);
            SendCommand(cmd,chan);
            break;
      }
      return 0;
}

// Return information about plugin
HRESULT KC0DefaultMapper::OnGetPluginInfo(TVdjPluginInfo *infos)
{
      static char st[128];

      infos->PluginName = ".";
      infos->Author = ".";
      infos->Description = ".";
      infos->Flag = 0;

      infos->Bitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(100));

      return S_OK;
}

//-----------------------------------------------------------------------------
HRESULT __stdcall DllGetClassObject(const GUID &rclsid,const GUID &riid,void** ppObject)
{
      if(memcmp(&rclsid,&CLSID_VdjPlugin,sizeof(GUID))!=0) return CLASS_E_CLASSNOTAVAILABLE;
            if(memcmp(&riid,&IID_IVdjPluginDevice,sizeof(GUID))!=0) return CLASS_E_CLASSNOTAVAILABLE;
                  *ppObject=new KC0DefaultMapper();
      return NO_ERROR;
}
//-----------------------------------------------------------------------------
0
 
sjith2000Commented:
>>>>>>I have discovered that by overriding only one funtion, I have over riden them all.
What I understand from this statement is that you are mentioning about the function GetDeviceType(int *type).
The class IVdjPluginDevice is an abstract class because of the presence of the pure virtual function
virtual HRESULT __stdcall GetDeviceType(int *type)=0;
When you derive the class KC0DefaultMapper from the class IVdjPluginDevice, definitely you have to override the function GetDeviceType(int *type) in the class KC0DefaultMapper.Otherwise KC0DefaultMapper will also become an abstract class and we can't create an object of KC0DefaultMapper. But it doesn't mean that all the virtual functions like OnReset(),OnButton(int chan,int button,int down) are also overridden.If those are to be overridden in the class KC0DefaultMapper, you have to override them separately in the derived class.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
makman111Author Commented:
Close...  Maybe I did not explain myself precisely

My intention is to overide KC0DefaultMapper::OnSlider ONLY.  I want the rest of the fucntions (subs) to be called from the base class as normal - however, this is not happening.

To add to the complexity, I only want KC0DefaultMapper::OnSlider to be overridden when switch(slider) = case KC0_SLID_CROSSFADER.  Otherwise proceed with KC0DefaultMapper::OnSlider as normal.
0
 
sjith2000Commented:
As per your requirement, you can override the function KC0DefaultMapper::OnSlider in the derived class.Also you can call the base class version of the function OnSlider using the function call IVdjPluginDevice::OnSlider(int chan,int slider,int absvalue,int relvalue) in the derived class.

Also since GetDeviceType(int *type) is a pure virtual function that has to be overridden.

Other functions like OnReset() will be called the base class version since they are not overridden.




0
 
itsmeandnobodyelseCommented:
>>>> I want the rest of the fucntions (subs) to be called
>>>> from the base class as normal - however, this is not happening.

Don't think you are right. There are OnReset, OnButton, OnTimer which have a baseclass implementations. In case you do *not* override these functions in KC0DefaultMapper class, the baseclass functions are called (if there is any call at all). As sjith2000 already told you can overide the virtual functions and call the baseclass function there

      HRESULT KC0DefaultMapper::OnButton(int chan,int button,int down)
     {  
           return IVdjPluginDevice(chan, button, down);
     }

so it doesn't make much sense.

>>>> My intention is to overide KC0DefaultMapper::OnSlider ONLY

      HRESULT KC0DefaultMapper::OnSlider(int chan,int slider,int absvalue,int relvalue)
     {  
           if (slider == KC0_SLID_CROSSFADER)
           {
                  // handle  the case here
                  ....
                  return ...;
           }
           else
                  return IVdjPluginDevice(chan, slider, absvalue, relvalue);
     }

You even could call the baseclass function additionally at begin (if you need some kind of default or initialization) or at end (if your function had made some preparations and the final things were done in the baseclass).


Regards, Alex
0
 
pranabnaikCommented:
Try this
switch(slider)
      {
            case KC0_SLID_CROSSFADER:
            wsprintf(cmd,"video_crossfade %d",absvalue);
            SendCommand(cmd,chan);
            break;
            default :
            DerivedclassPointer->IVdjPluginDevice ::OnSlider(values)
            break;
      }
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now