Mercurial > hg > Applications > Grep
changeset 31:4580f792d4c6
portmidi test program
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 05 Aug 2014 15:02:54 +0900 |
parents | edecf5b459c9 |
children | d6fd8aaaa358 d6c2c8f4e826 |
files | c/blocked_mmap/main.cc c/portmidi/Makefile c/portmidi/main.cc |
diffstat | 3 files changed, 62 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/c/blocked_mmap/main.cc Sun May 11 19:32:39 2014 +0900 +++ b/c/blocked_mmap/main.cc Tue Aug 05 15:02:54 2014 +0900 @@ -41,17 +41,17 @@ int loop_num = file_size / page_size; loop_num += (file_size % page_size != 0); - char * file_mmap = NULL; + char * file_mmap = (char *)malloc(4096); char * file_head = NULL; // head of read file for (int i = 0; i < loop_num; i++) { // mmap 6th arg must be a multiple of the paging size. - file_mmap = (char *)mmap(0, page_size, PROT_READ, MAP_PRIVATE, fd, i*page_size); - if (i == 0) file_head = file_mmap; - file_mmap += page_size; + printf("pre file_mmap addr : %p\n",file_mmap); + mmap(file_mmap + i*page_size, page_size, PROT_READ|PROT_WRITE, MAP_FIXED, fd, i*page_size); + printf("after file_mmap addr : %p\n",file_mmap); } - printf("%s\n",file_head); + printf("%s\n",file_mmap); munmap(file_mmap, file_size); close(fd);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c/portmidi/Makefile Tue Aug 05 15:02:54 2014 +0900 @@ -0,0 +1,11 @@ +TARGET=portmidi +OPTION= -Wall -O0 -g +LIBS= /usr/local/Cellar/portmidi/217/lib/libportmidi.dylib + +$(TARGET):main.cc + clang++ $(OPTION) $(LIBS) -o $(TARGET) main.cc + +clean: + rm -f $(TARGET) + rm -r $(TARGET).dSYM + rm -f *~ \#*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c/portmidi/main.cc Tue Aug 05 15:02:54 2014 +0900 @@ -0,0 +1,46 @@ +#include <iostream> +#include "portmidi.h" +#include "porttime.h" +#include <time.h> +#include <stdlib.h> + +#define TIME_PROC ((long (*)(void *)) Pt_Time) + +using namespace std; + + PmStream * midi; + char line[80]; + PmEvent buffer[5]; + void process_midi(PtTimestamp timestamp, void *userData); + +int main(int argc, char *argv[]) +{ + //pt_start must be called before initialising midi + Pt_Start(2000, &process_midi, 0); + Pm_Initialize(); + int device = 0;//microsoft midi mapper... + Pm_OpenOutput(&midi,device,NULL,0,NULL,NULL,10); + /*calling callback function once. When I called Pt_start + it waits until 'resolution' millisecs have passed before + start, hence I call the callback function once beforehand */ + process_midi(0, NULL); + cin.get(); + //wiat for user input and then stop midi timer callback function... + Pt_Stop(); + Pm_Close(midi); + printf("done closing and terminating...\n"); + Pm_Terminate(); +} + +void process_midi(PtTimestamp timestamp, void *userData) +{ + buffer[0].timestamp = timestamp+0; + buffer[0].message = Pm_Message(0x90, 60, 100); + buffer[1].timestamp = timestamp+1000; + buffer[1].message = Pm_Message(0x90, 60, 0); + buffer[2].timestamp = timestamp+1000; + buffer[2].message = Pm_Message(0x90, 64, 100); + buffer[3].timestamp = timestamp+2000; + buffer[3].message = Pm_Message(0x90, 64, 0); + Pm_Write(midi, buffer, 4); +}