AUMIDIEffectBase, error validating plugin - audio

I have just converted the Filter AU example from apple to use AUMIDIEffectBase class in order to convert it to midi controlled effect.
https://developer.apple.com/library/mac/samplecode/FilterDemo/Introduction/Intro.html
The filter builds however I am getting error in auval tool:
Test MIDI
ERROR: -4 IN CALL MusicDeviceSendMIDI
Anybody has implemented AUMIDIEffectBase successfully?
Any example code?

I was having the same problem today and discovered the issue is in a slightly non-current release of Apple's CoreAudioUtilityClasses, AUMIDIEffectBase class. Due to multiple inheritance the following needed to be added to AUMIDIEffectBase.h so that AUPluginDispatch calls the correct overridden methods.
virtual OSStatus MIDIEvent( UInt32 inStatus,
UInt32 inData1,
UInt32 inData2,
UInt32 inOffsetSampleFrame)
{
return AUMIDIBase::MIDIEvent (inStatus, inData1, inData2, inOffsetSampleFrame);
}
/*! #method SysEx */
virtual OSStatus SysEx( const UInt8 * inData,
UInt32 inLength)
{
return AUMIDIBase::SysEx (inData, inLength);
}
I just pulled the latest from Apple's site: https://developer.apple.com/library/mac/samplecode/CoreAudioUtilityClasses/CoreAudioUtilityClasses.zip and it looks like they already fixed the issue. We both had bad download timing, it seems!

Related

What is the correct monotouch binding for this?

It seems most of the examples regarding binding an Objective-C library to c# show methods and properties, but what do you do with instance variables that are declared?
Here's an example of the .h file I'm trying to create a binding for:
#interface NdefRecord : NSObject
{
#public
uint8_t Flags;
NDEF_TNF_Type Tnf;
uint8_t TypeLength;
uint8_t *Type;
uint8_t IdLength;
uint8_t *Id;
uint32_t PayloadLength;
uint8_t *PayloadData;
}
/**
Initialize this record.
- Optional: Since member fields are public, you can also set them directly.
*/
- (id) init:(NDEF_TNF_Type)tnf type:(NSData*)type Id:(NSData*)IdBytes payload:(NSData*)payload;
/**
Parse an NDEF Record from raw bytes.
*/
- (BOOL) parse:(UInt8*)data;
/**
Returns this entire NDEF Record as a byte array.
*/
- (uint32_t) toByteArray:(UInt8*)buffer;
...
#end
In my binding project, things like the parse: method are easy enough to bind, but things like TypeLength and *Type were missed by Objective Sharpie, and nothing I seem to hand create works properly.
In an iOS XCode project, those variables are accessed with syntax like so:
record->TypeLength instead of [record TypeLength] which leads me to believe a simple binding like:
[Export ("TypeLength")]
Byte TypeLength { get; set; }
isn't going to work.
I'm completely stuck on a solution here, so any guidance is much appreciated!
The binding tool does not support accessing internal fields of a class, which is what you are trying to do here.
The only thing you can bind with an [Export] are actual properties and methods.
You need to alter that library to expose properties to those internals.

CustomDraw remains in PrePaint drawstage

I am facing some troubles when processing the NM_CUSTOMDRAW message on 64 bit machines. We have an CListCtrl derived class with a CHeaderCtrl derived header (linked via PreSubclassWindow).
In the CHeader derived class we do some custom painting. This works for a 32bit build. But when I build a 64bit variant the drawstage remains CDDS_PREPAINT.
So I am posting here to get some help on this issue. I tried a lot of combinations of result values, drawstage handling in the OnCustomDraw ... but all of them still receive only the CDDS_PREPAINT drawstage.
Here you have my current testcode for OnCustomDraw:
void CListViewCtrlExHeader::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
LPNMCUSTOMDRAW lpnmcd = (LPNMCUSTOMDRAW )pNMHDR;
*pResult = CDRF_DODEFAULT;
if (lpnmcd)
{
switch (lpnmcd->dwDrawStage)
{
case CDDS_PREERASE:
{
TRACE(_T("CDDS_PREERASE\n"));
*pResult |= CDRF_NOTIFYPOSTERASE;
break;
}
case CDDS_POSTERASE:
{
TRACE(_T("CDDS_POSTERASE\n"));
break;
}
case CDDS_PREPAINT:
{
TRACE(_T("CDDS_PREPAINT\n"));
*pResult |= CDRF_NOTIFYPOSTPAINT;
break;
}
case CDDS_POSTPAINT:
{
TRACE(_T("CDDS_POSTPAINT\n"));
break;
}
default:
{
TRACE(_T("CDDS_OTHER\n"));
break;
}
}
}
}
The only purpose of this header ctrl is painting above the default painting, so there is not much code in there. The painting of the CListCtrl derived class does not not do anything special, it lets CListCtrl handle the OnPaint message. The CListCtrl derived class does contain an OnCustomDraw section. But since it works on 32 bit, I doubt the problems should be searched there, on the other hand I mention it since I am out of options...
I found some posts with similar issues (only64 bit or drawstage remains) but none of them worked for me. One of these solutions was an incorrect definition of NMCUSTOMDRAW struct, but mine is the MFC version and no complaints found for 64bit for it. Another was that result did not get processed because of where the component was placed, but then it should not work on 32 bit too. Other solutions are specific for handling the OnCustomDraw messages and results, but that seems to be fine for my testcode...
Kind Regards,
Kevin

