如何使用Audiokit发送midi poly压力消息?

时间:2017-07-04 14:20:20

标签: swift xcode8 midi audiokit

目前我正在建立一个应用程序,它基本上是我的Virus TI合成器的合成器控制器。病毒允许使用MIDI CC消息设置其大部分参数。 使用Audiokit非常简单:

midiOutput.sendEvent(AKMIDIEvent(controllerChange: 17, value: SomeValue, channel: 1))

但是,某些参数需要使用" Poly Pressure"消息。 每个音符都映射到某个参数,压力值将用于设置te参数。这看起来像一个黑客,但它就是它的方式。

我现在的问题是找不到发送midi poly压力消息的方法,因为它们似乎在audiokit中不可用。 (换句话说:没有多压力事件类型)

问题:有没有办法使用audiokit发送poly压力消息?例如,是否可以自己构建新的消息类型?

1 个答案:

答案 0 :(得分:0)

发送消息Aftertouch(通道压力,多压力)AudioKit使用基于十六进制转换的功能。不幸的是,在有关这些功能的官方文档中,几乎没有任何信息。

Extract

好吧,最后,我将在此答案中再添加一些其他类似的AudioKit MIDI功能,在文档中对此说得很少。

import { action as actionCreator } from 'typesafe-actions';
import * as uuid from 'uuid';

interface ITodo{
    id: string
}

const ADD_TODO = 'todos/ADD_TODO';
const TOGGLE_ALL = 'todos/TOGGLE_ALL';
const REMOVE_TODO = 'todos/REMOVE_TODO';

export const addTodo = (title: string) => actionCreator(ADD_TODO, { title });
export const removeTodo = (id: string) => actionCreator(REMOVE_TODO, { id });
export const toggleAll = (checked: boolean) =>
    actionCreator(TOGGLE_ALL, { checked });

type TodosAction =
    | ReturnType<typeof addTodo>
    | ReturnType<typeof removeTodo>
    | ReturnType<typeof toggleAll>;
type TodosState = ReadonlyArray<ITodo>;

type Payload<TAll extends { type: any; payload: any }, P> = Extract<TAll, { type: P}>['payload']
type Casses<T extends { type: any; payload: any }, TState> = { [P in T['type']]: (payload: Payload<T, P>) => TState }


const switchCase = <C extends { type: any; payload: any }, TState>(cases: Casses<C, TState>) => 
    <D extends (payload: any) => TState >(defaultCase: D) => {
        function getCase <K extends string>(key: K): (arg: Payload<C, K>) => TState
        function getCase <K extends string>(key: K): Casses<C, TState>[K] | D {
            return cases.hasOwnProperty(key) ? cases[key] : defaultCase;
        }
        return getCase;
    };

export default function (
    state: TodosState = [],
    action: TodosAction
): TodosState {
    // union type of 4 functions
    const reducer = switchCase<TodosAction, TodosState>({
        [ADD_TODO]: payload => [
            ...state,
            {
                completed: false,
                id: uuid.v4(),
                title: payload.title,
            },
        ],
        [REMOVE_TODO]: payload => state.filter(todo => todo.id !== payload.id),
        [TOGGLE_ALL]: payload =>
            state.map(todo => ({
                ...todo,
                completed: payload.checked,
            })),
    })(() => state)(action.type);

    return reducer(action.payload);
}