Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #93410
| Return-Path | <python-python-list@m.gmane.org> |
|---|---|
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; '(0,': 0.09; '(1,': 0.09; '-10': 0.09; '101': 0.09; '128': 0.09; 'guys.': 0.09; 'modulo': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'throws': 0.09; 'wed,': 0.15; '"d",': 0.16; '(2,': 0.16; '(3,': 0.16; '(8,': 0.16; '(9,': 0.16; '(say': 0.16; '-18': 0.16; '-22': 0.16; '12)': 0.16; '126': 0.16; '127': 0.16; 'add/subtract': 0.16; 'message- id:@4ax.com': 0.16; 'oddity': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'url:home': 0.18; 'creates': 0.18; 'input': 0.18; '>>>': 0.20; '2015': 0.23; 'specified': 0.23; 'header:X-Complaints-To:1': 0.26; 'skip:" 20': 0.26; 'question:': 0.29; 'guess': 0.29; 'point.': 0.29; 'values': 0.30; 'becomes': 0.31; 'print': 0.31; "i'd": 0.31; 'supposed': 0.31; 'post': 0.32; '-0700': 0.33; 'another': 0.34; 'gives': 0.35; 'to:addr:python- list': 0.35; 'really': 0.35; 'represent': 0.35; 'but': 0.36; 'being': 0.36; 'notes': 0.36; 'subject:" ': 0.36; 'so,': 0.37; 'should': 0.37; 'charset:us-ascii': 0.37; 'received:org': 0.38; 'positive': 0.38; 'means': 0.39; 'to:addr:python.org': 0.39; 'where': 0.40; 'your': 0.60; 'even': 0.61; 'map': 0.61; 'times': 0.61; 'places': 0.64; 'generated.': 0.66; 'jul': 0.72; 'as:': 0.79; '102': 0.84; 'apart.': 0.84; 'dennis': 0.91; 'subject:value': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
| Subject | Re: "normalizing" a value |
| Date | Wed, 01 Jul 2015 23:36:47 -0400 |
| Organization | IISS Elusive Unicorn |
| References | <fd370a7b-ea6a-48e5-90f4-9d86b89a745e@googlegroups.com> <mailman.230.1435800465.3674.python-list@python.org> <948e2800-e52b-429a-9e00-f268fcff5085@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | adsl-108-79-221-44.dsl.klmzmi.sbcglobal.net |
| X-Newsreader | Forte Agent 6.00/32.1186 |
| X-No-Archive | YES |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.233.1435808221.3674.python-list@python.org> (permalink) |
| Lines | 81 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1435808221 news.xs4all.nl 2850 [2001:888:2000:d::a6]:37786 |
| X-Complaints-To | abuse@xs4all.nl |
| Path | csiph.com!usenet.pasdenom.info!news.stben.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
| Xref | csiph.com comp.lang.python:93410 |
Show key headers only | View raw
On Wed, 1 Jul 2015 18:49:34 -0700 (PDT), bvdp <bob@mellowood.ca> declaimed
the following:
>
>Thanks guys. Yes, that is exactly what I want. I have a number of places where a MIDI note value is being generated. MIDI should be 0..127, but the process creates notes outside the range. Guess that's another question: if the value I have is <0 or >127 I add/subtract 12 'til it's in range. Don't see using modulo working on this???
>
>As far as the original question: Yes, that's what I need. At times I need to take a note (say 14) and map it into a single octave range. So, the 12 becomes 2. Both 14 and 2 are numeric values for note "d", just an octave apart.
>
Modulo will give you the "note", but throws out the octave.
Your original post specified -50..50, which spans only 101 values, whereas
MIDI spans 128 values -- so what do you really consider out of range? And
what MIDI value is -50 supposed to map against. Is input 0 supposed to
represent middle-C with negative values being notes on the bass clef and
positive values being treble clef?
MIDI middle-C is note 60. Presuming your 0 is supposed to be middle-C, I'd
do the transformation as:
midiNote = invalue + 60
if midiNote < 0: midiNote = midiNote % 12
if midiNote > 127: midiNote = (midiNote % 12) + 115
which actually means input values of -60..+67 are shifted directly to a
midi note number, and values outside of that range are shadowed as the
lowest or highest octave.
>>> for i in range(-70, 80, 4):
... midiNote = i + 60
... if midiNote < 0: midiNote = midiNote % 12
... if midiNote > 127: midiNote = ((midiNote - 5) % 12) + 113
... print i, midiNote, "CcDdEFfGgAaB"[midiNote % 12], divmod(midiNote,
12)
...
-70 2 D (0, 2)
-66 6 f (0, 6)
-62 10 a (0, 10)
-58 2 D (0, 2)
-54 6 f (0, 6)
-50 10 a (0, 10)
-46 14 D (1, 2)
-42 18 f (1, 6)
-38 22 a (1, 10)
-34 26 D (2, 2)
-30 30 f (2, 6)
-26 34 a (2, 10)
-22 38 D (3, 2)
-18 42 f (3, 6)
-14 46 a (3, 10)
-10 50 D (4, 2)
-6 54 f (4, 6)
-2 58 a (4, 10)
2 62 D (5, 2)
6 66 f (5, 6)
10 70 a (5, 10)
14 74 D (6, 2)
18 78 f (6, 6)
22 82 a (6, 10)
26 86 D (7, 2)
30 90 f (7, 6)
34 94 a (7, 10)
38 98 D (8, 2)
42 102 f (8, 6)
46 106 a (8, 10)
50 110 D (9, 2)
54 114 f (9, 6)
58 118 a (9, 10)
62 122 D (10, 2)
66 126 f (10, 6)
70 118 a (9, 10)
74 122 D (10, 2)
78 114 f (9, 6)
>>>
The oddity for the >127 case is that 127 is not an even octave break point.
divmod() gives you the "octave" and the note.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
"normalizing" a value bvdp <bob@mellowood.ca> - 2015-07-01 17:12 -0700
Re: "normalizing" a value MRAB <python@mrabarnett.plus.com> - 2015-07-02 01:30 +0100
Re: "normalizing" a value Paul Rubin <no.email@nospam.invalid> - 2015-07-01 17:36 -0700
Re: "normalizing" a value Denis McMahon <denismfmcmahon@gmail.com> - 2015-07-02 01:06 +0000
Re: "normalizing" a value random832@fastmail.us - 2015-07-01 21:27 -0400
Re: "normalizing" a value bvdp <bob@mellowood.ca> - 2015-07-01 18:49 -0700
Re: "normalizing" a value random832@fastmail.us - 2015-07-01 22:23 -0400
Re: "normalizing" a value bvdp <bob@mellowood.ca> - 2015-07-01 19:41 -0700
Re: "normalizing" a value Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-07-01 23:36 -0400
Re: "normalizing" a value bvdp <bob@mellowood.ca> - 2015-07-02 10:03 -0700
Re: "normalizing" a value Steven D'Aprano <steve@pearwood.info> - 2015-07-02 12:15 +1000
Re: "normalizing" a value bvdp <bob@mellowood.ca> - 2015-07-01 19:42 -0700
Re: "normalizing" a value Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-02 05:41 +0100
Re: "normalizing" a value Skip Montanaro <skip.montanaro@gmail.com> - 2015-07-02 10:05 -0500
csiph-web