Why the bad_alloc(const char*) was made private in Visual C++ 2012?

I am just trying to compile a bit bigger project using the Visual Studio 2012 Release Candidate, C++. The project was/is compiled using the VS2010 now. (I am just greedy to get the C++11 things, so I tried. :)
Apart of things that I can explain by myself, the project uses the code like this:
ostringstream ostr;
ostr << "The " __FUNCTION__ "() failed to malloc(" << i << ").";
throw bad_alloc(ostr.str().c_str());
The compiler now complains
error C2248: 'std::bad_alloc::bad_alloc' : cannot access private member declared
in class 'std::bad_alloc'
... which is true. That version of constructor is now private.
What was the reason to make that version of constructor private? Is it recommended by C++11 standard not to use that constructor with the argument?
(I can imagine that if allocation failed, it may cause more problems to try to construct anything new. However, it is only my guess.)
Thanks,
Petr
The C++11 Standard defines bad_alloc as such (18.6.2.1):
class bad_alloc : public exception {
public:
bad_alloc() noexcept;
bad_alloc(const bad_alloc&) noexcept;
bad_alloc& operator=(const bad_alloc&) noexcept;
virtual const char* what() const noexcept;
};
With no constructor that takes a string. A vendor providing such a constructor would make the code using it not portable, as other vendors are not obliged to provide it.
The C++03 standard defines a similar set of constructors, so VS didn't follow this part of the standard even before C++11. MS does try to make VS as standard compliant as possible, so they've probably just used the occasion (new VS, new standard) to fix an incompatibility.
Edit: Now that I've seen VS2012's code, it is also clear why the mentioned constructor is left private, instead of being completely removed: there seems to be only one use of that constructor, in the bad_array_new_length class. So bad_array_new_length is declared a friend in bad_alloc, and can therefore use that private constructor. This dependency could have been avoided if bad_array_new_length just stored the message in the pointer used by what(), but it's not a lot of code anyway.
If you are accustomed to passing a message when you throw a std::bad_alloc, a suitable technique is to define an internal class that derives from std::bad_alloc, and override ‘what’ to supply the appropriate message.
You can make the class public and call the assignment constructor directly, or make a helper function, such as throw_bad_alloc, which takes the parameters (and additional scalar information) and stores them in the internal class.
The message is not formatted until ‘what’ is called. In this way, stack unwinding may have freed some memory so the message can be formatted with the actual reason (memory exhaustion, bad request size, heap corruption, etc.) at the catch site. If formatting fails, simply assign and return a static message.
Trimmed example:
(Tip: The copy constructor can just assign _Message to nullptr, rather than copy the message since the message is formatted on demand. The move constructor, of course can just confiscate it :-).
class internal_bad_alloc: public std::bad_alloc
{
public:
// Default, copy and move constructors....
// Assignment constructor...
explicit internal_bad_alloc(int errno, size_t size, etc...) noexcept:
std::bad_alloc()
{
// Assign data members...
}
virtual ~internal_bad_alloc(void) noexcept
{
// Free _Message data member (if allocated).
}
// Override to format and return the reason:
virtual const char* what(void) const noexcept
{
if (_Message == nullptr)
{
// Format and assign _Message. Assign the default if the
// format fails...
}
return _Message;
}
private:
// Additional scalar data (error code, size, etc.) pass into the
// constructor and used when the message is formatted by 'what'...
mutable char* _Message;
static char _Default[];
}
};
//
// Throw helper(s)...
//
extern void throw_bad_alloc(int errno, size_t size, etc...)
{
throw internal_bad_alloc(errno, size, etc...);
}

