def coalesce_and_choose_sounds(w, state):
    rng = w.get_rng(state)
    def rnd(min, max):
        return min + (rng.random() * (max - min))

    chans = []

    # ----------------------------------------
    # Kick.

    k0 = w.get('kick_pat0')
    k1 = w.get('kick_pat1')
    kick = chain(w, k0, k1)
    w.set('chan0', kick)

    from models.sample import Sample
    ks = Sample.choose_random('bd', rng.random(), rng)
    chans.append({
            'bus': 'bd',
            'label': 'bd',
            'hard': 1.0,
            'soft': rnd(0.7, 0.9),
            'grace': rnd(0.01, 0.2),
            'pat': kick,
            'sound': ks.serve_url()
            })

    # ----------------------------------------
    # Snare.

    sn = w.get('sn_pat')
    w.set('chan1', sn)

    ss = Sample.choose_random('sn', rng.random(), rng)
    chans.append({
            'bus': 'sn',
            'label': 'sn',
            'hard': rnd(0.6, 0.9),
            'soft': rnd(0.2, 0.65),
            'grace': rnd(0.1, 0.25),
            'pat': sn,
            'sound': ss.serve_url()
            })

    # ----------------------------------------
    w.set('channels', len(chans))
    w.set_result({
            'bpm': w.get('tempo'),
            'chans': chans
            })

    return 'punching to\ntape...'
Exemple #2
0
 def get(self, sid = None):
     try:
         from models.sample import Sample
         sample = Sample.get_by_id(int(sid))
         if sample and sample.data:
             self.send_blob(sample.data)
         else:
             import random as rand
             sample = Sample.choose_random('?', rand.random(), rand)
             if sample and sample.data:
                 self.send_blob(sample.data)
             else:
                 return self.response.set_status(404)
     except Exception, e:
         logging.error('SAMPLE GET EXCEPTION! %s' % repr(e))
         return self.response.set_status(404)
Exemple #3
0
    def __get_average_sample_values(self, part_type: VehiclePart) -> Sample:
        positions = list(
            filter(lambda s: s.vehicle_part == part_type, self.__samples))
        x = y = 0
        n = len(positions)
        for pos in positions:
            x = x + pos.x
            y = y + pos.y

        return Sample(part_type, x // n, y // n)
    def get(self):
        # 获取要查询的产地名称
        origin = self.get_argument("origin", "")
        if not origin:
            return self.write("产地名称为空")
        try:
            items = Sample.select().where(Sample.origin == origin)
        except Exception:
            items = Sample()

        list = []
        # 遍历查询到的对象,转换为字典并添加进列表
        for item in items:
            dir = item.to_dir()
            list.append(dir)
            print(item.no)
        # 转化为json数据
        json1 = json.dumps(list)

        self.write(json1)
Exemple #5
0
    def post(self):
        logging.info('UPLOADED!')

        upload_files = self.get_uploads('file')
        blob_info = upload_files[0]

        from models.sample import Sample
        s = Sample.new(ip=self.request.remote_addr,
                       type=self.request.get('type', 'unknown'),
                       notes=self.request.get('notes', ''),
                       filename=blob_info.filename,
                       size=blob_info.size,
                       data=blob_info,
                       mime=blob_info.content_type)
        s.put()

        self.redirect('/_ah/nimda/samples')
Exemple #6
0
    def post(self):
        logging.info('UPLOADED!')

        upload_files = self.get_uploads('file')
        blob_info = upload_files[0]

        from models.sample import Sample
        s = Sample.new(ip = self.request.remote_addr,
                       type = self.request.get('type', 'unknown'),
                       notes = self.request.get('notes', ''),
                       filename = blob_info.filename,
                       size = blob_info.size,
                       data = blob_info,
                       mime = blob_info.content_type)
        s.put()

        self.redirect('/_ah/nimda/samples')
Exemple #7
0
 def get_sample(self, id):
     from models.sample import Sample
     return Sample.get_by_id(int(id))
Exemple #8
0
 def all_samples(self):
     from models.sample import Sample
     return Sample.all().fetch(1000)
Exemple #9
0
 def get_sample(self, id):
     from models.sample import Sample
     return Sample.get_by_id(int(id))
Exemple #10
0
 def all_samples(self):
     from models.sample import Sample
     return Sample.all().fetch(1000)
Exemple #11
0
 def __add_samples(self, filtered_objects: List[Object]) -> None:
     for obj in filtered_objects:
         if obj:
             sample = Sample.create(obj)
             self.__samples.append(sample)
             self.__increment_sample_count(sample.vehicle_part)
Exemple #12
0
def create_sample():
    request_data = request.get_json()
    request_data['collect']['_id'] = ObjectId(request_data['collect']['$oid'])
    del request_data['collect']['$oid']
    sample = Sample(**request_data).save()
    return jsonify(sample)
Exemple #13
0
 def _add_samples_from_spots(self, spots):
     for spot in spots:
         if spot.sample_name not in self.samples_by_name:
             self.samples_by_name[spot.sample_name] = Sample(
                 spot.sample_name)
         self.samples_by_name[spot.sample_name].spots.append(spot)