仲尼弟子座次
公元前525年孔子26岁时,郯国首任国君“郯子”来到鲁国拜见“鲁昭公”。郯国是一个位于山东临沂郯县的小国,而“郯子”是有史以来唯一的“民选国君”。“郯子”出生于普通农民家庭,凭借“鹿乳奉亲”的孝行成功跻身《二十四孝图》第五图。由于“郯子”贤孝之名远播,人们纷纷慕名来到他的家乡,拜他为师,向他学习知识以及做人的道理。有人为了求学方便,就和他“比邻而居”。渐渐的人越聚越多,郯子的家乡就由乡村变成了城镇.又由城镇变成了邦国。邦国“郯国”成立后,人们一致推举郯子做了第一任国君。郯子治理“郯国”时讲道德、施仁义,恩威有加,郯地文化发达,民风淳厚,百姓心悦诚服。孔子少年时也曾经在“郯国”住过一段时日,接受过郯子的教诲,这一次就趁着郯子访鲁的机会向他询问了有关古代官制中诸如“以鸟名官”之类的学问,从而留传下“孔子师郯子”的故事。
公元前523年孔子28岁时,在鲁国“三桓”孟氏家的公子“南宫敬叔”的陪同下,“一车二马一童一御”前往洛阳向时年48岁的“老聃”请教学问。临别时,老聃赠言说:『富贵者送人以财,仁义者送人以言。吾不富不贵,无财以送汝;愿以数言相送。当今之世,聪明而深察者,其所以遇难而几至于死,在于好讥人之非也;善辩而通达者,其所以招祸而屡至于身,在于好扬人之恶也。为人之子,勿以己为高;为人之臣,勿以己为上,望汝切记』,老聃看出孔子品行高洁,抵触“和光同尘”,性情坚毅,偏好“宁折不弯”,怕他聪明早夭,就告诫他不要“讥人非,扬人恶”,要“上善若水,善下于人”。孔子在黄河边发出『逝者如斯夫,不舍昼夜!』的慨叹,老聃明示他『人生天地之间,乃与天地一体也。天地,自然之物也;人生,亦自然之物;人有幼、少、壮、老之变化,犹如天地有春、夏、秋、冬之交替。生于自然,死于自然,任其自然,则本性不乱;不任自然,奔忙于仁义之间,则本性羁绊。功名存于心,则焦虑之情生;利欲留于心,则烦恼之情增』。
老聃欣赏孔子“好学上进,人才难得”,点化孔子不遗余力。孔子悟性一般,心眷红尘,难以领会“道门真义”。孔子说,『吾乃忧大道不行,仁义不施,战乱不止,国乱不治也,故有人生短暂,不能有功于世、不能有为于民之感叹矣』。孔子怀揣“行大道,施仁义,止战乱,治乱国”的赤子情怀回到鲁国,从此开放私学,广收门徒,传授六艺,兴盛士林,终成一代名儒,万世师表。
公元前522年,29岁的孔子开始教学生涯,此时年龄达到12周岁,够格当他弟子的至少有“南宫敬叔”,“孟懿子”,“颜路”,“曾点”,“子路”,“冉耕”,“秦子丕”,“任不齐”,“荣子祈”,“燕伋”,“闵子骞”等人。比如对于公元前518年孟懿子和南宫敬叔学礼于孔子一事,就有明确记录。
公元前517年孔子34岁时,鲁国发生内乱,鲁昭公被迫逃往齐国。孔子也离开鲁国,到了齐国,受到齐景公赏识和厚待。时年33岁的齐景公曾准备把尼溪一带的田地封给孔子,但被时年61岁的齐国大夫晏婴阻止。公元前507年,孔子45岁,此时年龄够格当他弟子的至少有增添“冉雍”,“冉求”,“宰予”,“颜回”,“有若”,“高子羔”,“子贡”,“宓不齐”。
公元前504年,季氏家臣“阳虎”擅权日重,孔子称之为“家臣掌政”。他退隐修著《诗》、《书》、《礼》、《乐》,带领众多弟子走学各国。阳虎想要见孔子,并劝孔子出仕,孔子没有明确表态,阳虎不久后任命孔子为“小司空”。公元前499年,52岁的孔子升任鲁国“大司寇”,『摄相事,七日而诛少正卯,曝尸三日,鲁国大治』。此时年龄够格当他弟子的至少有增添“原宪”,“石作蜀”,“公西赤”。
公元前497年,54岁的孔子与“三桓”闹掰,鲁国待不下去了,开始“周游列国”。公元前492年,孔子59岁,此时年龄够格当他弟子的至少有增添“澹台灭明”,“樊须”,“曾参”,“言偃”,“卜商”。公元前489年,62岁的孔子跟弟子在陈国和蔡国之间被困绝粮,许多弟子因为困饿而生了病。后来被楚国人相救。由楚国返回卫国。公元前487年孔子64岁时,时年31岁的“有若”参与了抵抗吴国侵略的军事行动,同年“闵子骞”去世,享年49岁。
公元前484年,齐国讨伐鲁国,时年38岁的“冉求”帅鲁军与齐军对战获胜。“季康子”问冉有指挥才能从何学来,冉求提到了自己的老师“孔子”。季康子派人以币迎时年67岁的孔子回归鲁国,孔子14年的“周游列国”生涯至此结束。孔子反对季康子诸如“施行田赋”之类的做法。他告诉冉有,应该用“君子礼数”来评价行为是否符合道义。“君子礼数”是施舍的时候,从重付出;做事的时候,中庸而行;死去的时候,对自己薄葬。由于与“季康子”等人在治国理念上谈不拢,孔子虽仍有心从政,但还是被敬而不用。这一年,年龄够格当他弟子的至少有增添“颛孙师”,“冉孺”,“冉季”。
公元前484年至公元前479年是孔子生命的最后五年,期间他的儿子“孔鲤”,他的弟子“颜回”,“子路”,“石作蜀”相继离世。公元前479年,孔子因病去世,此时活着的弟子中比较杰出的还有41岁的“子贡”,39岁的“有若”,36岁的“原宪”,28岁的“卜商”,27岁的“言偃”,26岁的“曾参”。由于秦始皇“焚书坑儒”时对孔子弟子的生卒年份以及事迹相关史料进行了加强版“和谐”操作,使得死于公元前479年至公元前401年之间的那些“孔门七十二贤”除了姓名,极少能留下蛛丝马迹。太史公司马迁在《史记卷六十七.仲尼弟子列传第七》留存下相关记载的,基本也只限于“孔门十哲”。
#
RenMin = [
['孔子', -551, -479],
['老子', -571, -471],
['蘧伯玉', -585, -484],
['晏婴', -578, -500],
['老莱子', -599, -479],
['子产', '?', -522],
['臧文仲', '?', -617],
['柳下惠', -720, -621],
#十哲
['颜回_子渊', -521, -481],
['闵损_子骞', -536, -487],
['冉耕_伯牛', -544, '?'],
['冉雍_仲弓', -522, '?'],
['冉求_子有', -522, '?'],
['仲由_子路', -542, -480],
['宰予_子我', -522, -458],
['端木赐_子贡', -520, -456],
['言偃_子游', -506, -443],
['卜商_子夏', -507, '?'],
#七十二贤
['颛孙师_子张', -503, '?'],
['曾参_子舆', -505, -435],
['澹台灭明_子羽', -512, '?'],
['宓不齐_子贱', -521, -445],
['原宪_子思', -515, '?'],
['公冶长_子长', '?', '?'],
['南宫适_子容', '?', '?'],
['公皙哀_季次', '?', '?'],
['曾点_皙', -545, '?'],
['颜路', -545, '?'],
['商瞿_子木', -522, '?'],
['高柴_子羔', -521, '?'],
['司马耕_子牛', '?', '?'],
['樊须_子迟', -505, '?'],
['有若_子有', -518, '?'],
['公西赤_子华', -509, '?'],
['巫马施_子期', -521, '?'],
['梁鳣_叔鱼', -522, '?'],
['颜幸_子柳', -503, '?'],
['冉孺_子鲁', -501, '?'],
['曹恤_子循', -501, '?'],
['伯虔_子折', -501, '?'],
['冉季_子产', -498, '?'],
['公祖句兹_子之', '?', '?'],
['秦祖_子南', '?', '?'],
['漆雕哆_子敛', '?', '?'],
['颜高_子骄', '?', '?'],
['漆雕徒父_子文', '?', '?'],
['壤驷赤_子徒', '?', '?'],
['商泽_子秀', '?', '?'],
['石作蜀_子明', -519, -479],
['任不齐_子选', -545, -468],
['公良孺_子正', '?', '?'],
['后处_子里', '?', '?'],
['秦冉_子开', '?', '?'],
['公夏首_秦', '?', '?'],
['奚容箴_子皙', '?', '?'],
['公肩定_子中', '?', '?'],
['颜相', '?', '?'],
['鄡单_子家', '?', '?'],
['句井疆' , '?', '?'],
['罕父黑', '?', '?'],
['秦商_子丕', -547, '?'],
['申党_子周','?', '?'],
['颜之仆_叔', '?', '?'],
['荣旗_子祈', -542, -470],
['县成_子祺', '?', '?'],
['左人郢_子行', '?', '?'],
['燕伋_思', -541, -476],
['郑邦_子徒', '?', '?'],
['秦非_子之', '?', '?'],
['施之常_子恒', '?', '?'],
['颜哙_子声', '?', '?'],
['步叔乘_子车', '?', '?'],
['原亢籍', '?', '?'],
['乐欬', '?', '?'],
['廉絜_子庸', '?', '?'],
['叔仲会_子期', -501, '?'],
['颜何_冉', '?', '?'],
['狄黑_皙', '?', '?'],
['邦巽_子敛', '?', '?'],
['孔忠', '?', '?'],
['公西舆如', '?', '?']
];
def tmp():
t = NianHaoTree();
#for item in DongZhou:
for item in RenMin:
t.addElem(NianHao(item[0], item[1], item[2]));
year = -500;
year2 = -479
a = t.searchPeople(year);
for i in range(len(a)):
a[i] = a[i][:-3];
b = t.searchPeople(year2);
print(b);
for i in range(len(b)):
b[i] = b[i][:-3];
c = set(b).difference(set(a));
print(c);
print(' -------');
t1 = NianHaoTree();
for item in DongZhou:
t1.addElem(NianHao(item[0], item[1], item[2]));
print(t1.search(year));
#print(t.search(-538));
#print(t.searchName('齐'));
#print(t.calcYear('晋献公', 22));
#
#
import struct;
import math;
import random;
#把十进制数按照小尾字节序切割
def littleEndian(number, byte = 4):
result = [0]*byte;
for i in range(byte):
result[i] = number%256;
number//=256;
return result;
#把UltraEdit中的值字串转化为hex序列组
def hexExpr(string):
resultString = '';
size = len(string);
for i in range(size):
if (i == 0 ):
resultString += '0x'+string[i];
elif (string[i] == ' '):
resultString += ', 0x';
else:
resultString += string[i];
print(resultString);
###
# @usage 写.wav文件,能把声波数据阵列用二进制写成.wav。
# @author mw
# @date 2016年04月28日 星期四 14:31:34
# @param
# @return
#
###
def writeWav(index , filename):
byteArray = [];
dataArray = [];
mode = 1;
#样本数据阵列
sampleArray = songArray();
#样本数据点数
N = len(sampleArray);
times = 1;
dataSize = N*times;
fileSize = dataSize+44; #44为格式头部分所用字节数
#RIFF WAVE CHUNK
RIFF_ID = [0x52, 0x49, 0x46, 0x46]; #'RIFF'
RIFF_Size = littleEndian(fileSize-8, 4); #文件总字节数减去8
RIFF_Type = [0x57, 0x41,0x56, 0x45, 0x66, 0x6D, 0x74, 0x20]; #'WAVEfat '
#Format Chunk
Format_10_17 = [0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00];#过滤4+格式2+声道2=8个字节
Format_18_1B = [0x11, 0x2B, 0x00, 0x00]; #采样频率0x2B11 = 11025
Format_1C_1F = [0x22, 0x56, 0x00, 0x00]; #比持率 = 频率*通道*样本位 = 22050
Format_20_23 = [0x02, 0x00, 0x10, 0x00]; #块对齐 = 通道数* 样本位数 = 1*2 = 2
#Fact Chunk(optional)
#Data Chunk
Data_24_27 = [0x64, 0x61, 0x74, 0x61]; #'DATA'标记
Data_Size = littleEndian(fileSize-44, 4); #下面的Data部分的字节数,文件总字节数-44
#RIFF WAVE CHUNK
'''
for i in range(4):
byte = struct.pack('B', RIFF_ID[i]);
byteArray.append(byte);
'''
RIFF = [b'R', b'I', b'F', b'F'];
for i in range(4):
byteArray.append(RIFF[i]);
for i in range(4):
byte = struct.pack('B', RIFF_Size[i]);
byteArray.append(byte);
'''
for i in range(8):
byte = struct.pack('B', RIFF_Type[i]);
byteArray.append(byte);
#Format Chunk
for i in range(8):
byte = struct.pack('B', Format_10_17[i]);
byteArray.append(byte);
for i in range(4):
byte = struct.pack('B', Format_18_1B[i]);
byteArray.append(byte);
for i in range(4):
byte = struct.pack('B', Format_1C_1F[i]);
byteArray.append(byte);
for i in range(4):
byte = struct.pack('B', Format_20_23[i]);
byteArray.append(byte);
#Data Chunk
for i in range(4):
byte = struct.pack('B', Data_24_27[i]);
byteArray.append(byte);
'''
#Format_28_2B是数据块大小,formatHead是它前面的所有部分
formatHead = [b'W', b'A', b'V', b'E', b'f', b'm', b't', b' ', \
b'\x10', b'\x00', b'\x00', b'\x00', b'\x01', b'\x00', b'\x01', b'\x00', \
b'\x11', b'+', b'\x00', b'\x00', \
b'"', b'V', b'\x00', b'\x00', \
b'\x02', b'\x00', b'\x10', b'\x00', \
b'd', b'a', b't', b'a'];
for i in range(len(formatHead)):
byteArray.append(formatHead[i]);
for i in range(4):
byte = struct.pack('B', Data_Size[i]);
byteArray.append(byte);
#写出到文件
print('文件写入开始。>>>');
s = '';
if mode == 1:
s = filename+'_'+str(index)+'.wav';
elif mode == 2:
s = 'randMusic'+str(index)+'.wav';
fout= open(s, 'wb');
size = len(byteArray);
for i in range(size):
fout.write(byteArray[i]);
size = len(sampleArray);
for j in range(times):
for i in range(size):
fout.write(sampleArray[i]);
fout.close();
print('文件写入完毕。');
#生成声音样本,返回样本矩阵
def sampleGen(N, freq):
#设立20000个数值点,约可听2秒
sampleArray = [];
coef = 2*math.pi*freq/11025;
for i in range(N):
xvalue = coef*i;
yvalue = math.sin(xvalue)
if (yvalue < 0):
yvalue *= 32768/2;
else:
yvalue *= 32767/2;
sampleArray.append(round(yvalue));
return sampleArray;
def waveDataGen(freq):
N = 200;
sampleArray = sampleGen(N, freq);
dataArray = [];
for i in range(N):
value = littleEndian(sampleArray[i], 2);
for j in range(2):
byte = struct.pack('B', value[j]);
dataArray.append(byte);
return dataArray;
def genIdle():
dataArray = [];
for i in range(200):
value = littleEndian(0, 2);
for j in range(2):
byte = struct.pack('B', value[j]);
dataArray.append(byte);
print(dataArray);
#生成声波数据
def tmp2():
print('生成波形开始。>>>');
fout= open('output.txt', 'w');
frequence = list(range(100, 7100, 100));
size = len(frequence);
for i in range(size):
dataStr = 'assistFreq_'+str(frequence[i]).replace('.', 'p') + ' = [';
fout.write(dataStr);
data = waveDataGen(frequence[i]);
size_1 = len(data);
for n in range(size_1):
fout.write(str(data[n]));
if (n < size_1-1):
fout.write(', ');
fout.write('];');
fout.write('\r\n');
fout.close();
print('生成波形结束,请到output.txt查收。');
import voice.song as Song;
#歌曲数据
def songArray():
#频率
FreqPiano = [[27.500, 29.135, 30.867, 32.702, 34.647, 36.707,
38.890, 41.203, 43.653, 46.249, 48.999, 51.913], #O1
[55.000, 58.270, 61.735, 65.406, 69.295, 73.416,
77.782, 82.407, 87.307, 92.499, 97.999, 103.826], #O2
[110.000, 116.541, 123.471, 130.813, 138.592, 146.833,
155.564, 164.814, 174.614, 184.997, 195.997, 207.652], #O3
[220.000, 233.082, 246.942, 261.626, 277.183, 293.665,
311.127, 329.628, 349.229, 369.995, 391.996, 415.305], #O4
[440.000, 466.164, 493.884, 523.252, 554.366, 587.330,
622.254, 659.255, 698.456, 739.988, 783.990, 830.608], #O5
[879.999, 932.326, 987.765, 1046.501, 1108.729, 1174.657,
1244.506, 1318.508, 1396.911, 1479.976, 1567.980, 1661.217], #O6
[1759.998, 1864.653, 1975.531, 2093.002, 2217.458, 2349.315,
2489.013, 2637.017, 2793.822, 2959.951, 3135.959, 3322.433]] #O7
#调式
toneChoose = 3;
if (toneChoose == 1):
Tone = [['C', [1, 3, 5, 6, 8, 10, 12]], #以CDEFGAB顺序排音 'a'
['G', [1, 3, 5, 7, 20, 22, 24]], #'e'
['D', [2, 15, 17, 19, 20, 22, 24]], #'b'
['A', [2, 3, 5, 7, 9, 22, 24]], #'#f'
['E', [2, 4, 17, 19, 21, 22, 24]], #'#c'
['B', [2, 4, 5, 7, 9, 11, 24]] #['B', [14, 16, 17, 19, 21, 23, 12]] #'#g'
];
elif (toneChoose == 2):
#调式
Tone = [['C', [1, 3, 5, 6, 8, 10, 12]], #以CDEFGAB顺序排音 'a'
['G', [13, 15, 17, 19, 8, 10, 12]], #'e'
['D', [14, 3, 5, 7, 8, 10, 12]], #'b'
['A', [14, 15, 17, 19, 21, 10, 12]], #'#f'
['E', [14, 16, 5, 7, 9, 10, 12]], #'#c'
['B', [14, 16, 17, 19, 21, 23, 24]] #['B', [14, 16, 17, 19, 21, 23, 12]] #'#g'
];
else:
#调式
Tone = [['C', [1, 3, 5, 6, 8, 10, 12]], #以CDEFGAB顺序排音 'a'
['G', [1, 3, 5, 7, 8, 10, 12]], #'e'
['D', [2, 3, 5, 7, 8, 10, 12]], #'b'
['A', [2, 3, 5, 7, 9, 10, 12]], #'#f'
['E', [2, 4, 5, 7, 9, 10, 12]], #'#c'
['B', [2, 4, 5, 7, 9, 11, 12]], #['B', [14, 16, 17, 19, 21, 23, 12]] #'#g'
['#F', [2, 4, 6, 7, 9, 11, 12]],
['#C', [2, 4, 6, 7, 9, 11, 13]]
];
#强弱节拍
strong = [[1.0, 0.8, 0.9, 0.8], #4/4拍
[1.0, 0.8, 0.8], #3/4拍
[1.0, 0.9], #2/4拍
[1.0, 0.8, 0.7, 1.0, 0.8, 0.7] #6/8拍
];
#旋律
#music = Song.JuanZhuLian;
music = Song.HaoHanGe;
print('曲谱检查开始');
#乐谱简单检查
for i in range(1, len(music)):
len_ = len(music[i]);
if (len_%2 != 0):
raise Exception('第{0}节歌曲--{1}--数据有误,请检查!'.format(i, music[i]));
totalendure = 0;
if (len_ != 0):
for j in range(0, len_, 2):
totalendure += music[i][j+1];
if (round(totalendure * 16))%4 != 0:
raise Exception('第{0}节歌曲--{1}--数据有误,请检查!'.format(i, music[i]));
print('根据调式选音开始');
keyFreq = [];
key = [];
level = 3;
if (music[0][0] == 'C'): #C大调
key = Tone[0][1];
elif (music[0][0] == 'G'): #G大调
key = Tone[1][1];
elif (music[0][0] == 'D'): #D大调
key = Tone[2][1];
elif (music[0][0] == 'A'): #A大调
key = Tone[3][1];
elif (music[0][0] == 'E'): #E大调
key = Tone[4][1];
elif (music[0][0] == 'B'): #B大调
key = Tone[5][1];
elif (music[0][0] == '#F'): #
key = Tone[6][1];
elif (music[0][0] == '#C'): #
key = Tone[7][1];
else:
pass;
#print(key);
for j in range(3): #低中高三阶音, 共21个键的音
keyFreq_ = [];
for i in range(7):
freq_ = key[i]+2;
'''
if key[i]%12 > 9 or key[i]%12 < 1:
freq_ -= 12;
'''
if (freq_ >= 24):
keyFreq_.append(FreqPiano[level+j+1][freq_ - 24]);
elif (freq_ >= 12):
keyFreq_.append(FreqPiano[level+j][freq_ - 12]);
else:
keyFreq_.append(FreqPiano[level+j-1][freq_]);
keyFreq.append(keyFreq_);
print(keyFreq);
#每拍时间
clapendure = 60/music[0][3];
#二进制数据
data = [];
#切分音使用指示
continuous = True;
print('--歌曲数据生成开始--');
if (music[0][1] == 4 and music[0][2] == 4): #4/4拍
clap = strong[0]; #拍子强弱
#上一个音符
lastkey = 0;
#波形相位
lastphase = 0;
for k in range(1, len(music)):
start = 0;
clapsection = 0;
explode = []; #小节内分解
for j in range(0, len(music[k]), 2):
#print(music[i][j], end = ', ');
endure = music[k][j+1]; #持续时间
#print('i', i, 'j', j);
#print(endure);
if (continuous == False):
#不使用切分音的场合,同一个音符轻重不同
spare = 0.25 - start;
if (spare >= endure):
explode.append([music[k][j], endure, clap[clapsection]]);
else:
if (start + endure > 0.75):
explode.append([music[k][j], spare, clap[clapsection]]);
explode.append([music[k][j], 0.25, clap[clapsection+1]]);
explode.append([music[k][j], 0.25, clap[clapsection+2]]);
start = endure-0.5-spare;
explode.append([music[k][j], start, clap[clapsection+3]]);
clapsection += 3;
elif (start + endure > 0.5):
explode.append([music[k][j], spare, clap[clapsection]]);
explode.append([music[k][j], 0.25, clap[clapsection+1]]);
start = endure-0.25-spare;
explode.append([music[k][j], start, clap[clapsection+2]]);
clapsection += 2;
elif (start + endure > 0.25):
explode.append([music[k][j], spare, clap[clapsection]]);
start = endure-spare;
explode.append([music[k][j], start, clap[clapsection+1]]);
clapsection += 1;
else:
pass;
else: #使用切分音
explode.append([music[k][j], endure, clap[clapsection]]);
start += endure;
if (start >= 0.75):
start -= 0.75;
clapsection = 3;
elif (start >= 0.5):
start -= 0.5;
clapsection = 2;
elif start >= 0.25:
start -= 0.25;
clapsection = 1;
else:
clapsection = 0;
for i in range(len(explode)):
endure_ = explode[i][1]/0.25*clapendure;
if (continuous == False):
if (explode[i][0] == 0): #空音
data += zeropack(endure_);
elif (explode[i][0] > 10): #高音
freq_ = keyFreq[2][explode[i][0]-10-1];
data += wavepack(datawave(freq_, endure_, explode[i][2]));
elif (explode[i][0] < 0): #低音
freq_ = keyFreq[0][explode[i][0]+10-1];
data += wavepack(datawave(freq_, endure_, explode[i][2]));
else:
freq_ = keyFreq[1][explode[i][0]-1];
data += wavepack(datawave(freq_, endure_, explode[i][2]));
else:
if (explode[i][0] == 0): #空音
data += zeropack(endure_);
lastkey = 0;
lastphase = 0;
else:
if (explode[i][0] > 10):
freq_ = keyFreq[2][explode[i][0]-10-1];
elif (explode[i][0] < 0):
freq_ = keyFreq[0][explode[i][0]+10-1];
else:
freq_ = keyFreq[1][explode[i][0]-1];
if (i == 0 and explode[i][0] == lastkey):
lastphase, data_ = datawave_con(freq_, endure_, explode[i][2], lastphase);
else:
lastphase, data_ = datawave_con(freq_, endure_, explode[i][2], 0);
data += wavepack(data_);
lastkey = explode[i][0];
else: #其它节奏
pass;
#print(data[:100]);
#print(len(data));
return data;
#波形数据
def datawave(freq, endure, strong):
#传入频率、持续时间,拍子强度
#设立20000个数值点,约可听2秒
sampleArray = [];
coef = 2*math.pi*freq/11025;
N = round(endure*11025);
for i in range(N):
xvalue = coef*i;
yvalue = math.sin(xvalue)
if (yvalue < 0):
yvalue *= strong * 32768/2;
else:
yvalue *= strong * 32767/2;
sampleArray.append(round(yvalue));
return sampleArray;
#波形数据,用于切分音
def datawave_con(freq, endure, strong, startphase):
#传入频率、持续时间,拍子强度
#设立20000个数值点,约可听2秒
sampleArray = [];
coef = 2*math.pi*freq/11025;
N = round(endure*11025);
for i in range(startphase, startphase+N):
xvalue = coef*i;
yvalue = math.sin(xvalue)
if (yvalue < 0):
yvalue *= strong * 32768/2;
else:
yvalue *= strong * 32767/2;
sampleArray.append(round(yvalue));
return i, sampleArray;
#波形压缩成二进制
def wavepack(wavedata):
dataArray = [];
for i in range(len(wavedata)):
value = littleEndian(wavedata[i], 2);
for j in range(2):
byte = struct.pack('B', value[j]);
dataArray.append(byte);
return dataArray;
#空音压缩成二进制
def zeropack(endure):
N = round(endure*11025)//2;
return [b'\x00', b'\x00']*N;
if __name__ == '__main__':
writeWav(2, 'HaoHanGe_#C');
#
#
#卷珠帘
JuanZhuLian = [['B', 4, 4, 100], #G大调,4/4拍, 90拍/分钟
#第一节
[5, 6/16, 4, 2/16, 4, 4/16, 3, 4/16],
[2, 6/16, 2, 2/16, 2, 4/16, 1, 2/16, -6, 2/16],
[-6, 2/16, -5, 2/16, -5, 12/16],
[0, 8/16, 4, 4/16, 11, 4/16],
[7, 6/16, 6, 2/16, 6, 4/16, 5, 4/16],
[6, 16/16],
[6, 8/16, 6, 4/16, 11, 2/16, 12, 2/16],
[12, 8/16, 11, 2/16, 12, 1/16, 11, 1/16, 6, 2/16, 5, 2/16],
[5, 8/16, 4, 4/16, 5, 4/16],
[6, 4/16, 5, 2/16, 4, 2/16, 4, 2/16, 5, 1/16, 4, 1/16, 2, 2/16, 1, 2/16],
[2, 12/16, 1, 4/16],
[2, 12/16, 4, 4/16],
#第一尾
[3, 4/16, 1, 2/16, -6, 2/16, 5, 4/16, 4, 2/16, 2, 2/16],
[2, 2/16, 2, 2/16, 2, 12/16],
[2, 16/16],
[0, 16/16],
[0, 16/16],
#第二节 基本同第一节
[5, 6/16, 4, 2/16, 4, 4/16, 3, 4/16],
[2, 6/16, 2, 2/16, 2, 4/16, 1, 2/16, -6, 2/16],
[-6, 2/16, -5, 2/16, -5, 12/16],
[0, 8/16, 4, 4/16, 11, 4/16],
[7, 6/16, 6, 2/16, 6, 4/16, 5, 4/16],
[6, 16/16],
[6, 8/16, 6, 4/16, 11, 2/16, 6, 1/16, 11, 1/16],
[12, 8/16, 11, 2/16, 12, 1/16, 11, 1/16, 6, 2/16, 5, 2/16],
[5, 8/16, 4, 4/16, 5, 4/16],
[6, 4/16, 5, 2/16, 4, 2/16, 4, 2/16, 5, 1/16, 4, 1/16, 2, 2/16, 1, 2/16],
[2, 12/16, 1, 4/16],
[2, 12/16, 4, 4/16],
#第二尾
[3, 4/16, 1, 2/16, -6, 2/16, 5, 4/16, 4, 2/16, 2, 2/16],
[2, 2/16, 4, 2/16, 2, 12/16],
[2, 4/16, 0, 4/16, 0, 4/16, 11, 4/16],
[12, 12/16, 12, 2/16, 13, 1/16, 12, 1/16],
[11, 6/16, 12, 1/16, 11, 1/16, 7, 4/16, 6, 4/16],
[7, 4/16, 6, 2/16, 5, 2/16, 2, 8/16],
[2, 8/16, 3, 4/16, 4, 4/16],
[4, 2/16, 11, 2/16, 11, 8/16, 11, 2/16, 11, 1/16, 12, 1/16],
[7, 8/16, 7, 4/16, 6, 2/16, 5, 2/16],
[4, 2/16, 5, 2/16, 6, 12/16],
[0, 12/16, 11, 4/16],
[12, 12/16, 12, 2/16, 13, 1/16, 12, 1/16],
[11, 6/16, 12, 1/16, 11, 1/16, 7, 4/16, 6, 2/16, 5, 2/16],
[7, 4/16, 6, 2/16, 5, 2/16, 6, 2/16, 5, 6/16],
[5, 8/16, 6, 4/16, 5, 4/16],
[2, 16/16],
[0, 4/16, 6, 2/16, 5, 2/16, 2, 6/16, 1, 2/16],
[2, 16/16],
[2, 16/16],
[0, 16/16],
[0, 16/16],
#第三节 同第二节
[5, 6/16, 4, 2/16, 4, 4/16, 3, 4/16],
[2, 6/16, 2, 2/16, 2, 4/16, 1, 2/16, -6, 2/16],
[-6, 2/16, -5, 2/16, -5, 12/16],
[0, 8/16, 4, 4/16, 11, 4/16],
[7, 6/16, 6, 2/16, 6, 4/16, 5, 4/16],
[6, 16/16],
[6, 8/16, 6, 4/16, 11, 2/16, 6, 1/16, 11, 1/16],
[12, 8/16, 11, 2/16, 12, 1/16, 11, 1/16, 6, 2/16, 5, 2/16],
[5, 8/16, 4, 4/16, 5, 4/16],
[6, 4/16, 5, 2/16, 4, 2/16, 4, 2/16, 5, 1/16, 4, 1/16, 2, 2/16, 1, 2/16],
[2, 12/16, 1, 4/16],
[2, 12/16, 4, 4/16],
#第三尾
[3, 4/16, 1, 2/16, -6, 2/16, 5, 4/16, 4, 2/16, 2, 2/16],
[2, 2/16, 1, 2/16, 2, 12/16],
[2, 16/16]
];
#好汉歌
HaoHanGe = [['#C', 4, 4, 80], #G大调,4/4拍, 90拍/分钟
#引子
[12, 2/16, 12, 2/16, 11, 2/16, 12, 6/16, 0, 4/16],
[12, 2/16, 12, 2/16, 11, 2/16, 12, 6/16, 0, 4/16],
#第一节
[5, 4/16, 15, 4/16, 7, 2/16, 7, 1/16, 6, 1/16, 5, 2/16, 5, 2/16],
[11, 2/16, 11, 1/16, 6, 1/16, 5, 2/16, 5, 2/16, 13, 1/16, 13, 2/16, 6, 1/16, 5, 2/16, 5, 2/16],
[5, 2/16, 15, 2/16, 0, 2/16, 15, 2/16, 11, 2/16, 6, 1/16, 11, 1/16, 12, 2/16, 12, 2/16],
[12, 2/16, 15, 2/16, 12, 2/16, 15, 2/16, 3, 1/16, 2, 1/16, 11, 2/16, 12, 2/16, 12, 2/16],
[5, 4/16, 15, 4/16, 7, 2/16, 7, 1/16, 6, 1/16, 5, 2/16, 5, 2/16],
[11, 2/16, 11, 1/16, 6, 1/16, 5, 2/16, 5, 2/16, 13, 1/16, 13, 2/16, 6, 1/16, 5, 2/16, 5, 2/16],
[5, 2/16, 15, 2/16, 5, 2/16, 15, 2/16, 13, 1/16, 12, 1/16, 11, 2/16, 12, 2/16, 12, 2/16],
[12, 2/16, 15, 2/16, 12, 2/16, 15, 2/16, 13, 1/16, 12, 1/16, 11, 2/16, 12, 2/16, 12, 2/16],
#第一节,第二遍
[5, 4/16, 15, 4/16, 7, 2/16, 7, 1/16, 6, 1/16, 5, 2/16, 5, 2/16],
[11, 2/16, 11, 1/16, 6, 1/16, 5, 2/16, 5, 2/16, 13, 1/16, 13, 2/16, 6, 1/16, 5, 2/16, 5, 2/16],
[5, 2/16, 15, 2/16, 0, 2/16, 15, 2/16, 11, 2/16, 6, 1/16, 11, 1/16, 12, 2/16, 12, 2/16],
[12, 2/16, 15, 2/16, 12, 2/16, 15, 2/16, 3, 1/16, 2, 1/16, 11, 2/16, 12, 2/16, 12, 2/16],
[5, 4/16, 15, 4/16, 7, 2/16, 7, 1/16, 6, 1/16, 5, 2/16, 5, 2/16],
[11, 2/16, 11, 1/16, 6, 1/16, 5, 2/16, 5, 2/16, 13, 1/16, 13, 2/16, 6, 1/16, 5, 2/16, 5, 2/16],
[5, 2/16, 15, 2/16, 5, 2/16, 15, 2/16, 13, 1/16, 12, 1/16, 11, 2/16, 12, 2/16, 12, 2/16],
[12, 2/16, 15, 2/16, 12, 2/16, 15, 2/16, 13, 1/16, 12, 1/16, 11, 2/16, 12, 2/16, 12, 2/16],
#副歌
[13, 3/16, 13, 1/16, 13, 2/16, 13, 2/16, 13, 1/16, 15, 1/16, 6, 2/16, 11, 2/16, 11, 2/16],
[15, 3/16, 6, 1/16, 5, 2/16, 5, 2/16, 6, 1/16, 5, 1/16, 4, 2/16, 5, 2/16, 5, 2/16],
[5, 2/16, 11, 2/16, 5, 2/16, 11, 2/16, 6, 1/16, 5, 1/16, 4, 2/16, 5, 2/16, 5, 2/16],
#副歌
[13, 3/16, 13, 1/16, 13, 2/16, 13, 2/16, 13, 1/16, 15, 1/16, 6, 2/16, 11, 2/16, 11, 2/16],
[15, 3/16, 6, 1/16, 5, 2/16, 5, 2/16, 6, 1/16, 5, 1/16, 4, 2/16, 5, 2/16, 5, 2/16],
[5, 2/16, 11, 2/16, 5, 2/16, 11, 2/16, 6, 1/16, 5, 1/16, 4, 2/16, 5, 2/16, 5, 2/16],
#第二节
[15, 3/16, 13, 1/16, 12, 4/16, 13, 1/16, 13, 2/16, 11, 1/16, 12, 4/16],
[0, 2/16, 15, 2/16, 14, 2/16, 15, 2/16, 16, 1/16, 11, 1/16, 13, 2/16, 12, 4/16],
[15, 3/16, 13, 1/16, 12, 4/16, 13, 2/16, 11, 2/16, 12, 4/16],
[12, 2/16, 15, 2/16, 12, 2/16, 15, 2/16, 3, 1/16, 2, 1/16, 11, 2/16, 12, 4/16],
[13, 3/16, 13, 1/16, 13, 2/16, 13, 2/16, 13, 1/16, 15, 1/16, 6, 2/16, 11, 2/16, 11, 2/16],
[15, 3/16, 6, 1/16, 5, 2/16, 5, 2/16, 6, 1/16, 5, 1/16, 4, 2/16, 5, 2/16, 5, 2/16],
[5, 2/16, 11, 2/16, 5, 2/16, 11, 2/16, 6, 1/16, 5, 1/16, 4, 2/16, 5, 2/16, 5, 2/16],
[-5, 2/16, 5, 2/16, -5, 2/16, 5, 2/16, 4, 2/16, 4, 2/16, 5, 2/16, 5, 2/16],
[-5, 2/16, 5, 2/16, -5, 2/16, 5, 2/16, 4, 2/16, 4, 2/16, 5, 2/16, 5, 2/16],
#第二遍
#第一节
[5, 4/16, 15, 4/16, 7, 2/16, 7, 1/16, 6, 1/16, 5, 2/16, 5, 2/16],
[11, 2/16, 11, 1/16, 6, 1/16, 5, 2/16, 5, 2/16, 13, 1/16, 13, 2/16, 6, 1/16, 5, 2/16, 5, 2/16],
[5, 2/16, 15, 2/16, 0, 2/16, 15, 2/16, 11, 2/16, 6, 1/16, 11, 1/16, 12, 2/16, 12, 2/16],
[12, 2/16, 15, 2/16, 12, 2/16, 15, 2/16, 3, 1/16, 2, 1/16, 11, 2/16, 12, 2/16, 12, 2/16],
[5, 4/16, 15, 4/16, 7, 2/16, 7, 1/16, 6, 1/16, 5, 2/16, 5, 2/16],
[11, 2/16, 11, 1/16, 6, 1/16, 5, 2/16, 5, 2/16, 13, 1/16, 13, 2/16, 6, 1/16, 5, 2/16, 5, 2/16],
[5, 2/16, 15, 2/16, 5, 2/16, 15, 2/16, 13, 1/16, 12, 1/16, 11, 2/16, 12, 2/16, 12, 2/16],
[12, 2/16, 15, 2/16, 12, 2/16, 15, 2/16, 13, 1/16, 12, 1/16, 11, 2/16, 12, 2/16, 12, 2/16],
#第一节 第二遍
[5, 4/16, 15, 4/16, 7, 2/16, 7, 1/16, 6, 1/16, 5, 2/16, 5, 2/16],
[11, 2/16, 11, 1/16, 6, 1/16, 5, 2/16, 5, 2/16, 13, 1/16, 13, 2/16, 6, 1/16, 5, 2/16, 5, 2/16],
[5, 2/16, 15, 2/16, 0, 2/16, 15, 2/16, 11, 2/16, 6, 1/16, 11, 1/16, 12, 2/16, 12, 2/16],
[12, 2/16, 15, 2/16, 12, 2/16, 15, 2/16, 3, 1/16, 2, 1/16, 11, 2/16, 12, 2/16, 12, 2/16],
[5, 4/16, 15, 4/16, 7, 2/16, 7, 1/16, 6, 1/16, 5, 2/16, 5, 2/16],
[11, 2/16, 11, 1/16, 6, 1/16, 5, 2/16, 5, 2/16, 13, 1/16, 13, 2/16, 6, 1/16, 5, 2/16, 5, 2/16],
[5, 2/16, 15, 2/16, 5, 2/16, 15, 2/16, 13, 1/16, 12, 1/16, 11, 2/16, 12, 2/16, 12, 2/16],
[12, 2/16, 15, 2/16, 12, 2/16, 15, 2/16, 13, 1/16, 12, 1/16, 11, 2/16, 12, 2/16, 12, 2/16],
#副歌
[13, 3/16, 13, 1/16, 13, 2/16, 13, 2/16, 13, 1/16, 15, 1/16, 6, 2/16, 11, 2/16, 11, 2/16],
[15, 3/16, 6, 1/16, 5, 2/16, 5, 2/16, 6, 1/16, 5, 1/16, 4, 2/16, 5, 2/16, 5, 2/16],
[5, 2/16, 11, 2/16, 5, 2/16, 11, 2/16, 6, 1/16, 5, 1/16, 4, 2/16, 5, 2/16, 5, 2/16],
#副歌
[13, 3/16, 13, 1/16, 13, 2/16, 13, 2/16, 13, 1/16, 15, 1/16, 6, 2/16, 11, 2/16, 11, 2/16],
[15, 3/16, 6, 1/16, 5, 2/16, 5, 2/16, 6, 1/16, 5, 1/16, 4, 2/16, 5, 2/16, 5, 2/16],
[5, 2/16, 11, 2/16, 5, 2/16, 11, 2/16, 6, 1/16, 5, 1/16, 4, 2/16, 5, 2/16, 5, 2/16],
#第二节
[15, 3/16, 13, 1/16, 12, 4/16, 13, 1/16, 13, 2/16, 11, 1/16, 12, 4/16],
[0, 2/16, 15, 2/16, 14, 2/16, 15, 2/16, 16, 1/16, 11, 1/16, 13, 2/16, 12, 4/16],
[15, 3/16, 13, 1/16, 12, 4/16, 13, 2/16, 11, 2/16, 12, 4/16],
[12, 2/16, 15, 2/16, 12, 2/16, 15, 2/16, 3, 1/16, 2, 1/16, 11, 2/16, 12, 4/16],
[13, 3/16, 13, 1/16, 13, 2/16, 13, 2/16, 13, 1/16, 15, 1/16, 6, 2/16, 11, 2/16, 11, 2/16],
[15, 3/16, 6, 1/16, 5, 2/16, 5, 2/16, 6, 1/16, 5, 1/16, 4, 2/16, 5, 2/16, 5, 2/16],
[5, 2/16, 11, 2/16, 5, 2/16, 11, 2/16, 6, 1/16, 5, 1/16, 4, 2/16, 5, 2/16, 5, 2/16],
[-5, 2/16, 5, 2/16, -5, 2/16, 5, 2/16, 4, 2/16, 4, 2/16, 5, 2/16, 5, 2/16],
[-5, 2/16, 5, 2/16, -5, 2/16, 5, 2/16, 4, 2/16, 4, 2/16, 5, 2/16, 5, 2/16],
#收尾
[5, 2/16, 11, 2/16, 5, 2/16, 11, 2/16, 16, 1/16, 15, 1/16, 14, 2/16, 5, 2/16, 5, 2/16],
[15, 16/16],
[15, 16/16],
[15, 4/16, 0, 12/16]
];
#
本节到此结束,欲知后事如何,请看下回分解。