int main(int argc, const char *argv[]) { if(argc < 2) { return -1; } unsigned int ports = midi.getPortCount(); if(ports < 1) { return -1; } // I'm not sure what port 0 is, but ports 1 and 2 seem to work midi.openPort(1); lua_State* L = luaL_newstate(); luaL_openlibs(L); lua_pushcfunction(L, midi_send); lua_setglobal(L, "midi_send"); luaL_dofile(L, argv[1]); lua_close(L); return 0; }
FREObject openOutputDevice(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) { int index = 0; FREGetObjectAsInt32(argv[0],&index); //printf("Native MIDI :: open output device %i\n",index); int pointer = -1; try { RtMidiOut* out = new RtMidiOut(); out->openPort(index); openMidiOut.push_back(out); pointer = (int)out; //printf("Open midi pointer : %i\n",pointer); // Don't ignore sysex, timing, or active sensing messages. } catch ( RtMidiError &error ) { error.printMessage(); } FREObject result; FRENewObjectFromInt32(pointer,&result); return result; }
int main(int argc, const char* argv[]) { if (argc < 1) { return -1; } unsigned int ports = midi.getPortCount(); if (ports < 1) { return -1; } midi.openPort(0); lua_State* L = luaL_newstate(); luaL_openlibs(L); lua_pushcfunction(L, midi_send); lua_setglobal(L, "midi_send"); luaL_dostring(L, "song = require 'notation'"); int result = luaL_dofile(L, argv[1]); if (result != 0) { std::cerr << lua_tostring(L, -1) << std::endl; } else { luaL_dostring(L, "song.go()"); } lua_close(L); return 0; }
int main() { std::vector<unsigned char> message; RtMidiOut *midiout = new RtMidiOut(); // Check available ports. unsigned int nPorts = midiout->getPortCount(); if ( nPorts == 0 ) { std::cout << "No ports available!\n"; goto cleanup; } cout<<"sending messages"<<endl; // Open first available port. midiout->openPort( 0 ); // Send out a series of MIDI messages. // Program change: 192, 5 message.push_back( 192 ); message.push_back( 5 ); midiout->sendMessage( &message ); // Control Change: 176, 7, 100 (volume) message[0] = 176; message[1] = 7; message.push_back( 100 ); midiout->sendMessage( &message ); // Note On: 144, 64, 90 message[0] = 144; message[1] = 64; message[2] = 90; midiout->sendMessage( &message ); sleep(1); message[0] = 144; message[1] = 64; message[2] = 90; midiout->sendMessage( &message ); sleep(3); cout<<"inside"<<endl; int bend; while(1){ cin>>bend; if (!bend) break; message[0] = 224; message[1] = 0; message[2] = bend; midiout->sendMessage( &message ); } // Note Off: 128, 64, 40 message[0] = 128; message[1] = 64; message[2] = 40; midiout->sendMessage( &message ); // Clean up cleanup: delete midiout; }
int main() { RtMidiOut *midiout = new RtMidiOut(); std::vector<unsigned char> message; // Check available ports. unsigned int nPorts = midiout->getPortCount(); if ( nPorts == 0 ) { std::cout << "No ports available!\n"; delete midiout; return -1; } // Open first available port. midiout->openPort( 0 ); // Send out a series of MIDI messages. // Program change: 192, 5 message.push_back( 192 ); message.push_back( 5 ); midiout->sendMessage( &message ); usleep( 500000 ); // Control Change: 176, 7, 100 (volume) message[0] = 176; message[1] = 7; message.push_back( 100 ); midiout->sendMessage( &message ); usleep( 500000 ); // Note On: 144, 64, 90 message[0] = 144; message[1] = 64; message[2] = 90; midiout->sendMessage( &message ); usleep( 500000 ); // Platform-dependent ... see example in tests directory. // Note Off: 128, 64, 40 message[0] = 128; message[1] = 64; message[2] = 40; midiout->sendMessage( &message ); usleep( 500000 ); return 0; }
int main(int argc, const char* argv[]) { if (argc < 1) { return -1; } unsigned int ports = midi.getPortCount(); if (ports < 1) { return -1; } midi.openPort(0); lua_State* L = luaL_newstate(); luaL_openlibs(L); lua_pushcfunction(L, midi_send); lua_setglobal(L, "midi_send"); luaL_dofile(L, argv[1]); lua_close(L); return 0; }
t_CKBOOL MidiOutManager::open( MidiOut * mout, t_CKINT device_num ) { // see if port not already open if( device_num >= (t_CKINT)the_mouts.capacity() || !the_mouts[device_num] ) { // allocate RtMidiOut * rtmout = new RtMidiOut; try { rtmout->openPort( device_num ); } catch( RtError & err ) { if( !mout->m_suppress_output ) { // print it EM_error2( 0, "MidiOut: couldn't open MIDI port %i...", device_num ); err.getMessage(); // const char * e = err.getMessage().c_str(); // EM_error2( 0, "...(%s)", err.getMessage().c_str() ); } return FALSE; } // resize? if( device_num >= (t_CKINT)the_mouts.capacity() ) { t_CKINT size = the_mouts.capacity() * 2; if( device_num >= size ) size = device_num + 1; the_mouts.resize( size ); } // put rtmout in vector for future generations the_mouts[device_num] = rtmout; } // found (always) (except when it doesn't get here) mout->mout = the_mouts[device_num]; mout->m_device_num = (t_CKUINT)device_num; // done return TRUE; }
int main(int argc, const char*argv[]) { if (argc < 1) { return -1; } unsigned int ports = midi.getPortCount(); if (ports < 1) { return -1; } midi.openPort(0); lua_State* L = luaL_newstate(); luaL_openlibs(L); lua_pushcfunction(L, midi_send); lua_setglobal(L, "midi_send"); int ret = luaL_dofile(L, argv[1]); if(ret != 0){ printf("Error occurs when calling luaL_dofile() Hint Machine 0x%x\n",ret); printf("Error: %s", lua_tostring(L,-1)); } lua_close(L); return 0; }
int main(){ HANDLE hSerial = CreateFile("COM8", GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,0); // Must specify Windows serial port above, i.e. COM6 if(hSerial==INVALID_HANDLE_VALUE){ if(GetLastError()==ERROR_FILE_NOT_FOUND){ cout << "Does not exist" << endl; //serial port does not exist. Inform user. } cout << "Strange error" << endl; } DCB dcbSerialParams = {0}; dcbSerialParams.DCBlength=sizeof(dcbSerialParams); if (!GetCommState(hSerial, &dcbSerialParams)) { cout << "Can't get state" << endl; } dcbSerialParams.BaudRate=CBR_9600; // I didn't expect this number but it works dcbSerialParams.ByteSize=8; dcbSerialParams.StopBits=ONESTOPBIT; dcbSerialParams.Parity=NOPARITY; if(!SetCommState(hSerial, &dcbSerialParams)){ cout << "Can't set state" << endl; } char szBuff[1 + 1] = {0}; // First 1 for number of bytes, not sure about the second 1 DWORD dwBytesRead = 0; RtMidiOut *midiout = new RtMidiOut(); // Check available ports. unsigned int nPorts = midiout->getPortCount(); if ( nPorts == 0 ) { std::cout << "No ports available!\n"; goto cleanup; } // Open first available port. midiout->openPort( PORT ); while(1){ if(!ReadFile(hSerial, szBuff, 1, &dwBytesRead, NULL)){ // 1 for number of bytes cout << "Can't read" << endl; } cout << szBuff << endl; // print read data if(szBuff[0] == '0'){ midiOff(midiout, 52); midiOff(midiout, 50); midiOff(midiout, 48); } if(szBuff[0] == '4'){ midiOff(midiout, 52); midiOff(midiout, 50); midiOn(midiout, 48); } if(szBuff[0] == '2'){ midiOff(midiout, 48); midiOff(midiout, 52); midiOn(midiout, 50); } if(szBuff[0] == '6'){ midiOff(midiout, 48); midiOff(midiout, 50); midiOn(midiout, 52); } } CloseHandle(hSerial); // Clean up cleanup: delete midiout; return 0; }
int _tmain (int argc, char** argv) { //FreeConsole(); //AllocConsole(); //freopen( "CONOUT$", "wb", stdout); ///// SETUP FILE WRITE const char* datafile = "data.txt"; ofstream outfile; outfile.open (datafile);//, std::ofstream::out | std::ofstream::trunc); //// Setup bluetooth const char* portLeft = "COM9"; const char* portRight = "COM6"; HANDLE* hSerialLeft = setupBluetooth(portLeft); HANDLE* hSerialRight = setupBluetooth(portRight); char szBuff[2 + 1] = {0}; // Not sure about the second 1 ////////////////////////////////////////// /////////////// SETUP MIDI //////////////// RtMidiOut *midiout = new RtMidiOut(); // Check available ports. unsigned int nPorts = midiout->getPortCount(); if ( nPorts == 0 ) { std::cout << "No ports available!\n"; //goto cleanup; } // Open first available port. midiout->openPort( PORT ); ///////////////////////////////////// SetConsoleTitle(_T("IR LEDs to GUI Integration Test - Demo")); HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); // write the title PrintTitle(console); // create a wiimote object wiimote remote; // in this demo we use a state-change callback to get notified of // extension-related events, and polling for everything else // (note you don't have to use both, use whatever suits your app): remote.ChangedCallback = on_state_change; // notify us only when the wiimote connected sucessfully, or something // related to extensions changes remote.CallbackTriggerFlags = (state_change_flags)(CONNECTED | EXTENSION_CHANGED | MOTIONPLUS_CHANGED); reconnect: COORD pos = { 0, 6 }; SetConsoleCursorPosition(console, pos); // try to connect the first available wiimote in the system // (available means 'installed, and currently Bluetooth-connected'): WHITE; _tprintf(_T(" Looking for a Wiimote ")); static const TCHAR* wait_str[] = { _T(". "), _T(".. "), _T("...") }; unsigned count = 0; while(!remote.Connect(wiimote::FIRST_AVAILABLE)) { _tprintf(_T("\b\b\b\b%s "), wait_str[count%3]); count++; } // connected - light all LEDs remote.SetLEDs(0x0f); BRIGHT_CYAN; _tprintf(_T("\b\b\b\b... connected!")); COORD cursor_pos = { 0, 6 }; /////////////// Wiimote Variables /////////////// float positions [2][2]; // First array is left hand, second array is right. First element of array is x, second is y int quads[2]; // First element is left hand, second element is right PositionHistory* posHistoryL = setupPosHistory(1000, 30); // Left hand PositionHistory* posHistoryR = setupPosHistory(1000, 30); // Left hand positions[0][0] = 0.67; // These give our starting points!!!! positions[0][1] = 0.5; // Very important positions[1][0] = 0.33; // Must calibrate these positions[1][1] = 0.5; // Don't forget!! int writeTimerCount = 0; ////////////////////////////////////////////////// // display the wiimote state data until 'Home' is pressed: while(!remote.Button.Home()){ // && !GetAsyncKeyState(VK_ESCAPE)) // IMPORTANT: the wiimote state needs to be refreshed each pass while(remote.RefreshState() == NO_CHANGE) Sleep(1); // // don't hog the CPU if nothing changed cursor_pos.Y = 8; SetConsoleCursorPosition(console, cursor_pos); // did we loose the connection? if(remote.ConnectionLost()){ BRIGHT_RED; _tprintf( _T(" *** connection lost! *** \n") BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE BLANK_LINE); Beep(100, 1000); Sleep(2000); COORD pos = { 0, 6 }; SetConsoleCursorPosition(console, pos); _tprintf(BLANK_LINE BLANK_LINE BLANK_LINE); goto reconnect; } // Battery level: CYAN; _tprintf(_T(" Battery: ")); // (the green/yellow colour ranges are rough guesses - my wiimote // with rechargeable battery pack fails at around 15%) (remote.bBatteryDrained )? BRIGHT_RED : (remote.BatteryPercent >= 30)? BRIGHT_GREEN : BRIGHT_YELLOW; _tprintf(_T("%3u%% "), remote.BatteryPercent); // IR: CYAN ; _tprintf(_T("\n IR:")); _tprintf(_T(" Mode %s "), ((remote.IR.Mode == wiimote_state::ir::OFF )? _T("OFF ") : (remote.IR.Mode == wiimote_state::ir::BASIC )? _T("BASIC") : (remote.IR.Mode == wiimote_state::ir::EXTENDED)? _T("EXT. ") : _T("FULL "))); // IR dot sizes are only reported in EXTENDED IR mode (FULL isn't supported yet) bool dot_sizes = (remote.IR.Mode == wiimote_state::ir::EXTENDED); for(unsigned index=0; index<4; index++){ wiimote_state::ir::dot &dot = remote.IR.Dot[index]; if(!remote.IsBalanceBoard()) WHITE; _tprintf(_T("%u: "), index); if(dot.bVisible) { WHITE; _tprintf(_T("Seen ")); } else{ RED; _tprintf(_T("Not seen ")); } _tprintf(_T("Size")); if(dot_sizes) _tprintf(_T("%3d "), dot.Size); else{ RED; _tprintf(_T(" n/a")); if(dot.bVisible) WHITE; } //_tprintf(_T(" X %.3f Y %.3f\n"), 133.9*(dot.X-0.470), 88.7*(dot.Y-0.575)); // Changed stuff here! _tprintf(_T(" X %.3f Y %.3f\n"), dot.X, dot.Y); if(index < 3) _tprintf(_T(" ")); } BRIGHT_WHITE; determineQuadrant(remote.IR.Dot, quads, positions); cout << quads[0] << endl; cout << quads[1] << endl; cout << "Left Hand - X = " << positions[0][0] << " Y = " << positions[0][1] << endl; cout << "Right Hand - X = " << positions[1][0] << " Y = " << positions[1][1] << endl; if (writeTimerCount == 3){ outfile << positions[0][0] << " " << positions[0][1] << " " << "1" << endl; // write to file outfile << positions[1][0] << " " << positions[1][1] << " " << "0" << endl; writeTimerCount = 0; } else { writeTimerCount++; } posHistoryL->oldest_point = (posHistoryL->oldest_point + 1) % posHistoryL->size; // Move circular buffer forward posHistoryL->velo_point = (posHistoryL->velo_point + 1) % posHistoryL->size; // Move circular buffer forward posHistoryL->positionsX[posHistoryL->oldest_point] = positions[0][0]; // Update left hand X position posHistoryL->positionsY[posHistoryL->oldest_point] = positions[0][1]; // Update left hand Y position cout << (posHistoryL->positionsX[posHistoryL->oldest_point] - posHistoryL->positionsX[posHistoryL->velo_point])/posHistoryL->dis << endl; // Print left hand x velocity cout << posHistoryL->oldest_point << endl; // For debugging /// Read Bluetooth and send MIDI signals /// readBluetooth(*hSerialRight, szBuff, quads, midiout, 0); readBluetooth(*hSerialLeft, szBuff, quads, midiout, 40); } outfile.close(); remove (datafile); // disconnect (auto-happens on wiimote destruction anyway, but let's play nice) remote.Disconnect(); Beep(1000, 200); BRIGHT_WHITE; // for automatic 'press any key to continue' msg ///////////////////////////// CloseHandle(*hSerialLeft); CloseHandle(*hSerialRight); // Clean up //cleanup: //delete midiout; CloseHandle(console); //system("exit"); return 0; }
value rtmidi_out_openport(value obj, value port) { RtMidiOut *midiout = (RtMidiOut *)(intptr_t)val_float(obj); midiout->openPort(val_int(port)); return alloc_null(); }