-
-
Notifications
You must be signed in to change notification settings - Fork 34
feat: support for midi 0.1 #736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| } from './types'; | ||
|
|
||
| // Web MIDI API types | ||
| interface WebMIDIPort { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicated MIDIPortInfo
| import type { CodegenTypes, TurboModule } from 'react-native'; | ||
| import { TurboModuleRegistry } from 'react-native'; | ||
|
|
||
| export interface MIDIPortInfoCodegen { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicated MIDIPortInfo
packages/react-native-medi/android/src/main/java/com/medi/MediModule.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since midi package is not planned to be in separate repository, you can use our main .gitignore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't get it? You can nest .gitignores it is auto generated from expo project it has some expo specific things i guess
| #ifdef RCT_NEW_ARCH_ENABLED | ||
| - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule: | ||
| (const facebook::react::ObjCTurboModule::InitParams &)params | ||
| { | ||
| return std::make_shared<facebook::react::NativeMediSpecJSI>(params); | ||
| } | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it doesn't support old arch, why this check
| package = JSON.parse(File.read(File.join(__dir__, "package.json"))) | ||
|
|
||
| Pod::Spec.new do |s| | ||
| s.name = "Medi" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| s.name = "Medi" | |
| s.name = "RNOurAgreedName" |
| /// | ||
| /// PS: Not actually wasted time cuz it works but brooo☠ | ||
| dispatch_async(dispatch_get_main_queue(), ^{ | ||
| OSStatus status = MIDIClientCreateWithBlock(CFSTR("MediClient"), &_midiClient, ^(const MIDINotification *message) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| OSStatus status = MIDIClientCreateWithBlock(CFSTR("MediClient"), &_midiClient, ^(const MIDINotification *message) { | |
| OSStatus status = MIDIClientCreateWithBlock(CFSTR("MediClient"), &self->_midiClient, ^(const MIDINotification *message) { |
|
|
||
| self.sysexEnabled = sysex; | ||
| NSLog(@"MIDIClientCreateWithBlock status: %d, sysex: %d", status, sysex); | ||
| OSStatus statusPort = MIDIInputPortCreateWithProtocol(self.midiClient, CFSTR("MediInputPort"), kMIDIProtocol_1_0, &_inputPort, ^(const MIDIEventList *eventList, void *srcConnRefCon) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| OSStatus statusPort = MIDIInputPortCreateWithProtocol(self.midiClient, CFSTR("MediInputPort"), kMIDIProtocol_1_0, &_inputPort, ^(const MIDIEventList *eventList, void *srcConnRefCon) { | |
| OSStatus statusPort = MIDIInputPortCreateWithProtocol(self.midiClient, CFSTR("MediInputPort"), kMIDIProtocol_1_0, &self->_inputPort, ^(const MIDIEventList *eventList, void *srcConnRefCon) { |
| reject:(RCTPromiseRejectBlock)reject) | ||
| { | ||
| if (self.midiClient != 0) { | ||
| resolve(nil); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolve promises with better info
| NSLog(@"MIDIInputPortCreateWithProtocol status: %d", statusPort); | ||
|
|
||
| // Resolve the promise after MIDI client is fully initialized | ||
| resolve(nil); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolve promises with better info
| RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, openPort:(NSString *)portId) | ||
| { | ||
| NSString *type = [portId hasPrefix:@"input_"] ? @"input" : @"output"; | ||
| SInt32 uniqueID = [[portId substringFromIndex:[type length] + 1] intValue]; | ||
| if ([type isEqualToString:@"output"]) { | ||
| // We do not need to open output ports so it is considered always successful | ||
| NSLog(@"Opened output port: %@", portId); | ||
| return @YES; | ||
| } | ||
| MIDIEndpointRef endpoint = 0; | ||
| ItemCount srcCount = MIDIGetNumberOfSources(); | ||
| for (ItemCount i = 0; i < srcCount; ++i) { | ||
| MIDIEndpointRef src = MIDIGetSource(i); | ||
| SInt32 srcUniqueID = 0; | ||
| MIDIObjectGetIntegerProperty(src, kMIDIPropertyUniqueID, &srcUniqueID); | ||
| if (srcUniqueID == uniqueID) { | ||
| endpoint = src; | ||
| break; | ||
| } | ||
| } | ||
| if (endpoint == 0) { | ||
| NSLog(@"Port not found: %@", portId); | ||
| return @NO; | ||
| } | ||
|
|
||
| OSStatus status = MIDIPortConnectSource(self.inputPort, endpoint, (void *)(uintptr_t)endpoint); | ||
| if (status != noErr) { | ||
| NSLog(@"Failed to connect input port: %@, status: %d", portId, status); | ||
| return @NO; | ||
| } | ||
|
|
||
| self.openPorts[portId] = @(endpoint); | ||
| NSLog(@"Opened port: %@", portId); | ||
| return @YES; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, openPort:(NSString *)portId) | |
| { | |
| NSString *type = [portId hasPrefix:@"input_"] ? @"input" : @"output"; | |
| SInt32 uniqueID = [[portId substringFromIndex:[type length] + 1] intValue]; | |
| if ([type isEqualToString:@"output"]) { | |
| // We do not need to open output ports so it is considered always successful | |
| NSLog(@"Opened output port: %@", portId); | |
| return @YES; | |
| } | |
| MIDIEndpointRef endpoint = 0; | |
| ItemCount srcCount = MIDIGetNumberOfSources(); | |
| for (ItemCount i = 0; i < srcCount; ++i) { | |
| MIDIEndpointRef src = MIDIGetSource(i); | |
| SInt32 srcUniqueID = 0; | |
| MIDIObjectGetIntegerProperty(src, kMIDIPropertyUniqueID, &srcUniqueID); | |
| if (srcUniqueID == uniqueID) { | |
| endpoint = src; | |
| break; | |
| } | |
| } | |
| if (endpoint == 0) { | |
| NSLog(@"Port not found: %@", portId); | |
| return @NO; | |
| } | |
| OSStatus status = MIDIPortConnectSource(self.inputPort, endpoint, (void *)(uintptr_t)endpoint); | |
| if (status != noErr) { | |
| NSLog(@"Failed to connect input port: %@, status: %d", portId, status); | |
| return @NO; | |
| } | |
| self.openPorts[portId] = @(endpoint); | |
| NSLog(@"Opened port: %@", portId); | |
| return @YES; | |
| } | |
| RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(BOOL, openPort:(NSString *)portId) | |
| { | |
| NSString *type = [portId hasPrefix:@"input_"] ? @"input" : @"output"; | |
| SInt32 uniqueID = [[portId substringFromIndex:[type length] + 1] intValue]; | |
| if ([type isEqualToString:@"output"]) { | |
| // We do not need to open output ports so it is considered always successful | |
| NSLog(@"Opened output port: %@", portId); | |
| return YES; | |
| } | |
| MIDIEndpointRef endpoint = 0; | |
| ItemCount srcCount = MIDIGetNumberOfSources(); | |
| for (ItemCount i = 0; i < srcCount; ++i) { | |
| MIDIEndpointRef src = MIDIGetSource(i); | |
| SInt32 srcUniqueID = 0; | |
| MIDIObjectGetIntegerProperty(src, kMIDIPropertyUniqueID, &srcUniqueID); | |
| if (srcUniqueID == uniqueID) { | |
| endpoint = src; | |
| break; | |
| } | |
| } | |
| if (endpoint == 0) { | |
| NSLog(@"Port not found: %@", portId); | |
| return NO; | |
| } | |
| OSStatus status = MIDIPortConnectSource(self.inputPort, endpoint, (void *)(uintptr_t)endpoint); | |
| if (status != noErr) { | |
| NSLog(@"Failed to connect input port: %@, status: %d", portId, status); | |
| return NO; | |
| } | |
| self.openPorts[portId] = @(endpoint); | |
| NSLog(@"Opened port: %@", portId); | |
| return YES; | |
| } |
for me it would better map with js equivalent of this function
Under construction
Closes #
Introduced changes
Checklist