source: buchla-68k/ram/pix2mid.c@ f4fbee9

Last change on this file since f4fbee9 was f40a309, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Unix line breaks.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 =============================================================================
3 pix2mid.c -- convert cursor position to MIDI note number and score time
4 Version 9 -- 1988-10-27 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#include "stddefs.h"
9#include "graphdef.h"
10#include "vsdd.h"
11#include "score.h"
12
13#include "midas.h"
14#include "scfns.h"
15#include "scdsp.h"
16
17#define PCENTER 256 /* pixel offset of 0 time line */
18
19extern short cflag; /* accidental flag */
20extern short cnote; /* note value at cursor */
21extern short cyval; /* cursor y value */
22extern short cxval; /* cursor x value */
23
24extern long ctime; /* time at cursor */
25extern long t_cur; /* time at p_cur */
26
27/*
28
29*/
30
31short mpixtab[52][4] = { /* pixel to MIDI note for the white keys */
32
33/* [0] = center pixel, [1] = MIDI note, [2] = sharp tag, [3] = flat tag */
34
35 { 1, 108, 0, 0}, /* 8C 00 -- 0 */
36
37
38 { 5, 107, 0, 1}, /* 7B 00 -- 1 */
39 { 9, 105, 1, 1}, /* 7A 00 -- 2 */
40 { 13, 103, 1, 1}, /* 7G 00 -- 3 */
41 { 17, 101, 1, 0}, /* 7F 00 -- 4 */
42
43 { 21, 100, 0, 1}, /* 7E 00 -- 5 */
44 { 25, 98, 1, 1}, /* 7D 00 -- 6 */
45 { 29, 96, 1, 0}, /* 7C 00 -- 7 */
46
47
48 { 33, 95, 0, 1}, /* 6B 00 -- 8 */
49 { 37, 93, 1, 1}, /* 6A 00 -- 9 */
50 { 41, 91, 1, 1}, /* 6G 00 -- 10 */
51 { 45, 89, 1, 0}, /* 6F 00 -- 11 */
52
53 { 49, 88, 0, 1}, /* 6E 00 -- 12 */
54 { 53, 86, 1, 1}, /* 6D 00 -- 13 */
55 { 57, 84, 1, 0}, /* 6C 00 -- 14 */
56
57
58 { 61, 83, 0, 1}, /* 5B 00 -- 15 */
59 { 65, 81, 1, 1}, /* 5A 00 -- 16 */
60 { 69, 79, 1, 1}, /* 5G 00 -- 17 */
61 { 73, 77, 1, 0}, /* 5F 00 -- 18 */
62
63 { 77, 76, 0, 1}, /* 5E 00 -- 19 */
64 { 81, 74, 1, 1}, /* 5D 00 -- 20 */
65 { 85, 72, 1, 0}, /* 5C 00 -- 21 */
66
67 { 89, 71, 0, 1}, /* 4B 00 -- 22 */
68 { 93, 69, 1, 1}, /* 4A 00 -- 23 */
69 { 97, 67, 1, 1}, /* 4G 00 -- 24 */
70 {101, 65, 1, 0}, /* 4F 00 -- 25 */
71
72 {105, 64, 0, 1}, /* 4E 00 -- 26 */
73 {109, 62, 1, 1}, /* 4D 00 -- 27 */
74 {113, 60, 1, 0}, /* 4C 00 -- 28 -- Middle C */
75
76/*
77
78*/
79
80 {117, 59, 0, 1}, /* 3B 00 -- 29 */
81 {121, 57, 1, 1}, /* 3A 00 -- 30 */
82 {125, 55, 1, 1}, /* 3G 00 -- 31 */
83 {129, 53, 1, 0}, /* 3F 00 -- 32 */
84
85 {133, 52, 0, 1}, /* 3E 00 -- 33 */
86 {137, 50, 1, 1}, /* 3D 00 -- 34 */
87 {141, 48, 1, 0}, /* 3C 00 -- 35 */
88
89
90 {145, 47, 0, 1}, /* 2B 00 -- 36 */
91 {149, 45, 1, 1}, /* 2A 00 -- 37 */
92 {153, 43, 1, 1}, /* 2G 00 -- 38 */
93 {157, 41, 1, 0}, /* 2F 00 -- 39 */
94
95 {161, 40, 0, 1}, /* 2E 00 -- 40 */
96 {165, 38, 1, 1}, /* 2D 00 -- 41 */
97 {169, 36, 1, 0}, /* 2C 00 -- 42 */
98
99
100 {173, 35, 0, 1}, /* 1B 00 -- 43 */
101 {177, 33, 1, 1}, /* 1A 00 -- 44 */
102 {181, 31, 1, 1}, /* 1G 00 -- 45 */
103 {185, 29, 1, 0}, /* 1F 00 -- 46 */
104
105 {189, 28, 0, 1}, /* 1E 00 -- 47 */
106 {193, 26, 1, 1}, /* 1D 00 -- 48 */
107 {197, 24, 1, 0}, /* 1C 00 -- 49 */
108
109
110 {201, 23, 0, 1}, /* 0B 00 -- 50 */
111 {205, 21, 1, 0} /* 0A 00 -- 51 */
112};
113
114/*
115
116*/
117
118/*
119 =============================================================================
120 pix2mid() -- convert (px, py) to MIDI note and score time
121 =============================================================================
122*/
123
124short
125pix2mid()
126{
127 register short i, cy, mpc;
128 register long ct;
129
130 cnote = -1;
131 ctime = -1L;
132 cflag = -1;
133 mpc = ac_code EQ N_SHARP ? 2 : 3;
134
135 ct = t_cur + ((long)cxval - (long)PCENTER);
136
137 if (ct < 0L)
138 return(FAILURE);
139
140 ctime = ct;
141 cy = cyval - 14;
142
143 for (i = 0; i < 52; i++) {
144
145 if ((cy GE mpixtab[i][0]) AND
146 (cy LE mpixtab[i][0] + 2)) {
147
148 cnote = mpixtab[i][1];
149 cflag = mpixtab[i][mpc];
150 break;
151 }
152 }
153
154 return((cnote EQ -1L) ? FAILURE : SUCCESS);
155}
Note: See TracBrowser for help on using the repository browser.