inserting "this" into an STL map from the constructor

VERSION 1
class Doh {
private:
static std::map<const std::string, const Doh*> someMap;
std::string stringValue_;
public:
Doh(std::string str) : stringValue_(str) {
Doh::someMap.insert(
std::make_pair<const std::string,const Doh*>
(this->stringValue_,this)
);
}
}
The above was ok with MSVC 2010 but with MSVC 2008 it fails – and I guess it is because the object is not constructed yet when it is inserted in the map (I got a memory access violation).
So, I tried a delayed insertion, which worked:
VERSION 2
Doh(std::string str) : stringValue_(str) {
boost::thread(&Doh::insertIntoTheStaticMap,this);
}
void insertIntoTheStaticMap() {
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
Doh::someMap.insert(
std::make_pair<const std::string,const Doh*>
(this->stringValue_,this)
);
}
But as you might be able to guess, my intention is to have the static Doh::someMap as a common lookup dictionary.
VERSION 1 didn’t need any thread-safety because I would create all Doh instances in the same thread – in initialization blocks - which would be called by dynamic initializers before I enter main().
But with VERSION 2, the naïve sleep() is neither graceful nor reliable (not to mention, I might need to lock the map before insertion).
What would be a nice KISS approach?
Only potential issue I see is the initialization of the static member, if there are multiple source files. Try guarding it with a function.
class Doh {
private:
static std::map< std::string, Doh * > &get_map() {
static std::map< std::string, Doh * > someMap;
return someMap; // initialize upon first use
}
std::string stringValue_;
public:
Doh(std::string str) : stringValue_(str) {
get_map().insert(
std::make_pair
(this->stringValue_,this)
);
}
};
In neither version is there any sign of init for stringvalue_ - what does the debugger show you about this key when you hit the map insert in version 1 of the code? How is this field set up, and what is its type?
Running this in the debugger for VS2008 should allow you to narrow down the point of failure into the <map> source, I would have thought.

RBuf8 to char* in Symbian C++

I am downloading a text string from a web service into an RBuf8 using this kind of code (it works..)
void CMyApp::BodyReceivedL( const TDesC8& data ) {
int newLength = iTextBuffer.Length() + data.Length();
if (iTextBuffer.MaxLength() < newLength)
{
iTextBuffer.ReAllocL(newLength);
}
iTextBuffer.Append(data);
}
I want to then convert the RBuf8 into a char* string I can display in a label or whatever.. or for the purposes of debug, display in
RDebug::Printf("downloading text %S", charstring);
edit for clarity..
My conversion function looks like this..
void CMyApp::DownloadCompleteL() {
{
RBuf16 buf;
buf.CreateL(iTextBuffer.Length());
buf.Copy(iTextBuffer);
RDebug::Printf("downloaded text %S", buf);
iTextBuffer.SetLength(0);
iTextBuffer.ReAlloc(0);
}
But this still causes a crash. I am using S60 3rd Edition FP2 v1.1
What you may need is something to the effect of:
RDebug::Print( _L( "downloaded text %S" ), &buf );
This tutorial may help you.
void RBuf16::Copy(const TDesC8&) will take an 8bit descriptor and convert it into a 16bit descriptor.
You should be able to display any 16bit descriptor on the screen. If it doesn't seem to work, post the specific API you're using.
When an API can be used with an undefined number of parameters (like void RDebug::Printf(const char*, ...) ), %S is used for "pointer to 16bit descriptor". Note the uppercase %S.
Thanks, the %S is a helpful reminder.
However, this doesn't seem to work.. my conversion function looks like this..
void CMyApp::DownloadCompleteL() {
{
RBuf16 buf;
buf.CreateL(iTextBuffer.Length());
buf.Copy(iTextBuffer);
RDebug::Printf("downloaded text %S", buf);
iTextBuffer.SetLength(0);
iTextBuffer.ReAlloc(0);
}
But this still causes a crash. I am using S60 3rd Edition FP2 v1.1
You have to supply a pointer to the descriptor in RDebuf::Printf so it should be
RDebug::Print(_L("downloaded text %S"), &buf);
Although use of _L is discouraged. _LIT macro is preferred.
As stated by quickrecipesonsymbainosblogspotcom, you need to pass a pointer to the descriptor.
RDebug::Printf("downloaded text %S", &buf); //note the address-of operator
This works because RBuf8 is derived from TDes8 (and the same with the 16-bit versions).

Resources