@@ -2,14 +2,15 @@ use std::cell::UnsafeCell;
2
2
use std:: collections:: { HashMap , HashSet } ;
3
3
use std:: ffi:: { c_void, CStr } ;
4
4
use std:: ptr;
5
+ use std:: rc:: Rc ;
5
6
use std:: sync:: Arc ;
6
7
7
8
use vst3:: { Class , ComRef , ComWrapper , Steinberg :: Vst :: * , Steinberg :: * } ;
8
9
9
10
use super :: buffers:: ScratchBuffers ;
10
11
use super :: host:: Vst3Host ;
11
12
use super :: util:: { copy_wstring, utf16_from_ptr} ;
12
- use super :: view:: View ;
13
+ use super :: view:: { View , Vst3EditorHost } ;
13
14
use crate :: bus:: { BusDir , Format , Layout } ;
14
15
use crate :: editor:: Editor ;
15
16
use crate :: events:: { Data , Event , Events } ;
@@ -39,6 +40,7 @@ pub struct MainThreadState<P: Plugin> {
39
40
pub config : Config ,
40
41
pub plugin : P ,
41
42
pub editor_params : Vec < f64 > ,
43
+ pub editor_host : Rc < Vst3EditorHost > ,
42
44
pub editor : Option < P :: Editor > ,
43
45
}
44
46
@@ -57,7 +59,7 @@ pub struct Component<P: Plugin> {
57
59
param_map : HashMap < ParamId , usize > ,
58
60
plugin_params : ParamValues ,
59
61
processor_params : ParamValues ,
60
- host : Arc < Vst3Host > ,
62
+ _host : Arc < Vst3Host > ,
61
63
main_thread_state : Arc < UnsafeCell < MainThreadState < P > > > ,
62
64
// When the audio processor is *not* active, references to ProcessState may only be formed from
63
65
// the main thread. When the audio processor *is* active, references to ProcessState may only
@@ -107,11 +109,12 @@ impl<P: Plugin> Component<P> {
107
109
param_map,
108
110
plugin_params : ParamValues :: new ( & info. params ) ,
109
111
processor_params : ParamValues :: new ( & info. params ) ,
110
- host : host. clone ( ) ,
112
+ _host : host. clone ( ) ,
111
113
main_thread_state : Arc :: new ( UnsafeCell :: new ( MainThreadState {
112
114
config : config. clone ( ) ,
113
115
plugin : P :: new ( Host :: from_inner ( host) ) ,
114
116
editor_params,
117
+ editor_host : Rc :: new ( Vst3EditorHost :: new ( ) ) ,
115
118
editor : None ,
116
119
} ) ) ,
117
120
process_state : UnsafeCell :: new ( ProcessState {
@@ -693,7 +696,9 @@ impl<P: Plugin> IEditControllerTrait for Component<P> {
693
696
}
694
697
695
698
unsafe fn setComponentHandler ( & self , handler : * mut IComponentHandler ) -> tresult {
696
- let mut current_handler = self . host . handler . write ( ) . unwrap ( ) ;
699
+ let main_thread_state = & mut * self . main_thread_state . get ( ) ;
700
+
701
+ let mut current_handler = main_thread_state. editor_host . handler . borrow_mut ( ) ;
697
702
if let Some ( handler) = ComRef :: from_raw ( handler) {
698
703
* current_handler = Some ( handler. to_com_ptr ( ) ) ;
699
704
} else {
0 commit comments