-
January 6th, 2012, 10:35 AM
#1
Please help Inheritance Problems
Sorry if this is a beginner topic and ive posted it in the wrong place, I am a complete begginer. I'm using Juce and want to make a load button class but having trouble getting it to inherit from a class like FileChooser so i can use it to select an audio file. Can someone point me in the write direction i'm really struggling to understand JUCE api documentation and topics like pointers.
here is the cpp and h sections of my load button so far which ive succesfully managed to build and make clickable to callback function which prints hello world. can anyone code me a callback function which loads in an audio file or just a file as a starting point.
#ifndef H_BUTTON
#define H_BUTTON
#include <juce.h>
#include "LoadButton.h"
/**
play button component for the applicaiton
*/
class LoadButton : public TextButton,
public Button::Listener
{
public:
//==============================================================================
/**
Constructor
*/
LoadButton();
/**
Destructor
*/
~LoadButton();
void buttonClicked (Button* button);
private:
//==============================================================================
//Add data members here
int button;
};
#endif //H_BUTTON
#include "LoadButton.h"
LoadButton::LoadButton()
{
addListener(this);
}
LoadButton::~LoadButton()
{
}
void LoadButton::buttonClicked(Button* button)
{
printf("hello world");
}
Further guidance on JUCE classes can be sought here for those better at c++ than me but not familiar with JUCE.
http://www.rawmaterialsoftware.com/api/
-
January 6th, 2012, 10:56 AM
#2
Re: Please help Inheritance Problems
I don't know anything about Juice, but what you're describing on the surface doesn't sound like something you'd use inheritance for.
Seems like you just want a button that when clicked invokes a file selection dialog. Is that correct? If it is you just want to create an instance of FileChooser in your button's click event handler.
-
January 6th, 2012, 10:59 AM
#3
Re: Please help Inheritance Problems
i'm really new to C++ and any sort of programming just been thrown in at the deep end. would you be able to help me in how i'd go about doing this?
-
January 6th, 2012, 11:06 AM
#4
Re: Please help Inheritance Problems
Originally Posted by SUPERcuulWOWZASUPERcuulWOWZA
i'm really new to C++ and any sort of programming just been thrown in at the deep end. would you be able to help me in how i'd go about doing this?
I don't even know what Juice is, but it looks like you already have a click handler set up. Look at the documentation for your FileChooser class if that's what it's called and see if there's an example of how it works.
-
January 6th, 2012, 11:35 AM
#5
Re: Please help Inheritance Problems
thanks for your help so far. i've successfully done this i think and stored it in a variable within my loading button class. do you know how i can then use this variable within a different class called play button. is it to do with pointers? this was my solution to my initial question.
#include "LoadButton.h"
LoadButton::LoadButton()
{
addListener(this);
}
LoadButton::~LoadButton()
{
}
void LoadButton::buttonClicked(Button* button)
{
FileChooser pedoFileChooser ("Choose an Audio File", File::nonexistent, String::empty, true);
if (pedoFileChooser.browseForFileToOpen ())
{
File pedoFile (pedoFileChooser.getResult());
}
}
I want to use the variable pedofile in another class. how do i do this
-
January 6th, 2012, 11:45 AM
#6
Re: Please help Inheritance Problems
pedoFile is a really unfortunate name for a variable.
Again, I don't know what Juice is or what OS you're using, but in Windows programming, typically a button will belong to a dialog class and the dialog will handle the button's click rather than the button itself. If you can set it up that way, then the parent window of the buttons would have be responsible for creating and owning the FileChooser. Failing that approach, you could make the FileChooser a member of your button rather than just created locally in the click handler.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|