[AUv3 iOS] How to implement fullState for enabling user preset saving

Hi, I've been trying to implement fullState parameter for letting users to save their custom presets but I haven't been able to.

My factory presets are just working fine. However, I think I need to implement fullState in order to let users to save their own presets.


- (NSDictionary<NSString *,id> *)fullState {
  return @{
    @"velocityParameter": [self.parameterTree valueForKey:@"velocityParameter"]
  };
}

- (void)setFullState:(NSDictionary<NSString *,id> *)fullState {
  [self.parameterTree setValue:fullState[@"velocityParameter"] forKey:@"velocityParameter"];
}



That's what I did, but it didn't work. What should I do?

Thanks

Accepted Reply

I finally figured it out. For the ones who don't know how to implement fullState, it's like this:


- (NSDictionary *)fullState {
  NSMutableDictionary *state = [[NSMutableDictionary alloc] initWithDictionary:super.fullState];
  // write your params
  NSDictionary<nsstring*, id=""> *params = @{
                                          @"velocityParameter": [NSNumber numberWithInt:velocityParameter.value],
                                          };
  state[@"data"] = [NSKeyedArchiver archivedDataWithRootObject:params];
  return state;
}

- (void)setFullState:(NSDictionary *)fullState {
  NSData *data = (NSData *)fullState[@"data"];
  NSDictionary *params = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  // read your params 
  velocityParameter.value = [(NSNumber *)params[@"velocityParameter"] intValue];
}

Replies

I finally figured it out. For the ones who don't know how to implement fullState, it's like this:


- (NSDictionary *)fullState {
  NSMutableDictionary *state = [[NSMutableDictionary alloc] initWithDictionary:super.fullState];
  // write your params
  NSDictionary<nsstring*, id=""> *params = @{
                                          @"velocityParameter": [NSNumber numberWithInt:velocityParameter.value],
                                          };
  state[@"data"] = [NSKeyedArchiver archivedDataWithRootObject:params];
  return state;
}

- (void)setFullState:(NSDictionary *)fullState {
  NSData *data = (NSData *)fullState[@"data"];
  NSDictionary *params = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  // read your params 
  velocityParameter.value = [(NSNumber *)params[@"velocityParameter"] intValue];
}